Skip to content

fix(appshell): move openSource useCallback above conditional returns#17

Merged
vikranthreddimasu merged 1 commit into
mainfrom
fix/appshell-hooks-order
Apr 18, 2026
Merged

fix(appshell): move openSource useCallback above conditional returns#17
vikranthreddimasu merged 1 commit into
mainfrom
fix/appshell-hooks-order

Conversation

@vikranthreddimasu

Copy link
Copy Markdown
Owner

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:

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.

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

  • `npm run build` clean
  • Loaded the fixed module in Vite and confirmed the full app shell renders, sidebar populates, chat streams, source panel shows citations [1]–[5]. React devtools no longer emits the hook-order error.

🤖 Generated with Claude Code

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>
@vikranthreddimasu vikranthreddimasu merged commit d62c159 into main Apr 18, 2026
2 checks passed
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.

1 participant