-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
With LocalePrefix: 'never' locale switches to previous choice on navigating app pages #786
Comments
Hey, thanks for the report! I tried reproducing it but no luck unfortunately yet: Kapture.2024-01-18.at.09.05.40.mp4Am I doing something wrong here? |
Looks like you are doing the same, but for me it reproduces every time. Issue.movI've tried to use different versions and firstly face this behaviour with latest version, I experimented that why maybe it has old version in package lock. My idea was that it can work on old version because when I run it with version 3.0.1 first time it seems worked as on your video, but after I tried find a version it start working so on all the version I've tried including 3.0.1. I even tried to use different node version and next version. Issue is still there. |
Interesting, not sure why you're seeing a different result. There is however something related I saw recently that could explain this bug. Reproduction:
(2) is a problem specific to Vercel. It also affects new visits, so e.g. if you have (3) is a problem specific to Next.js. Opting out of the router cache for navigations that change the locale would be ideal, but maybe we can update the cookie manually by writing to I think addressing (3) could help with your use case. |
I made some progress in regard to this in #790. After hitting a blocker, I wanted to submit a bug report to Next.js, but found that the latest canary version of Next.js seems to improve the story here. You can see my reproduction here: https://github.com/amannn/nextjs-bug-router-cache. After upgrading to the latest canary the buggy behavior was gone. I think we should wait for the next stable release of Next.js and then continue looking into this. Thanks again for the report! |
…Cache is used (#790) Fixes #786 If you frequently change the locale, Next.js will at some point use the Router Cache to return a previous response immediately, not making a request to the server. This has the side effect that no `set-cookie` response header is returned that will update the locale cookie. To address this, `next-intl` navigation APIs will now manually keep the cookie in sync. Note that a related issue described in #786 was addressed in Next.js 14.1, so upgrading both `next` and `next-intl` is recommended.
So it turns out just a few hours after my comment Next.js 14.1 was released—which seems to fix the issue :). #790 furthermore includes a relevant fix for you. Updating both Thanks again for the report! |
Great thanks for your support and all work you are doing! |
May I say that the issue of having wrong cookie under for example if you visit '/en' the NEXT_LOCALE will be the previous one and so on without having localePrefix sat to 'never' |
@bim-oulabi Can you open a new issue with a reproduction? |
I want to apologize as the issue was not because of next-intl, To put it here in case anyone faced the issue in the future, If you are using custom next/link to change locale Disable prefetching by using As prefetch will override the locale cookie with the new locale Or diasble default link behavior by using And navigate using hooks |
Adding |
Newest Next.js version 14.2.3 breaks it down again, downgraded to Next.js 14.1.4 (with next-inl 3.13.0) and it works |
Seems like, there was a new report about this in #1066. I'll reopen this for the time being until this is fixed on the Next.js side. Does anyone know if there's an upstream bug report? If not, it might be a good idea to create one, maybe for the Next.js team to create a regression test. Maybe as a workaround, you could call
(source) |
Calling const handleLocaleChange = (locale: string) => {
startTransition(() => {
router.replace(`${pathname}?${searchParams.toString()}`, { locale });
router.refresh(); // clear caching to make sure the locale cookie is set correctly
});
}; |
Seems to be broken again, and adding |
Same issue here with |
I'll try other solutions, but I wouldn't want to remove prefetch, as it helps to have faster navigation between pages. |
This is still an issue even with experimental: {
staleTimes: {
static: 0,
dynamic: 0,
},
} None of the mentioned workarounds worked. |
Description
While I used
LocalePrefix: 'never'
configuration I faced strange behaviour - if I navigate to any page of my app then change locale I see that locale was changed to previous choice when I navigate to other pages. I created CodeSandbox example of the issue, but looks likeLocalePrefix: 'never'
is not working there (I added a link to show this), you can download sources to run it locally.Addition to this issue (it might be helpful): If I change locale several times on the third time it stops changing
NEXT_LOCALE
cookie value, but it works well only withLocalePrefix: 'always'
Mandatory reproduction URL (CodeSandbox or GitHub repository)
https://codesandbox.io/p/devbox/next-intl-bug-template-app-forked-r7cscn
Reproduction description
Steps to reproduce:
/home
pagePage
link - it opens '/page' pageSwitch to German
linkPage
link - there are two unexpected results: page will be in English or application crashes with text on the screen:Application error: a client-side exception has occurred
and in console there is this log:Expected behaviour
Locale and translations should stay in German
The text was updated successfully, but these errors were encountered: