vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.35k stars 26.78k forks source link

locale is always the default locale on page reload when using the pages router + middleware + edge runtime #61201

Open gabrielf opened 8 months ago

gabrielf commented 8 months ago

Link to the code that reproduces this issue

https://github.com/gabrielf/next-edge-runtime-locale-bug

To Reproduce

  1. Start the minimal bug reproduction using npm run dev
  2. Visit http://localhost:3000/en in a browser

Current vs. Expected behavior

As I visit /en I expect the locale to be en but it is default.

Clicking the link English leads to a client side navigation to the same page which correctly shows the locale as en.

Additional links and their purpose:

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020
Binaries:
  Node: 18.18.2
  npm: 9.8.1
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.1-canary.12 // Latest available version is detected (14.1.1-canary.12).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Internationalization (i18n), Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

The bug may have been introduced in version 13.4.20-canary.24 as using 13.4.20-canary.23 works fine but 24 does not. The bug seems to have existed since then.

pierrebiver commented 7 months ago

Same issue here using pages router + middleware and Next js 14.1. When disabling the middleware it works just fine.

VaDominikKienzler commented 5 months ago

Weird how 13/14 can be considered stable if translations become completely broken when updating ...