Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n links are unusable in dev builds when using multiple domains #21211

Closed
sebastian-nowak opened this issue Jan 15, 2021 · 4 comments · Fixed by #22032
Closed

i18n links are unusable in dev builds when using multiple domains #21211

sebastian-nowak opened this issue Jan 15, 2021 · 4 comments · Fixed by #22032
Labels
bug Issue was opened via the bug report template.

Comments

@sebastian-nowak
Copy link

What version of Next.js are you using?

10.0.5

What version of Node.js are you using?

15.6.0

What browser are you using?

n/a

What operating system are you using?

n/a

How are you deploying your application?

next dev

Describe the Bug

Links created with next/link use the i18n domains from next.config.js when running in development mode.

That makes them unusable, since the dev server runs on localhost:3000 and the generated links point to production.

Expected Behavior

next/link should ignore the i18n domains when running in development mode

To Reproduce

Run npx create-next-app, then enable i18n in next.config.js:

module.exports = {
  i18n: {
    locales: ['en', 'pl'],
    defaultLocale: 'en',
    domains: [
      {
        domain: 'google.com',
        defaultLocale: 'en'
      },
      {
        domain: 'google.pl',
        defaultLocale: 'pl'
      }
    ]
  }
}

Add the following links somewhere in pages/index.js:

<Link href='/'><a>auto</a></Link>
<Link href='/' locale='en'><a>en</a></Link>
<Link href='/' locale='pl'><a>pl</a></Link>

Run npm dev and try clicking on these links. They will take you to google so the dev build isn't very useful.

@sebastian-nowak sebastian-nowak added the bug Issue was opened via the bug report template. label Jan 15, 2021
@ijjk
Copy link
Member

ijjk commented Jan 18, 2021

Hmm it seems expected that the links would match production while developing so you don't get differing experience between development and production. If you want to avoid this from using the domains in development you can change the config value when not in production mode e.g. domains: process.env.NODE_ENV === 'production' ? [ /* production i18n domains */ ] : [],

@javiercr
Copy link

@ijjk the problem is not just whether development and production use the same domains, it's that after v10.0.5 client side navigation doesn't work for any domain that is not listed under domains in next.config.js.

IMHO that's not what someone would expect from the i18n domain routing config. Also the i18n docs on domain routing doesn't mention anything about being forced to use only those domains for all environments.

@kodiakhq kodiakhq bot closed this as completed in #22032 Feb 11, 2021
kodiakhq bot pushed a commit that referenced this issue Feb 11, 2021
This updates to only create locale domain links if the current hostname is a locale domain to prevent making links unvisitable in development and preview environments where the configured locale domains don't point to the current build. 

Closes: #21211
Closes: #22011
@ijjk
Copy link
Member

ijjk commented Feb 11, 2021

Hi, this has been updated in the latest canary of Next.js v10.0.7-canary.7, please update and give it a try!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants