Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Changing locale and then going back negates locale change nextjs 14 #700

Closed
mp3por opened this issue Dec 6, 2023 · 1 comment
Closed
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@mp3por
Copy link

mp3por commented Dec 6, 2023

Description

When I change locale via the LocaleSwitcher from the example I see the page in German.

However when I click back in the browser I see the page in English again.

My use case is a nextjs app which is embedded in a react-native-web-view and has a dedicated page for changing the language. When the user changes the language there is a back button to navigate away which uses the normal router.back command. Due to the described behaviour when the user navigates back the locale change is overridden.

As a workaround for now I will have a local copy of the history so that I am able to go back by pushing a new url and not via the router.back.

PS: I was not able to fork the bug template in CodeSandbox. Please check permissions or something.

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://codesandbox.io/p/sandbox/next-intl-bug-template-app-forked-zcymvq

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. Click on "Show in German"
  3. Click on browser back button

Result: Content is in English
Expected Result: Content is in German

Expected behaviour

I would expect that when I change the language and go back it will keep the new language. I understand that the URL has precedence over the next-intl cookie however I don't think this is the correct behaviour. If I have already selected my language for the site (and thus have my next-intl cookie set) I should be able to open any link (regardless of the locale) and automatically see the site in my selected locale. Therefore the precedence should be the cookie. When the URL changes the library should monitor the locale parameters and sync it with the cookie via router.replace to ensure consistency with the desired locale and back - forward movement works.

@mp3por mp3por added bug Something isn't working unconfirmed Needs triage. labels Dec 6, 2023
@amannn
Copy link
Owner

amannn commented Dec 6, 2023

I see your point, but changing the locale in next-intl is really about changing the locale segment in the URL—i.e. changing the locale means changing the URL. In case of localized pathnames this can go as far as /en/about vs. /de/ueber-uns therefore patching the browser history is not really an option. I'd also question how often the user really changes the locale and runs into a case where a browser back will lead to a locale change.

If your use case doesn't require a locale prefix, you can disable it via localePrefix: 'never'.

I'll move this to a discussion since this seems to be a usage question and not a bug report.

Repository owner locked and limited conversation to collaborators Dec 6, 2023
@amannn amannn converted this issue into discussion #702 Dec 6, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants