Skip to content

fix(control-plane): drop locale slug from URLs (localePrefix never)#2075

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/control-plane-drop-locale-slug
Jun 9, 2026
Merged

fix(control-plane): drop locale slug from URLs (localePrefix never)#2075
nicoloboschi merged 1 commit into
mainfrom
fix/control-plane-drop-locale-slug

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

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.tsx reads usePathname() from next/navigation (which includes the prefix) and parses the bank id with a ^/banks/ anchored regex, so the match fails and currentBank stays null on 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 the NEXT_LOCALE cookie (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 in middleware.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

  • Language is now a per-user cookie preference, not URL-addressable (no shareable /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

  • Bug fix (non-breaking change that fixes an issue)

How to Test

  1. Open Control Plane, select a bank, refresh → bank stays selected.
  2. Switch language via the picker → UI translates, URL stays /banks/x (no /es/ prefix), locale persists across refresh via cookie.

Test Results

  • tsc --noEmit: clean
  • eslint (changed files): clean
  • vitest: 65/65 pass

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.
@nicoloboschi nicoloboschi merged commit c0f0c3a into main Jun 9, 2026
75 checks passed
@nicoloboschi nicoloboschi deleted the fix/control-plane-drop-locale-slug branch June 9, 2026 11:29
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.

Control Plane: bank selection lost on page refresh (URL locale prefix mismatch)

1 participant