How should large single-page applications restructure event handlers to reduce INP without sacrificing interactivity on complex filtering interfaces?
Answered 3-minute answer rooted in 3 pages
Split each filter handler into what the visitor must see now and what can follow. The handler should make the immediate visual change, such as the checkbox checked, the chip added or a loading state shown, and then yield so the browser can paint that frame. The heavy work, such as filtering a large dataset, updating state and re-rendering the results, runs afterward in smaller pieces. INP measures the time from the input to the next painted frame, so a handler that paints its acknowledgment quickly and does the rest after yielding keeps that interaction fast without removing any functionality.
Why filter handlers produce slow interactions
web.dev’s INP article counts three phases per interaction: input delay, processing duration, the time the event handlers take to run, and presentation delay. A filter click in a large SPA can fill both of the last two: the handler filters thousands of items and updates the application state, then the framework re-renders the result list, and the browser has to lay out and paint it before the frame appears.
If all of that runs in one synchronous task, the visitor sees nothing until it finishes. web.dev’s long tasks guide defines a task over 50 milliseconds as long; a single filter task on a large dataset can exceed that by a wide margin on a mid-range phone.
The restructuring pattern
1. Paint the acknowledgment first. Update only the control the visitor touched and a lightweight loading indicator for the results. This change is small, so its frame is cheap.
2. Yield before the heavy work. web.dev’s INP optimization guide advises yielding to the main thread frequently and describes a refined version: yield immediately after the callback that updates the user interface, “so rendering logic can run sooner”. The guide shows a cross-browser way to schedule the deferred work so it runs after the next frame rather than before it; moving the work into requestAnimationFrame() alone does not achieve that.
3. Break the computation into chunks. Filtering a very large list can be done in batches with a yield between them, so other inputs, such as a second filter click, can be handled in between.
4. Make the re-render smaller. The most expensive part can be rendering, not filtering. Render only the visible results, virtualize long lists, and avoid re-rendering components whose data did not change. The INP guide notes that rendering work grows with DOM size.
5. Cancel stale work. When a visitor clicks several filters quickly, only the latest result matters. Abandon in-progress work for older selections instead of finishing it.
What “without sacrificing interactivity” means here
The pattern does not remove features or debounce the controls into unresponsiveness. Every click is acknowledged in the next frame; the results arrive shortly after. The alternatives that do sacrifice interactivity, such as disabling the controls while filtering, or making filters apply only after a separate “Apply” click, are design choices to take only if the work cannot be made fast enough this way.
Measuring the change
- Collect INP with attribution for the filter interactions from real visits, and note which phase was slow before the change.
- Trace the interaction in the lab under CPU throttling to see the task structure: one long task before, several short ones after.
- Confirm in the field that the 75th percentile INP for the filter interactions moved under 200 milliseconds on the devices that were slow.
A filter that paints its response in the first frame and finishes over the next few records a lower INP than one that freezes for the same total time, because INP stops at the next paint.
Answers that share these roots
- What is the mechanism by which total JavaScript payload size affects INP even when the initial page load appears fast and LCP is within the good threshold? shares 3 pages
- Why can replacing synchronous JavaScript with requestAnimationFrame callbacks sometimes increase INP rather than decrease it? shares 2 pages
- Why do sites that strictly enforce a 200KB JavaScript budget sometimes still fail INP when they rely heavily on CSS animations and complex DOM trees? shares 2 pages
- How does Interaction to Next Paint differ mechanistically from First Input Delay in what it captures about main-thread responsiveness? shares 1 page
- How do third-party scripts affect Core Web Vitals when they load asynchronously but still compete for main-thread execution time during user interactions? shares 1 page
- What diagnostic approach should you use when INP scores are poor at the 75th percentile but good at the median, indicating a long-tail interaction problem? shares 1 page
Leave a Reply