-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/elastic-sound-fpmpdt
To Reproduce
- Build and run the project with
pnpm build && pnpm startif it's not already running. - Open https://fpmpdt-3000.csb.app/en
- If no client-side exception shows up, hard-refresh until it does.
- Observe the
Minified React error #310(Rendered more hooks than during the previous render.) being logged in the browser's console.
Note:
The project has to be built. In dev-mode, no error occurs. It's also not always the case.
Current vs. Expected behavior
I expect the not-found page inside /[locale] to be rendered without issue. However, the page rendering results in a React error.
Provide environment information
Original
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023
Available memory (MB): 4102
Available CPU cores: 2
Binaries:
Node: 20.9.0
npm: 9.8.1
Yarn: 1.22.19
pnpm: 8.10.2
Relevant Packages:
next: 14.2.0-canary.26 // Latest available version is detected (14.2.0-canary.26).
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.3
Next.js Config:
output: N/AAlso tested with
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Thu Jan 11 04:09:03 UTC 2024
Available memory (MB): 15853
Available CPU cores: 16
Binaries:
Node: 18.20.1
npm: 10.5.0
Yarn: 1.22.22
pnpm: 8.15.5
Relevant Packages:
next: 14.3.0-canary.73 // Latest available version is detected (14.3.0-canary.73).
eslint-config-next: N/A
react: 19.0.0-beta-04b058868c-20240508
react-dom: 19.0.0-beta-04b058868c-20240508
typescript: 5.1.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
App Router, Routing (next/router, next/navigation, next/link)
Which stage(s) are affected? (Select all that apply)
next start (local), Vercel (Deployed)
Additional context
First of all, the crash won't happen 100% of the time, and only in production mode. This took a while to debug 😅
The stars need to align
The crash stops happening, or happens less often, if one of the following is the case:
- The
[locale]/not-found.tsxpage does not include anext/link<Link>. - The
<Suspense>is removed. - The
useRouterand itsuseEffectis commented out. - The data fetching in the server component is taking longer. E.g.
500msinstead of the50msconfigured. This points to a race condition.
Race condition
Because of the race-conditiony nature of the bug, it could not be reproducible on some machines.
next/link links in general?
It seems that any next/link link that will be rendered together with the not found page (e.g. those in the layout) triggers the bug. In a bigger project (where the issue first appeared), turning all the <Link> tags into <a> tags got rid of the issue.