amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

use broswer back & forword & refresh will lead to url locale & cookie not sync #1418

Closed GrahamQuan closed 1 month ago

GrahamQuan commented 1 month ago

Description

[Bug]

When using browser navigate back & forward & refresh, url locale & cookie locale not sync, Is it expected?

[Behavior]

  1. lets say now in /en/blog
  2. switch locale to like /ja/blog
  3. click /pricing, now /ja/pricing
  4. click browser back button 2 times on the top menu, now is /en/blog (url locale will be en, but cookie locale is still ja)
  5. click /pricing page, go to /ja/pricing since cookie is ja or maybe cache?
  6. click /blog page, go to /ja/blog or /en/blog (yes this will be 2 results)

[Basically]

using browser navigate will make locale mess

[Next13 remove router event]

We can't really listen to router.event cause next13 /app remove it, which means we can't modify cookie locale when use browser back & forward, see https://github.com/vercel/next.js/discussions/41934

[version]

Verifications

Mandatory reproduction URL

App Router

Reproduction description

[Behavior]

  1. lets say now in /en/blog
  2. switch locale to like /ja/blog
  3. click /pricing, now /ja/pricing
  4. click browser back button 2 times on the top menu, now is /en/blog (url locale will be en, but cookie locale is still ja)
  5. click /pricing page, go to /ja/pricing since cookie is ja or maybe cache?
  6. click /blog page, go to /ja/blog or /en/blog (yes this will be 2 results)

Expected behaviour

use broswer back & forword & refresh, url locale & cookie will sync