From 5244e107288408ca846fec7773c7050a36e9963c Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Sun, 12 Apr 2026 09:59:49 +0200 Subject: [PATCH] Fix IPA/syllable race condition: loadGrid no longer depends on buildGrid loadGrid depended on buildGrid (for 404 fallback), which depended on ipaMode/syllableMode. Every mode change created a new loadGrid ref, triggering StepGridReview's useEffect to load the OLD saved grid, overwriting the freshly rebuilt one. Now loadGrid only depends on sessionId. The 404 fallback builds inline with current modes. Mode changes are handled exclusively by the separate rebuild useEffect. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../components/grid-editor/useGridEditor.ts | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/admin-lehrer/components/grid-editor/useGridEditor.ts b/admin-lehrer/components/grid-editor/useGridEditor.ts index 9308dc5..188357d 100644 --- a/admin-lehrer/components/grid-editor/useGridEditor.ts +++ b/admin-lehrer/components/grid-editor/useGridEditor.ts @@ -81,8 +81,19 @@ export function useGridEditor(sessionId: string | null) { `${KLAUSUR_API}/api/v1/ocr-pipeline/sessions/${sessionId}/grid-editor`, ) if (res.status === 404) { - // No grid yet — build it - await buildGrid() + // No grid yet — build it with current modes + const params = new URLSearchParams() + params.set('ipa_mode', ipaMode) + params.set('syllable_mode', syllableMode) + const buildRes = await fetch( + `${KLAUSUR_API}/api/v1/ocr-pipeline/sessions/${sessionId}/build-grid?${params}`, + { method: 'POST' }, + ) + if (buildRes.ok) { + const data: StructuredGrid = await buildRes.json() + setGrid(data) + setDirty(false) + } return } if (!res.ok) { @@ -99,7 +110,10 @@ export function useGridEditor(sessionId: string | null) { } finally { setLoading(false) } - }, [sessionId, buildGrid]) + // Only depends on sessionId — mode changes are handled by the + // separate useEffect below, not by re-triggering loadGrid. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [sessionId]) // Auto-rebuild when IPA or syllable mode changes (skip initial mount). // We call the API directly with the new values instead of going through