vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.51k stars 26.92k forks source link

Router: defaultLocale and locale are swapped #23220

Open fmacherey opened 3 years ago

fmacherey commented 3 years ago

What version of Next.js are you using?

10.0.9

What version of Node.js are you using?

15.5.1

What browser are you using?

Chromium

What operating system are you using?

macOS

How are you deploying your application?

Other

Describe the Bug

We are using domain routing with subdomains to localize our app. I configured three domains with locales in next.config.js:

    domains = [
        {
            domain: "www.example.com",
            defaultLocale: "de-DE",
        },
        {
            domain: "at.example.com",
            defaultLocale: "de-AT",
        },
        {
            domain: "ch.example.com",
            defaultLocale: "de-CH",
        },
    ];

The default locale is set to de-DE I set the domains depending on which env to deploy (local, stage, prod). For localhost, everything works as it expected. When deploying to our stage, the non-defaults aren't working. When logging the whole object returned from useRouter, I figured out, that defaultLocale and locale props seems to be swapped.

I also switched off automatic locale detection, so that only the url should be affect the locale.

We are using next with current preact@10.5.13

Expected Behavior

router.defaultLocale is always "de-DE" (in our case) and router.locale is the locale, depending on domain setting.

To Reproduce

see above

fmacherey commented 3 years ago

I also left a comment here, as it is maybe related https://github.com/vercel/next.js/issues/21810#issuecomment-797412757

fatihpkn commented 2 years ago

We are facing the similar issue with next@12.3.1

Did you find out any workaround? @fmacherey

fatihpkn commented 1 year ago

We figure out this issue. In our case nginx doesn't pass host header to server, so we pass the host and it works normally now