From 2144a92349eafd30de3f26536994f21a9aab6234 Mon Sep 17 00:00:00 2001 From: Evandro Fonseca Junior Date: Fri, 3 Apr 2026 23:25:22 -0300 Subject: [PATCH] fix: resolve ReferenceError accessing scanModels before initialization Moved the useEffect that auto-scans models below the definition of scanModels to fix a ReferenceError caused by the Temporal Dead Zone (TDZ) when calling a block-scoped useCallback function before it was initialized. --- .../src/features/runtime/useRuntimeManager.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tauri-app/src/features/runtime/useRuntimeManager.ts b/tauri-app/src/features/runtime/useRuntimeManager.ts index 0bcd369..89d865e 100644 --- a/tauri-app/src/features/runtime/useRuntimeManager.ts +++ b/tauri-app/src/features/runtime/useRuntimeManager.ts @@ -193,14 +193,6 @@ export function useRuntimeManager() { }; }, [refresh]); - // Auto-scan models when the configured directory changes - useEffect(() => { - const modelsDir = draftState.liveSnapshot.config.models_dir; - if (modelsDir) { - scanModels(modelsDir).catch(() => undefined); - } - }, [draftState.liveSnapshot.config.models_dir, scanModels]); - const openDraft = useCallback(() => { setDraftState((current) => { const draftConfig = current.isDirty ? current.draftConfig : cloneConfig(current.savedBaseline); @@ -381,6 +373,14 @@ export function useRuntimeManager() { } }, []); + // Auto-scan models when the configured directory changes + useEffect(() => { + const modelsDir = draftState.liveSnapshot.config.models_dir; + if (modelsDir) { + scanModels(modelsDir).catch(() => undefined); + } + }, [draftState.liveSnapshot.config.models_dir, scanModels]); + const commitSavedSnapshot = useCallback((next: RuntimeSnapshot, keepOpen: boolean) => { setDraftState((current) => ({ ...current,