Skip to content

Using notFound in suspended interleaved server component breaks rendering if not-found page (or layout) renders a next/link - production-only - Minified React error #310 #63388

@michaelschufi

Description

@michaelschufi

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/elastic-sound-fpmpdt

To Reproduce

  1. Build and run the project with pnpm build && pnpm start if it's not already running.
  2. Open https://fpmpdt-3000.csb.app/en
  3. If no client-side exception shows up, hard-refresh until it does.
  4. 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/A

Also 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.tsx page does not include a next/link <Link>.
  • The <Suspense> is removed.
  • The useRouter and its useEffect is commented out.
  • The data fetching in the server component is taking longer. E.g. 500ms instead of the 50ms configured. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Linking and NavigatingRelated to Next.js linking (e.g., <Link>) and navigation.bugIssue was opened via the bug report template.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions