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

enabling differentDomains leads to navigation issues #1708

Closed
cexbrayat opened this issue Dec 8, 2022 · 6 comments · Fixed by #1770
Closed

enabling differentDomains leads to navigation issues #1708

cexbrayat opened this issue Dec 8, 2022 · 6 comments · Fixed by #1770
Labels
domain 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage v8

Comments

@cexbrayat
Copy link

Environment


  • Operating System: Darwin
  • Node Version: v16.17.0
  • Nuxt Version: 3.0.0
  • Nitro Version: 1.0.0
  • Package Manager: pnpm@7.17.0
  • Builder: vite
  • User Config: app, css, modules, typescript, ignore, i18n, content
  • Runtime Modules: @nuxtjs/i18n@8.0.0-beta.7
  • Build Modules: -

Reproduction

The code in this stackblitz showcases the issue (but not directly in stackblitz, you have to download the code, then run npm install && npm run dev)

Describe the bug

Click on any links in the navbar and see that the navigation fails every second click.

In the following screencast, when I navigate from team to home, for example, the first click fails (it navigates but then returns to team very quickly). The second click works.

Kapture 2022-12-08 at 10 17 50

Additional context

I reproduce this behavior consistently in the minimal repro shared on stackblitz and in the real project where I'm using nuxtjs/i18n

Note that this is triggered by differentDomains: true. Maybe I'm missing something obvious in the configuration, but I've tried several combinations and nothing helps.

This happens with beta.6 and beta.7.

Logs

No response

@kazupon kazupon added the v8 label Dec 8, 2022 — with Volta.net
Copy link
Collaborator

kazupon commented Dec 8, 2022

Thank you for your reporting!

When we will use defference domain, i18n module is changed routing behavior that is handled such as NuxtLink.
Enspecialy, when we are specifying localhost, it will result in unexpected behavior.
honestly, the defference domain is not easy to test, so there will still be bugs 😅

@kazupon kazupon added 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage and removed pending triage labels Dec 8, 2022 — with Volta.net
@cexbrayat
Copy link
Author

@kazupon Thanks for your answer. Note that this behavior occurs with hosts different from localhost as well.

@nWacky
Copy link

nWacky commented Dec 15, 2022

Setting skipSettingLocaleOnNavigate: true in NuxtI18nOptions seems to have helped me

Example NuxtI18nOptions
i18n: {
  langDir: 'i18n',
  locales: [
    {
      code: 'en',
      name: "English",
      domain: 'example.com',
      file: 'en.json',
    },
    {
      code: 'fr',
      domain: 'fr.example.com',
      file: 'fr.json',
    },
  ],
  differentDomains: true,
  detectBrowserLanguage: false,
  skipSettingLocaleOnNavigate: true,
  defaultLocale: 'en',
  vueI18n: {
    legacy: false,
    fallbackLocale: 'en',
  },
}

@ReDev1L
Copy link

ReDev1L commented Dec 25, 2022

