fix(examples): fix paraglide middleware usage in start-i18n-paraglide example#6172
fix(examples): fix paraglide middleware usage in start-i18n-paraglide example#6172jasperfue wants to merge 2 commits intoTanStack:mainfrom
Conversation
WalkthroughUpdates to the React/TanStack Start Paraglide i18n example, including simplified server middleware invocation, enhanced Vite plugin configuration, and URL rewriting examples. Documentation adjustments accompany code pattern refinements. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10–15 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (2)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{js,ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
i need to look closer into that, this might just be a bug in router instead the example being incorrect |
|
@schiller-manuel I thought about that too, but wasn't sure. |
|
thank you for providing the correct solution here. |
This PR fixes an issue where the
start-i18n-paraglideexample causes infinite 307 redirect loops in production environments (e.g., Netlify) or when cookie strategies are involved.The Issue:
The
paraglideMiddlewareautomatically de-localizes the URL (e.g.,/en/about->/about) in therequestobject passed to its callback.However, the example also configures a
rewritein the TanStack Router:By passing the already de-localized request from the middleware to
handler.fetch(request), TanStack Start receives a URL that conflicts with its internal routing/rewrite logic during SSR. This leads to mismatching states where the middleware tries to enforce cookies/redirects while the router tries to handle the URL, resulting in a redirect loop.The Fix:
We strictly use
paraglideMiddlewareto set theAsyncLocalStoragecontext (for translations), but we pass the originalreqtohandler.fetch. This allows TanStack Router to handle the URL rewriting via its configuredrewriteproperty as intended.Note:
.../paraglide-js/examples/tanstack-start) also seems to be broken/404, but fixing this inline code snippet is the most important part for users getting started.Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.