Skip to content

fix(i18n): use correct defaultLocale when domains array is present on default host#93151

Open
hammadxcm wants to merge 1 commit intovercel:canaryfrom
hammadxcm:fix/i18n-domain-defaultlocale-regression
Open

fix(i18n): use correct defaultLocale when domains array is present on default host#93151
hammadxcm wants to merge 1 commit intovercel:canaryfrom
hammadxcm:fix/i18n-domain-defaultlocale-regression

Conversation

@hammadxcm
Copy link
Copy Markdown

What?

Fixes the defaultLocale resolution in RouteModule.prepare() when a domains array is configured in the i18n config and the request is served from the default domain (not a configured domain hostname).

Why?

When visiting a locale path like /fr on the default domain (e.g., localhost), detectDomainLocale() matches a configured domain entry (e.g., example.fr) based on the detected locale — not hostname. The matched domain's defaultLocale was then incorrectly used as the request's defaultLocale, causing:

  • Wrong defaultLocale in getServerSideProps / getStaticProps args
  • Wrong router.defaultLocale on SSR (sent via __NEXT_DATA__)
  • Hydration errors from <Link> components rendering domain-prefixed hrefs

This is a regression introduced between v15.3 and v15.4 when the Pages Router handler was refactored to use RouteModule.prepare().

How?

Removed domainLocale?.defaultLocale from the defaultLocale fallback chain in RouteModule.prepare(). The correct defaultLocale is already set in request metadata by base-server.ts using hostname-only domain matching, so the locale-matched domainLocale value is not needed here.

The domainLocale variable (with locale-based matching) is still used for isLocaleDomain — which is needed for domain-prefixed link generation.

Before:

const defaultLocale =
  getRequestMeta(req, 'defaultLocale') ||
  domainLocale?.defaultLocale ||
  i18n?.defaultLocale

After:

const defaultLocale =
  getRequestMeta(req, 'defaultLocale') || i18n?.defaultLocale

Test plan

  • Added regression test: visits /go/another and /do/another on localhost (no host header) and verifies defaultLocale is en-US (main config) in both GSSP props and router.defaultLocale
  • Full i18n integration test suite passes (189/193, 4 skipped)
  • Existing domain locale tests still pass (link domain prefixing, correct default locale on configured domains)

Fixes #90131

… default host

When a `domains` array is configured in i18n and the request is served
from the default domain (e.g., localhost), `defaultLocale` was
incorrectly set to a configured domain's value because
`detectDomainLocale` matched on the detected locale rather than
hostname. Remove `domainLocale?.defaultLocale` from the fallback chain
in `RouteModule.prepare()` since `base-server.ts` already sets the
correct value in request metadata via hostname-only matching.

Fixes vercel#90131
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.

Locale detection isn't working correctly after the update from 15.3 to 15.4/15.5 if a domains array is present in next.config

1 participant