useCookie on setup true                                                                                                00:01:50
defautlLocale on setup en                                                                                              00:01:50
detectLocale: initialLocale - en                                                                                       00:01:50
detectBrowserLanguage: (path, strategy, alwaysRedirect, redirectOn, locale) - / prefix_except_default true no prefix en
getLocaleCookie { useCookie: true, cookieKey: 'lang_key', localeCodes: [ 'en', 'ru' ] }                                00:01:50
getLocaleCookie cookie undefined                                                                                       00:01:50
detectBrowserLanguage: cookieLocale undefined                                                                          00:01:50
getBrowserLocale accept-language { 'accept-language': 'ru,en;q=0.9,ru-RU;q=0.8' }                                      00:01:50
detectBrowserLanguage: browserLocale ru                                                                                00:01:50
detectBrowserLanguage: (matchedLocale, cookieLocale, localeFrom) - ru undefined navigator_or_header                    00:01:50
detectBrowserLanguage: first finaleLocale (finaleLocale, lcoaleForm) - ru undefined navigator_or_header                00:01:50
detectBrowserLanguage: vueI18nLocale en                                                                                00:01:50
detectBrowserLanguage: finalLocale !== vueI18nLocale ru                                                                00:01:50
detectLocale: detectBrowserLanguage (browserLocale, stat, reason, from) - ru true undefined navigator_or_header        00:01:50
detectLocale: finaleLocale first (finaleLocale, strategy) - ru prefix_except_default                                   00:01:50
detectLocale: finaleLocale second (finaleLocale, detectBrowserLanguage) - ru {                                         00:01:50
  alwaysRedirect: true,
  cookieCrossOrigin: false,
  cookieDomain: null,
  cookieKey: 'lang_key',
  cookieSecure: false,
  fallbackLocale: 'en',
  redirectOn: 'no prefix',
  useCookie: true
}
detectLocale: finalLocale last (finalLocale, defaultLocale) - ru en                                                    00:01:50
detectLocale: finalLocale - ru                                                                                         00:01:50
first detect initial locale ru                                                                                         00:01:50
final initial locale: ru                                                                                               00:01:50
locale-changing middleware {                                                                                           00:01:50
  fullPath: '/',
  hash: '',
  query: {},
  name: 'index___en',
  path: '/',
  params: {},
  matched: [
    {
      path: '/',
      redirect: undefined,
      name: 'index___en',
      meta: {},
      aliasOf: undefined,
      beforeEnter: undefined,
      props: [Object],
      children: [],
      instances: {},
      leaveGuards: Set(0) {},
      updateGuards: Set(0) {},
      enterCallbacks: {},
      components: [Object]
    }
  ],
  meta: {},
  redirectedFrom: undefined,
  href: '/'
} {
  fullPath: '/',
  path: '/',
  query: {},
  hash: '',
  name: 'index___en',
  params: {},
  matched: [
    {
      path: '/',
      redirect: undefined,
      name: 'index___en',
      meta: {},
      aliasOf: undefined,
      beforeEnter: undefined,
      props: [Object],
      children: [],
      instances: {},
      leaveGuards: Set(0) {},
      updateGuards: Set(0) {},
      enterCallbacks: {},
      components: [Object]
    }
  ],
  meta: {},
  redirectedFrom: undefined,
  href: '/'
}
detectLocale: initialLocale - ru                                                                                       00:01:50
detectBrowserLanguage: (path, strategy, alwaysRedirect, redirectOn, locale) - / prefix_except_default true no prefix ru
getLocaleCookie { useCookie: true, cookieKey: 'lang_key', localeCodes: [ 'en', 'ru' ] }                                00:01:50
getLocaleCookie cookie undefined                                                                                       00:01:50
detectBrowserLanguage: cookieLocale undefined                                                                          00:01:50
getBrowserLocale accept-language { 'accept-language': 'ru,en;q=0.9,ru-RU;q=0.8' }                                      00:01:50
detectBrowserLanguage: browserLocale ru                                                                                00:01:50
detectBrowserLanguage: (matchedLocale, cookieLocale, localeFrom) - ru undefined navigator_or_header                    00:01:50
detectBrowserLanguage: first finaleLocale (finaleLocale, lcoaleForm) - ru undefined navigator_or_header                00:01:50
detectBrowserLanguage: vueI18nLocale ru                                                                                00:01:50
detectLocale: detectBrowserLanguage (browserLocale, stat, reason, from) - ru true undefined navigator_or_header        00:01:50
detectLocale: finaleLocale first (finaleLocale, strategy) - ru prefix_except_default                                   00:01:50
detectLocale: finaleLocale second (finaleLocale, detectBrowserLanguage) - ru {                                         00:01:50
  alwaysRedirect: true,
  cookieCrossOrigin: false,
  cookieDomain: null,
  cookieKey: 'lang_key',
  cookieSecure: false,
  fallbackLocale: 'en',
  redirectOn: 'no prefix',
  useCookie: true
}
detectLocale: finalLocale last (finalLocale, defaultLocale) - ru en                                                    00:01:50
detectLocale: finalLocale - ru                                                                                         00:01:50
detect locale ru                                                                                                       00:01:50
localeSetup false                                                                                                      00:01:50
setLocale: new ->  ru  old ->  ru  initial ->  false                                                                   00:01:50
detectRedirect: targetLocale ->  ru                                                                                    00:01:50
detectRedirect: route ->  {                                                                                            00:01:50
  fullPath: '/',
  hash: '',
  query: {},
  name: 'index___en',
  path: '/',
  params: {},
  matched: [
    {
      path: '/',
      redirect: undefined,
      name: 'index___en',
      meta: {},
      aliasOf: undefined,
      beforeEnter: undefined,
      props: [Object],
      children: [],
      instances: {},
      leaveGuards: Set(0) {},
      updateGuards: Set(0) {},
      enterCallbacks: {},
      components: [Object]
    }
  ],
  meta: {},
  redirectedFrom: undefined,
  href: '/'
}
extendSwitchLocalePathIntercepter: domain ->  http://ru.localhost:3000/  path ->  /                                    00:01:50
detectRedirect: calculate domain routePath ->  http://ru.localhost:3000/                                               00:01:50
redirectPath on locale-changing middleware http://ru.localhost:3000/                                                   00:01:50
navigate options  302 null true false                                                                                  00:01:50
redirect state ->                                                                                                      00:01:50
differentDomains servermode  http://ru.localhost:3000/                                                                 00:01:50
extendSwitchLocalePathIntercepter: domain ->  http://localhost:3000/  path ->  /                                       00:01:50

is this related?

Copy link
Collaborator

kazupon commented Dec 26, 2022

I've just fixed, and released edge version @nuxtjs/i18n-edge@8.0.0-beta.7-27867903.cc6cc78
you can try to use edge version.

@Stiropor
Copy link

Setting skipSettingLocaleOnNavigate: true in NuxtI18nOptions seems to have helped me

Sir, you saved my day 🎉

@kazupon kazupon added the domain label Jul 20, 2023 — with Volta.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage v8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants