Skip to content

Conversation

@jasperfue
Copy link

@jasperfue jasperfue commented Dec 21, 2025

This PR fixes an issue where the start-i18n-paraglide example causes infinite 307 redirect loops in production environments (e.g., Netlify) or when cookie strategies are involved.
The Issue:
The paraglideMiddleware automatically de-localizes the URL (e.g., /en/about -> /about) in the request object passed to its callback.
However, the example also configures a rewrite in the TanStack Router:

rewrite: {
  input: ({ url }) => deLocalizeUrl(url),
  // ...
}

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 paraglideMiddleware to set the AsyncLocalStorage context (for translations), but we pass the original req to handler.fetch. This allows TanStack Router to handle the URL rewriting via its configured rewrite property as intended.

Note:

  • The link to the source code in the README (.../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.
  • I noticed the link to the paraglide monorepo example is dead.

Summary by CodeRabbit

Release Notes

  • Documentation
    • Improved integration guides for Paraglide with Vite and TanStack Start frameworks, featuring comprehensive configuration examples and best practices.
    • Introduced URL rewriting examples showcasing enhanced localization capabilities.
    • Updated server middleware integration documentation with refined implementation patterns.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 21, 2025

Walkthrough

Updates 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

Cohort / File(s) Summary
Paraglide Example Configuration
examples/react/start-i18n-paraglide/README.md
Removed reference to Paraglide source in monorepo; added Vite plugin configuration example with paraglideVitePlugin setup and URL rewriting pattern using deLocalizeUrl and localizeUrl.
Server Middleware Pattern
examples/react/start-i18n-paraglide/src/server.ts
Updated paraglideMiddleware callback to invoke handler.fetch(req) directly using captured outer scope, removing destructured parameter extraction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Verify Vite plugin configuration object syntax and completeness
  • Confirm server.ts callback refactoring preserves middleware behavior and request flow
  • Validate URL rewriting example usage of deLocalizeUrl/localizeUrl helpers

Possibly related PRs

Suggested labels

documentation

Suggested reviewers

  • schiller-manuel
  • birkskyum

Poem

🐰 Paraglide takes wing with Vite's new grace,
URLs rewritten in their rightful place,
Middleware flows with callback refine,
i18n examples now perfectly align!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: fixing paraglide middleware usage in the start-i18n-paraglide example to resolve redirect loop issues in production.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6839bfb and 2b4cb15.

📒 Files selected for processing (2)
  • examples/react/start-i18n-paraglide/README.md (2 hunks)
  • examples/react/start-i18n-paraglide/src/server.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript strict mode with extensive type safety for all code

Files:

  • examples/react/start-i18n-paraglide/src/server.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Implement ESLint rules for router best practices using the ESLint plugin router

Files:

  • examples/react/start-i18n-paraglide/src/server.ts
🔇 Additional comments (4)
examples/react/start-i18n-paraglide/src/server.ts (1)

5-7: Excellent fix for the redirect loop issue!

This change correctly resolves the infinite 307 redirect problem by passing the original req to handler.fetch. The middleware still sets up the translation context via AsyncLocalStorage, but now the TanStack Router's rewrite.input configuration can properly handle URL de-localization without conflicts. The closure over the outer req is intentional and ensures the correct request flow.

examples/react/start-i18n-paraglide/README.md (3)

3-3: LGTM - Clear and concise description.


82-87: Documentation accurately reflects the code fix.

The server.ts example correctly shows the updated pattern that resolves the redirect loop issue. The documentation is now consistent with the actual implementation.


26-53: Comprehensive integration guidance provided.

The documentation now includes detailed Vite plugin configuration and URL rewriting examples that complement the server.ts fix. This will help users properly configure the paraglide integration and avoid the redirect loop issues.

Also applies to: 59-75


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@schiller-manuel
Copy link
Contributor

i need to look closer into that, this might just be a bug in router instead the example being incorrect

@jasperfue
Copy link
Author

@schiller-manuel I thought about that too, but wasn't sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants