The Toast That Never Left — JavaScript Bug Hunt
Inspired by notification trays everywhere: expired toasts that linger forever.
- Language: JavaScript
- Layer: Frontend
- Difficulty: Medium
- Concepts: Arrays, Mutation
- Modelled on: Notification trays
- Visible tests: adjacent expired toasts are both removed; expiring exactly now counts as expired
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-3
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- adjacent expired toasts are both removed — expected ["z"] but got ["y","z"]
- expiring exactly now counts as expired — expected ["b"] but got ["a","b"]
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by notification trays everywhere: expired toasts that linger forever. Two bugs conspire — the classic splice-while-iterating skip (removing index i shifts the next element into i, then i++ jumps over it), and an exclusive comparison that spares anything expiring exactly now.
toasts.js sweeps the tray.
Bug report
BUG-TOAST · Reported by: design systems
sweep(toasts, now):
- remove every toast with expiresAt <= now
- keep the survivors in order
Observed: when two expired toasts sit side by side, only the first is removed; and a toast expiring exactly at the sweep tick survives forever.
Logs
[tray] sweep(now=6): removed 1 of 2 expiredThe code as shipped
src/ui/toasts.js (editable)
// Removes expired toasts (mutates and returns the array).
exports.sweep = function (toasts, now) {
for (var i = 0; i < toasts.length; i++) {
if (toasts[i].expiresAt < now) {
toasts.splice(i, 1);
}
}
return toasts;
};
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.