Bug: outOfFocusTimeouts array grows unboundedly — cleared timeout ids never removed from array

Aperta Adatta ai principianti
#8,366 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Inizia in frontend/src/ts/states/test.ts, dove viene popolato outOfFocusTimeouts, e analizza utils/misc.ts:148-153, dove clearTimeouts gestisce le voci. Traccia i chiamanti per confermare se cancellare tutti gli ID memorizzati o conservare solo l’ID più recente preserva il comportamento previsto di blur/refocus. Il lavoro è completato quando gli ID dei timeout cancellati non vengono più conservati e gli eventi ripetuti di unfocus/refocus non fanno più crescere l’array indefinitamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
  1. Open devtools memory snapshot / add a breakpoint log on outOfFocusTimeouts.push.
  2. Blur/refocus the window repeatedly during tests.
  3. Array length increases without bound and is never reset.
Environment
  • OS: Any
  • Browser: Any
  • Found via source review of master @ 91bd24bb8
Lingua principale
TypeScript
Stelle
20.7k
Fork
3.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di monkeytypegame/monkeytype

Tutte le issue di monkeytypegame/monkeytype

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.