Skip to content

Commit 2a5cf31

Browse files
committed
fix: add cleanup to showTime timer effect to prevent stale timeout
Merged the separate cleanup useEffect into the showTime effect's return function. This ensures the 5s timer is properly cleared when remainingSeconds/totalSeconds change mid-countdown, preventing a stale setShowTime(false) call after the component has moved to a different phase.
1 parent 62e8255 commit 2a5cf31

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎client/src/features/pomodoro/components/ImmersiveTimer.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,13 @@ export default function ImmersiveTimer({
170170
if (showTimerRef.current) clearTimeout(showTimerRef.current);
171171
showTimerRef.current = setTimeout(() => setShowTime(false), 5000);
172172
}
173+
return () => {
174+
if (showTimerRef.current) {
175+
clearTimeout(showTimerRef.current);
176+
showTimerRef.current = null;
177+
}
178+
};
173179
}, [remainingSeconds, totalSeconds]);
174-
useEffect(() => () => { if (showTimerRef.current) clearTimeout(showTimerRef.current); }, []);
175180

176181
// 3.8 心流音乐引擎(工作阶段激活)
177182
const flowMusic = useFlowMusic(focusScore);

0 commit comments

Comments
 (0)