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

bug: inconsistent redirects and locale detection #1850

Closed
tafelnl opened this issue Feb 9, 2023 · 2 comments · Fixed by #2164 or #2252
Closed

bug: inconsistent redirects and locale detection #1850

tafelnl opened this issue Feb 9, 2023 · 2 comments · Fixed by #2164 or #2252

Comments

@tafelnl
Copy link

tafelnl commented Feb 9, 2023

Environment

  • Node Version: v16.14.2
  • Nuxt Version: 3.2.0
  • Nitro Version: 2.2.1
  • Builder: vite
  • User Config: ssr, modules, i18n, typescript
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-8hn8cb

Describe the bug

I think there's quite some inconsistencies/unclarity in this plugin regarding redirection and locale detection.


For the rest of this issue, suppose we have the following base config set:

  i18n: {
    locales: [
      {
        code: 'en',
        name: 'English',
        iso: 'en-GB',
      },
      {
        code: 'nl',
        name: 'Nederlands',
        iso: 'nl-NL',
      },
    ],
    defaultLocale: 'en',
  },

A few examples:


1.

with the following settings:

  i18n: {
    // ... base config ...
    strategy: 'prefix',
  },

If your browser locale is set to nl and you navigate to /, the following will happen:

  • the logs will detect nl is your browser locale
  • not redirected anywhere (stays on /) [1]
  • ends with a 302 Found status code [2]
  • locale wrongly set to en instead of nl [3]
  • cookie wrongly set to en instead of nl [4]

[1] although from the docs I understand the prefix strategy should redirect to the correct locale.
[2] which is not good for SEO and just in general unexpected I guess
[3] I don't know why this would happen
[4] I don't understand when a cookie will be or will not be set (see example 2. also)


2.

with the following settings:

  i18n: {
    // ... base config ...
    detectBrowserLanguage: {
      alwaysRedirect: true,
    },
    strategy: 'prefix',
  },

If your browser locale is set to nl and you navigate to /, the following will happen:

  • the logs will detect nl is your browser locale
  • not redirected anywhere (stays on /) [1]
  • ends with a 302 Found status code [2]
  • locale correctly set to nl
  • no cookie will be set [5]

[5] Weird because in the previous example, it was set (incorrectly, but that doesn't matter here for now). So I think it's unexpected to not set it here.


3.

with the following settings:

  i18n: {
    // ... base config ...
    detectBrowserLanguage: {
      alwaysRedirect: true,
      redirectOn: 'no prefix',
    },
    strategy: 'prefix',
  },

If your browser locale is set to nl and you navigate to /foobar, the following will happen:

  • the logs will detect nl is your browser locale
  • not redirected anywhere (stays on /foobar) [1]
  • ends with a 302 Found status code [2]
  • locale wrongly set to en instead of nl [6]
  • cookie wrongly set to en instead of nl [4]

[6] Which is weird, because as we saw in the previous example, for the root it was correctly set to nl

Additional context

Maybe these examples should have been split up into separate issues. But I'm not sure if they are or are not related to each other.

Logs

No response

@Suniron
Copy link

Suniron commented Feb 9, 2023

Same error with nuxt bridge

@ashour
Copy link

ashour commented Apr 11, 2023

I've encountered similar behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants