fix(app-router): extract RouterContent to prevent hooks error#94147
Open
SpencerJung wants to merge 1 commit into
Open
fix(app-router): extract RouterContent to prevent hooks error#94147SpencerJung wants to merge 1 commit into
SpencerJung wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Related