fix(control-plane): drop locale slug from URLs (localePrefix never)#2075
Merged
Conversation
Bank selection was lost on refresh for non-default locales because the locale prefix (e.g. /es/banks/x) defeated path parsing in bank-context. Switch next-intl to localePrefix "never" so the locale is resolved from the NEXT_LOCALE cookie and never appears in the URL. Paths stay clean (/banks/x) for every language, so the existing ^/banks/ parsing works. Also removes the now-dead stripLocalePrefix() helper in middleware. Supersedes #2070.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Control Plane loses the selected bank on page refresh for non-default locales.
Root cause: routing used
localePrefix: "as-needed", so non-English locales carry a locale prefix in the URL (e.g./es/banks/hermes).bank-context.tsxreadsusePathname()fromnext/navigation(which includes the prefix) and parses the bank id with a^/banks/anchored regex, so the match fails andcurrentBankstaysnullon load. English (the default locale) had no prefix, so the bug only affected the other 9 locales.Fix: switch next-intl to
localePrefix: "never". The active locale is resolved from theNEXT_LOCALEcookie (Accept-Language fallback) and next-intl rewrites internally to the[locale]segment, so the locale never appears in the URL. Every path stays clean (/banks/x), and the existing^/banks/parsing works for all languages.Also removes the now-dead
stripLocalePrefix()helper inmiddleware.ts(there is no prefix to strip anymore).Supersedes #2070
#2070 patched the same symptom by un-anchoring the regex. This addresses it at the routing layer instead: the locale slug was unintentional for an authenticated admin UI, and removing it keeps the address bar locale-agnostic. With this change #2070 is no longer needed.
Related Issue
Fixes #2069
Trade-offs
/es/...deep links). Irrelevant for an authed control plane with no SEO surface.[locale]route folders are unchanged; next-intl rewrites to them internally.Type of Change
How to Test
/banks/x(no/es/prefix), locale persists across refresh via cookie.Test Results
tsc --noEmit: cleaneslint(changed files): cleanvitest: 65/65 pass