Question presented to candidate: "Our toasts pile up when a sync job fails twenty times in a row. Build a toast queue: at most three on screen, the rest wait their turn, each closes after three seconds with a progress bar, and hovering a toast pauses it. When the mouse leaves, it should continue from where it was, not start again."
Requirements:
- A toast API (
success,error,info,dismiss) available app-wide. - At most 3 visible toasts; the rest wait in FIFO order, with a "+N more" indicator.
- When a visible toast closes (timer or close button), the next queued one appears, and its 3 s timer starts only then.
- Hovering or keyboard-focusing a toast pauses its timer; leaving resumes with the remaining time, not the full duration.
- A progress bar that stops while paused;
role="alert"for errors,role="status"otherwise, inside a live region.
What a strong answer should cover:
- One array in arrival order as the source of truth, with "visible" and "waiting" derived from it rather than stored separately.
- The pause and resume maths: record when the timer started, subtract the elapsed time on pause, schedule the remainder on resume.
- Starting each timer when the toast becomes visible, not when it is queued.
- Pausing on focus as well as hover (keyboard users, WCAG timing), and not double-subtracting when both happen.
- Clean timer teardown on close and unmount, and how to test with fake timers.
Clarifying questions expected:
- "Does hovering one toast pause just that one, or the whole stack?"
- "Should errors jump the queue, or stay in arrival order?"
- "What happens when the tab is in the background: keep counting or pause?"
Code / implementation expected: Yes. A queue provider or service, a toast item with a pausable timer, and a stack that renders the first three plus a waiting count.