next.js: Minified React error #310: Rendered more hooks than during the previous render.

Link to the code that reproduces this issue

https://github.com/moroshko/rendered-more-hooks-issue

To Reproduce

Once the application is started in Dev mode, and http://localhost:3000 is visited, the following error appears:

Application error: a client-side exception has occurred while loading …

and the console shows:

Rendered more hooks than during the previous render.

Then, the error magically disappears and the page is rendered as expected.

Visit here to experience this yourself.

Current vs. Expected behavior

There should be no error.

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 24.4.0: Wed Mar 19 21:16:31 PDT 2025; root:xnu-11417.101.15~1/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 12
Binaries:
  Node: 22.11.0
  npm: 10.8.1
  Yarn: 1.22.22
  pnpm: 9.14.2
Relevant Packages:
  next: 15.4.0-canary.2 // Latest available version is detected (15.4.0-canary.2).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: N/A

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

Redirects, Server Actions

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

Vercel (Deployed)

Additional context

If I do any of the following, the issue is gone:

  • Remove redirect("/dashboard") on the Home page and render some HTML instead.
  • Replace <Suspense> with a <div> in SignedInLayout.
  • Don’t call the getAuth() server action in Providers.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Running into this issue as well on 15.1.2, similar cause to what @glekner discovered. One of our client context providers in our root layout file fetches some data and then updates its internal value with whatever it got from the server. This fetch is done via a server action which does no mutations, just fetches some data.

Though, while the layout client component is fetching its data a redirect happens, and causes this error.

  GET /one 200 in 78ms
~Root layout client component calls action to fetch data
~Page level (page one) server component performs redirect based on some condition
  GET /two 200 in 61ms
~Server action starting on server (sent from root layout)
~Resolving data from server action
  POST /one 200 in 92ms
  GET /two 200 in 37ms
~Server action starting on server
~Resolving from server action
  POST /two 200 in 72ms

Next Info:

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:40 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6031
  Available memory (MB): 36864
  Available CPU cores: 14
Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: 9.15.5
Relevant Packages:
  next: 15.2.1 // There is a newer version (15.3.1) available, upgrade recommended! 
  eslint-config-next: 15.2.1
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.4.5
Next.js Config:
  output: N/A