Skip to content

Domain Locales incorrectly set on nextUrl object in middleware files #758

@nicholas-c

Description

@nicholas-c

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:

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",
      },
    ],
  },

Image

Image

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",
      },
    ],
  },

Image

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions