From 1b1ebdb676371139a4ddc54c4e0620e0ce348347 Mon Sep 17 00:00:00 2001 From: David Kaya Date: Wed, 25 Mar 2026 20:16:44 +0100 Subject: [PATCH] fix: move handleCreateScratchpad above early return to fix hooks order The useCallback for handleCreateScratchpad was placed after the early return for the loading state, causing React to see a different number of hooks between the initial render (workspace undefined) and subsequent renders. Move it before the guard and add a null check inside instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/renderer/App.tsx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 1ee4815..a32b012 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -177,16 +177,8 @@ export default function App() { } }, []); - // Loading state - if (!workspace) { - return ( -
-
Loading workspace…
-
- ); - } - const handleCreateScratchpad = useCallback(() => { + if (!workspace) return; const singlePatterns = workspace.patterns .filter((p) => p.mode === 'single' && p.availability !== 'unavailable') .sort((a, b) => { @@ -199,7 +191,16 @@ export default function App() { if (defaultPattern) { void api.createSession({ projectId: SCRATCHPAD_PROJECT_ID, patternId: defaultPattern.id }); } - }, [api, workspace?.patterns]); + }, [api, workspace]); + + // Loading state + if (!workspace) { + return ( +
+
Loading workspace…
+
+ ); + } // Determine main content let content: React.ReactNode;