A loading spinner never paints
A click handler shows a spinner and processes a large array in many small chunks. Each chunk uses queueMicrotask to schedule the next chunk. The spinner still doesn’t paint until processing ends. Why? Suggest one way to keep the UI responsive.
Model Answer & Explanation
The browser drains queued microtasks, including new ones they enqueue, before it can move on to the next task or take a rendering opportunity. Repeated microtasks do not yield to rendering. Split the work across tasks with bounded chunks, or move heavy CPU work into a Web Worker and leave the main thread free for the UI.
What a Strong Answer Covers
- Distinguish yielding within a microtask checkpoint from yielding to a new task.
- Offer a fix that lets the browser render and handle input.