From 54b1c7d7d789f03bee93fba12dd9dda409794f62 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Sun, 12 Apr 2026 09:40:57 +0200 Subject: [PATCH] Fix IPA/syllable first-click not working (off-by-one in initialLoadDone) The old guard checked if grid was loaded AND set initialLoadDone in the same pass, then returned without rebuilding. This meant the first user-triggered mode change was always swallowed. Simplified to a mount-skip ref: skip exactly the first useEffect trigger (component mount), rebuild on every subsequent trigger (user changes). Co-Authored-By: Claude Opus 4.6 (1M context) --- admin-lehrer/components/grid-editor/useGridEditor.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/admin-lehrer/components/grid-editor/useGridEditor.ts b/admin-lehrer/components/grid-editor/useGridEditor.ts index a689d98..9308dc5 100644 --- a/admin-lehrer/components/grid-editor/useGridEditor.ts +++ b/admin-lehrer/components/grid-editor/useGridEditor.ts @@ -105,10 +105,11 @@ export function useGridEditor(sessionId: string | null) { // We call the API directly with the new values instead of going through // the buildGrid callback, which may still close over stale state due to // React's asynchronous state batching. - const initialLoadDone = useRef(false) + const mountedRef = useRef(false) useEffect(() => { - if (!initialLoadDone.current) { - if (grid) initialLoadDone.current = true + if (!mountedRef.current) { + // Skip the first trigger (component mount) — don't rebuild yet + mountedRef.current = true return } if (!sessionId) return