[MEDIUM] Clear setTimeout timer on unmount in copyToClipboard #43

Closed
opened 2026-06-09 00:03:13 +00:00 by Mark · 0 comments
Owner

Location: src/App.tsx:358-362

Problem: setTimeout(() => setCopiedKey(null), 2000) in copyToClipboard is not cleared on unmount. Timer fires after component unmounts, causing stale state update.

Impact: Memory leak in long-lived sessions; React warning about state update on unmounted component.

Fix: Store timer ID in a useRef; clear in useEffect cleanup or wrap in a custom hook.

const timerRef = useRef<number>();
timerRef.current = window.setTimeout(() => setCopiedKey(null), 2000);
return () => clearTimeout(timerRef.current);

Effort: ~10 mins

**Location:** `src/App.tsx:358-362` **Problem:** `setTimeout(() => setCopiedKey(null), 2000)` in `copyToClipboard` is not cleared on unmount. Timer fires after component unmounts, causing stale state update. **Impact:** Memory leak in long-lived sessions; React warning about state update on unmounted component. **Fix:** Store timer ID in a `useRef`; clear in `useEffect` cleanup or wrap in a custom hook. ```ts const timerRef = useRef<number>(); timerRef.current = window.setTimeout(() => setCopiedKey(null), 2000); return () => clearTimeout(timerRef.current); ``` **Effort:** ~10 mins
Mark 2026-06-09 00:03:13 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/subvault#43
No description provided.