Bug: outOfFocusTimeouts array grows unboundedly — cleared timeout ids never removed from array
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- frontend, performance
Research direction
Start in frontend/src/ts/states/test.ts, where outOfFocusTimeouts is populated, and inspect utils/misc.ts:148-153, where clearTimeouts handles the entries. Trace the callers to confirm whether clearing all stored IDs or retaining only the latest ID preserves the intended blur/refocus behavior. Done means cleared timeout IDs are no longer retained and repeated unfocus/refocus events no longer grow the array indefinitely.
Written by the indexing model from the issue text.
Description
Did you clear cache before opening an issue?
- I have cleared my cache
Is there an existing issue for this?
- I have searched the existing open and closed issues
Does the issue happen when logged in?
Yes
Does the issue happen when logged out?
Yes
Does the issue happen in incognito mode when logged in?
Yes
Does the issue happen in incognito mode when logged out?
Yes
Issue details
Current Behavior
outOfFocusTimeouts in frontend/src/ts/states/test.ts accumulates timeout ids forever:
// states/test.ts:38-54
const outOfFocusTimeouts: (number | NodeJS.Timeout)[] = [];
...
} else {
outOfFocusTimeouts.push(
setTimeout(() => { set(val); }, 1000),
);
}
Every unfocus event pushes a new id onto the array. clearTimeouts() (utils/misc.ts:148-153) only calls clearTimeout on each entry but never removes them from the array, so the array grows monotonically for the entire session. Long sessions with frequent alt-tabbing accumulate thousands of stale numeric ids (small but unnecessary retained memory, and the array scan in clearTimeouts grows linearly).
Expected Behavior
Remove consumed entries after clearing, e.g.:
export function clearTimeouts(timeouts: (number | NodeJS.Timeout)[]): void {
timeouts.forEach((to) => clearTimeout(to));
timeouts.length = 0;
}
or store only the latest timeout id, since scheduling a newer unfocus supersedes older pending ones anyway.
Steps To Reproduce
- Open devtools memory snapshot / add a breakpoint log on
outOfFocusTimeouts.push. - Blur/refocus the window repeatedly during tests.
- Array length increases without bound and is never reset.
Environment
- OS: Any
- Browser: Any
- Found via source review of
master@ 91bd24bb8
- Dominant language
- TypeScript
- Stars
- 20.7k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from monkeytypegame/monkeytype
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
monkeytypegame/monkeytype#8365 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
monkeytypegame/monkeytype#8364 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
monkeytypegame/monkeytype#8363 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
monkeytypegame/monkeytype#8362 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
monkeytypegame/monkeytype#8361 · 2 comments ·
All issues in monkeytypegame/monkeytype
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·