-
Notifications
You must be signed in to change notification settings - Fork 177
Description
Summary
When using req.nextUrl.locale in middleware, in combination with domain locales in next.config.js, when built with Open next the middleware is incorrectly reporting the locale. This only seems to affect middleware and not getServersideProps for example. Can work around by using defaultLocale as this has the correct locale, but that feels wrong and is a change of behaviour from previous version of Next.js and Open-next (currently upgrading from next v13 and open-next v2)
Debug information
Next version: 5.1.7 and 5.2.0
Open-next version: 3.4.2 and 3.5.0 (Edit: Spotted there was a new release, same behaviour in 3.5.0)
Example repo: https://github.com/nicholas-c/next-15-open-next-example
Example URL:
- EN - https://next-15-en.nich-carter-qza3ng.gymshark-sandbox.tools/
- ES - https://next-15-es.nich-carter-qza3ng.gymshark-sandbox.tools/
Console log of entire req.nextUrl object:
{
[Symbol(NextURLInternal)]: {
url: URL {
href: 'https://next-15-es.nich-carter-qza3ng.gymshark-sandbox.tools/',
origin: 'https://next-15-es.nich-carter-qza3ng.gymshark-sandbox.tools',
protocol: 'https:',
username: '',
password: '',
host: 'next-15-es.nich-carter-qza3ng.gymshark-sandbox.tools',
hostname: 'next-15-es.nich-carter-qza3ng.gymshark-sandbox.tools',
port: '',
pathname: '/',
search: '',
searchParams: URLSearchParams {},
hash: ''
},
options: { headers: [Object], nextConfig: [Object] },
basePath: '',
domainLocale: {
domain: 'next-15-es.nich-carter-qza3ng.gymshark-sandbox.tools',
defaultLocale: 'es'
},
defaultLocale: 'es',
buildId: undefined,
locale: 'en',
trailingSlash: true
}
}
Next start behaviour:
yarn dev or next build/next start
next.config.ts
i18n: {
locales: ["en", "es"],
defaultLocale: "en",
localeDetection: false,
domains: [
{
domain: "gymshark.local",
defaultLocale: "en",
},
{
domain: "es.gymshark.local",
defaultLocale: "es",
},
],
},
Open-next behaviour:
next.config.ts
i18n: {
locales: ["en", "es"],
defaultLocale: "en",
localeDetection: false,
domains: [
{
domain: "next-15-en.nich-carter-qza3ng.gymshark-sandbox.tools",
defaultLocale: "en",
},
{
domain: "next-15-es.nich-carter-qza3ng.gymshark-sandbox.tools",
defaultLocale: "es",
},
],
},



