الانتقال إلى المحتوى
FrontendWeb Performance· 6 دقائق للقراءة

Slow Clicks Aren't a Network Problem: INP and Long Tasks

INP stops at the next paint, so what makes it slow is main-thread work, not the API behind the button.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

The "In stock only" filter on a product listing feels sluggish, and field data puts the page's INP in "needs improvement". The team spends a week caching the products API. Nothing changes, because the filter never touches the network: it filters 20,000 products already in memory and re-renders the list. We rebuilt it and clicked it in headless Chromium 156, unthrottled on a desktop CPU: 240 to 312 ms from click to next frame, across five runs. A version that showed "Updating…" and then waited a full second for an API call measured 16 ms.

The common misconception

The belief: slow interactions come from slow APIs or networks, so INP is something you fix on the backend.

It's an honest mistake. Users do complain that "the button is slow", and many buttons do send a request. The Network panel shows a long bar, the backend is the usual suspect, and a faster API really does make the result arrive sooner. But INP doesn't measure when the result arrives. It measures when the page first reacts, and that is decided on the .

What actually happens

INP ends at the next paint

web.dev states the intent plainly: doesn't try to measure every eventual effect of an interaction, such as network fetches and UI updates from other asynchronous operations, but the time the next paint is blocked. It observes clicks, taps and key presses, not hovering or scrolling, and reports the longest interaction on the page, ignoring one outlier for every 50 interactions. Good is 200 ms or less, poor is above 500 ms, at the 75th percentile.

That's why the API version scored 16 ms: the handler set "Updating…" and returned at its first await, and the browser painted that frame right away. The one-second wait happened after the paint, outside INP.

Three parts, all held up by main-thread work

web.dev splits every interaction into three parts:

  1. Input delay: from the user's input until the first event handler starts. It grows when the main thread is busy with something else.
  2. Processing duration: the time all the event handlers take to run.
  3. Presentation delay: from the end of the handlers until the next frame is presented, which includes the style, layout and paint for whatever the handlers changed.

Our filter spent 33 to 56 ms in its handler and 203 to 255 ms in presentation delay, rendering roughly 13,000 new list items. And input delay needs no slow handler at all: when a 250 ms task from elsewhere on the page was already running, a click whose handler only changed one line of text measured 216 to 224 ms, nearly all of it input delay.

Long tasks are what block it

A task that runs longer than 50 ms is a , and while it runs, the browser can't start your handler or paint a frame. The fix is to yield: end the current task so the browser can render and handle input, and continue the work in a new one.

await alone isn't a yield

Recall how the works: the code after an await runs as a , and the browser never renders while microtasks are pending. So await Promise.resolve() before the heavy work changed nothing in our run: 232 to 248 ms. Yielding means ending the task. setTimeout(resolve, 0) does it but sends your continuation to the back of the queue; scheduler.yield() continues in a prioritized task, ahead of other work at the same priority. It's in Chrome and Edge 129 and Firefox 142 but not Safari, so web.dev's helper falls back to setTimeout:

JavaScript filters.js
filterButton.addEventListener("click", () => {  status.textContent = "Updating…";  render(products.filter((p) => p.inStock)); // same task, no paint  status.textContent = "In stock";});

In the wrong version, "Updating…" never even appears: it's overwritten before any frame is painted. The right version measured 16 to 24 ms over five runs. The work didn't get cheaper, though: the frame that rendered the filtered list was still a long animation frame of 227 to 347 ms. Yielding moved it after the feedback; it didn't remove it.

Part of INPTypical causeWhat helps
Input delayAnother long task is running: third-party scripts, timers, startup codeBreak long tasks up and yield between chunks
Processing durationHandlers do everything at onceDo the visible update, yield, then the rest
Presentation delayA huge DOM change, forced layoutsRender less, avoid layout thrashing
Network wait after the paintA slow API behind the buttonNot part of INP: show feedback, then fix the API for its own sake

How to apply it in your project

  1. Find the interactionCollect INP with attribution from real users, group by interactionTarget, and pick the worst element on the pages with the most traffic.
  2. Read the breakdownLarge input delay points at other long tasks on the page; large processing at your handlers; large presentation delay at how much DOM and layout each update causes.
  3. Paint first, then workMake the visible change, then yield with scheduler.yield() or the setTimeout fallback. Move analytics, saving and other invisible work after the yield.
  4. Shrink the remaining workChunk long loops with a yield between chunks, render only what's visible, and keep reads and writes apart so a handler doesn't force layout.

Key takeaways

  • INP runs from the input to the next painted frame; a network wait after that paint isn't part of it.
  • Its three parts, input delay, processing and presentation delay, all grow with work on the main thread.
  • await on a resolved promise doesn't yield: rendering waits for microtasks. End the task with scheduler.yield() or setTimeout.
  • Yielding lets feedback paint first, but the remaining work still blocks later input, so chunk it and render less.
  • Use INP attribution from the field to see which element and which part to fix.

📚 المصادر

  1. Interaction to Next Paint (INP) — web.dev
  2. Optimize Interaction to Next Paint — web.dev
  3. Optimize long tasks — web.dev
  4. Scheduler: yield() method — MDN
  5. Find slow interactions in the field — web.dev

التعليقات (0)