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.
This commit is contained in:
Evandro Fonseca Junior committed 2026-04-03 23:25:22 -03:00
1 parent 36b80bc0a8
commit 2144a92349
1 file changed
+8 -8
@@ -193,14 +193,6 @@ export function useRuntimeManager() {
}; };
}, [refresh]); }, [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(() => { const openDraft = useCallback(() => {
setDraftState((current) => { setDraftState((current) => {
const draftConfig = current.isDirty ? current.draftConfig : cloneConfig(current.savedBaseline); 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) => { const commitSavedSnapshot = useCallback((next: RuntimeSnapshot, keepOpen: boolean) => {
setDraftState((current) => ({ setDraftState((current) => ({
...current, ...current,