fix(appshell): move openSource useCallback above conditional returns#17
Merged
Conversation
Post-Wave-2, AppShell had a Rules of Hooks violation: openSource's useCallback sat BELOW two early-return branches (showWizard, showWelcome). On the first render — when either of those was true — the hook was never called; once both became false on a subsequent render, it ran, shifting the hook order by one slot and triggering: "React has detected a change in the order of Hooks called by AppShell. ... 66. useRef → useRef, 67. undefined → useCallback" The net effect in production: the renderer threw during render on the transition from welcome → main shell, so the Electron window stayed blank for users who launched the app on an existing notebook. Fix: hoist openSource above the conditional returns so every render evaluates the same hook sequence. No behavior change — the callback captures the same state and serves the same citation-click and source- card-click handlers. Verified by pointing Vite at the fixed build and observing the full app shell render correctly; React console no longer emits the hook-order error after the module reload. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
The bug
Post-Wave-2, `AppShell` had a Rules of Hooks violation: `openSource`'s `useCallback` sat below two early-return branches (`showWizard`, `showWelcome`). On the first render — when either of those was true — the hook was never called. Once both became false on a subsequent render, it ran, shifting the hook order by one slot and triggering:
The net effect in production: the renderer threw during render on the transition from welcome → main shell, so the Electron window stayed blank for users who launched the app on an existing notebook.
The fix
Hoist `openSource` above the conditional early-return blocks so every render evaluates the same hook sequence. No behavior change — the callback captures the same state and serves the same citation-click and source-card-click handlers.
Verified
🤖 Generated with Claude Code