Skip to content

fix(app-router): extract RouterContent to prevent hooks error#94147

Open
SpencerJung wants to merge 1 commit into
vercel:canaryfrom
SpencerJung:fix/63121-router-hooks-error
Open

fix(app-router): extract RouterContent to prevent hooks error#94147
SpencerJung wants to merge 1 commit into
vercel:canaryfrom
SpencerJung:fix/63121-router-hooks-error

Conversation

@SpencerJung
Copy link
Copy Markdown

Description

This PR fixes the 'Rendered more hooks than during the previous render' error that occurs in the App Router during navigation and redirects.

Problem

The Router component calls useActionQueue followed by useMemo and other hooks. When the state returned by useActionQueue changes between renders (e.g., during redirects or navigation), the hook count can become inconsistent, causing React errors.

Solution

Extracted the content after useActionQueue into a separate RouterContent component. This ensures that hooks are always called in the same order within each component, preventing the hooks error.

Verification

  • LSP diagnostics clean on changed files
  • Type check passed (requires pnpm install)
  • Tests passed (requires pnpm install)

Related

The Router component was calling useActionQueue followed by useMemo
and other hooks. When the state returned by useActionQueue changed
between renders (e.g., during redirects or navigation), the hook
count could become inconsistent, causing 'Rendered more hooks than
during the previous render' errors.

This fix extracts the content after useActionQueue into a separate
RouterContent component, ensuring that hooks are always called in
the same order within each component.

Fixes vercel#63121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Rendered more hooks than during previous render" when using App Router

1 participant