Fix final 4 resilience edge cases

This commit is contained in:
2026-06-01 10:54:35 +02:00
parent 40704fa49b
commit 1c223e3cf6
4 changed files with 26 additions and 17 deletions
+10 -5
View File
@@ -289,8 +289,8 @@ export default function PreviewScreen({
}
};
// Auto-save and exit
const handleExit = useCallback(async () => {
const handleExitRef = useRef<() => void>();
handleExitRef.current = async () => {
if (idleTimerRef.current) clearTimeout(idleTimerRef.current);
if (!mountedRef.current) return;
if (isProcessing) return;
@@ -319,15 +319,20 @@ export default function PreviewScreen({
setIsProcessing(false);
state.onReset();
}
}, []); // Stable reference
};
// Auto-save and exit
const handleExit = useCallback(async () => {
if (handleExitRef.current) handleExitRef.current();
}, []);
// Idle timer logic
const resetIdleTimer = useCallback(() => {
if (idleTimerRef.current) clearTimeout(idleTimerRef.current);
idleTimerRef.current = setTimeout(() => {
handleExit();
if (handleExitRef.current) handleExitRef.current();
}, 60000);
}, [handleExit]);
}, []);
useEffect(() => {
resetIdleTimer();