fix(app): call SessionsList hooks before the early return (Rules of Hooks)#1426
Open
chphch wants to merge 1 commit into
Open
fix(app): call SessionsList hooks before the early return (Rules of Hooks)#1426chphch wants to merge 1 commit into
chphch wants to merge 1 commit into
Conversation
…ooks) SessionsList defined three useCallback hooks (keyExtractor, renderItem, HeaderComponent) *after* an early `if (!data) return`. When a mounted instance's session list data flips from null to a populated array, the render goes from fewer hooks to more, throwing "Rendered more hooks than during the previous render" and dropping the whole screen to the error boundary. Move the early return below all hooks so the hook order is identical on every render, and null-guard renderItem's `data` lookups (it is now typed nullable above the narrowing, though FlatList only invokes it once data is non-null). Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
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.
SessionsListdefines threeuseCallbackhooks (keyExtractor,renderItem,HeaderComponent) after its earlyif (!data) return, which violates the Rules of Hooks: when a mounted instance'sdata(the memoizedsessionListViewData) flips fromnullto a populated array, the render goes from fewer hooks to more and React throwsRendered more hooks than during the previous render, dropping the whole screen to the error boundary. In normal use the store has already settledsessionListViewDatato[](non-null) before the component mounts, so the early-return path is effectively dead and the bug stays latent — but any code path that mounts the list while the store is still empty and then populates it hits the crash. This moves the early return below all hooks so the hook order is identical on every render, and null-guardsrenderItem'sdatalookups (it's now typed nullable above the narrowing, though FlatList only invokes it oncedatais non-null). No behavior change otherwise.Proof
Reproduced on Expo web by mounting
<SessionsList/>whilesessionListViewData === null, then injecting sessions on the next tick (the null → array transition). Left = currentmain(error boundary: "Rendered more hooks than during the previous render"); right = with this fix (the list renders normally).pnpm typecheckis clean.