feat(experimental): opt-in localeAgnosticDefaultRoutes route-name resolution (PoC)#4017
feat(experimental): opt-in localeAgnosticDefaultRoutes route-name resolution (PoC)#4017Togetic wants to merge 1 commit into
localeAgnosticDefaultRoutes route-name resolution (PoC)#4017Conversation
…olution Add an opt-in `experimental.localeAgnosticDefaultRoutes` flag that, under `prefix_except_default`, resolves the default locale to the locale-agnostic `___default` route name in `createLocaleRouteNameGetter` instead of the build-bound `<base>___<defaultLocale>`. This lets a single build serve regions whose default locale is chosen at runtime: the default-locale route tree becomes addressable by a locale-agnostic name, so name-based resolution (localePath/localeRoute, hreflang/canonical) targets it regardless of the build default. Off by default — no behavior change when unset. Proof of concept for discussion; scoped to the runtime name-getter seam (the part that cannot live in a userland module without patching dist/).
WalkthroughA new experimental option Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/routing/utils.ts`:
- Around line 25-33: The default-locale route naming is inconsistent between
runtime and generation for prefix_except_default. Update the route name emission
in src/routing.ts so it uses the same locale-agnostic suffix as utils.ts (via
normalizeRouteName, getLocalizedRouteName, and defaultRouteNameSuffix) when
experimental.localeAgnosticDefaultRoutes is enabled, ensuring both sides resolve
the default locale to the same <name>___default form.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e103db93-f409-4ea7-930f-618ed7db5d70
📒 Files selected for processing (7)
src/bundler.tssrc/constants.tssrc/env.d.tssrc/runtime/routing/utils.tssrc/types.tstest/routing-utils.test.tstest/setup.ts
🔗 Linked issue
Part of #4016
📚 Description
Adds an opt-in
experimental.localeAgnosticDefaultRoutesflag that, understrategy: 'prefix_except_default', makescreateLocaleRouteNameGetterresolve the default locale to the locale-agnostic___defaultroute name instead of the build-bound<base>___<defaultLocale>.Why: to serve a single build across regions whose default locale is chosen at runtime, the default-locale route tree must be addressable by a locale-agnostic name (
<base>___default). The build side can be done from a module (pages:resolvedrename), but the runtime name getter hardcodes<base>___<locale>forprefix_except_defaultwith no seam to influence it — so consumers are forced to patchdist/. This gives that behavior a supported home.Scope (deliberately minimal):
experimental.compactRoutes(src/types.ts,src/constants.ts, thesrc/bundler.tsdefine,src/env.d.ts).createLocaleRouteNameGetter: under the flag +prefix_except_default, the default locale →normalizeRouteName(name) + defaultRouteNameSuffix; non-default locales unchanged.Not in this PoC (discussion in #4016): generating the
___defaulttree natively (so no companion module is needed), reading the default locale from runtime config, and the locale-detection fallback.✅ Verification
pnpm test:types,pnpm lint, andpnpm test:unitall pass.test/routing-utils.test.tscovering flag-on resolution (default locale →route1___default, non-default →route1___fr); existing getter tests unchanged.📝 Notes
The behavior here mirrors a
dist/patch that has been running in production (single image, multiple regions). This PR is about giving it a supported, opt-in home and starting the API conversation rather than landing a finished feature.Summary by CodeRabbit
New Features
___defaultpath while other locales continue to use localized routes.Bug Fixes
Tests