Improve INP in React Apps: A Practical Core Web Vitals Guide
Interaction to Next Paint (INP) became a Core Web Vital in March 2024, replacing First Input Delay. FID only measured the delay before the browser started handling the first interaction. INP looks at every click, tap and key press during a visit and reports one of the slowest, so it catches the sluggish dropdown or the filter that freezes the page. This guide shows how to measure INP in a React app and how to fix it.
Key takeaways
- A good INP is 200 ms or less at the 75th percentile, and anything above 500 ms is poor.
- INP is made of input delay, processing time and presentation delay.
- Long tasks on the main thread are the usual cause.
- Measure in the field first, then reproduce in DevTools.
What INP measures
For each interaction, the browser measures the time from the user's input until the next frame is painted. That time has three parts:
- Input delay. The main thread was busy, so the event handler could not start.
- Processing time. Your event handlers and the React work they trigger.
- Presentation delay. Rendering, layout and paint after the handlers finish.
To score well, all three must stay small, which means keeping the main thread free and keeping each update cheap.
Measure it first
Lab tools can miss INP because it depends on real interactions. Collect it from real users with the web-vitals library and its attribution build, which tells you which element and which phase was slow.
import { onINP } from "web-vitals/attribution";
onINP(({ value, attribution }) => {
navigator.sendBeacon(
"/analytics",
JSON.stringify({
value,
target: attribution.interactionTarget,
inputDelay: attribution.inputDelay,
processing: attribution.processingDuration,
presentation: attribution.presentationDelay,
}),
);
});Then reproduce the worst interactions in the Chrome DevTools Performance panel and look for long tasks over 50 ms.
Fix 1: break up long tasks
If a handler does a lot of synchronous work, split it and yield to the browser between chunks so it can paint.
function yieldToMain() {
if (globalThis.scheduler?.yield) return scheduler.yield();
return new Promise((resolve) => setTimeout(resolve, 0));
}
async function processAll(items) {
for (const item of items) {
handle(item);
await yieldToMain();
}
}Fix 2: mark non-urgent React updates
When typing in a search box filters a large list, the keystroke should feel instant while the list catches up. useTransition and useDeferredValue tell React which update can wait.
const [query, setQuery] = useState("");
const deferredQuery = useDeferredValue(query);
return (
<>
<input value={query} onChange={(e) => setQuery(e.target.value)} />
<ResultsList query={deferredQuery} />
</>
);The input updates immediately, and the expensive list re-renders at lower priority.
Fix 3: render less
- Virtualize long lists. Render only the rows in view.
- Avoid re-rendering the whole tree. Keep state close to where it is used and split large components.
- Memoize deliberately.
React.memoanduseMemohelp when you have measured an expensive render, and the React Compiler can automate much of this. - Do not run heavy work in event handlers. Move it to a worker or defer it.
Fix 4: ship less JavaScript
Every kilobyte of JavaScript has to be downloaded, parsed and executed, and hydration can block interactions on load. Route-based code splitting, lazy loading heavy components and server rendering the static parts all reduce main-thread work. On a multi-tenant SaaS single-page app I optimised, route splitting and vendor chunking cut the main bundle from 4.69 MB to 2.38 MB, which makes every later interaction cheaper because there is simply less code competing for the thread.
Fix 5: avoid layout thrashing
Reading layout values such as offsetHeight right after writing styles forces the browser to recalculate layout synchronously. Batch reads together, then writes, and prefer CSS transitions over JavaScript-driven animation where you can.
A simple checklist
- Add
web-vitalsattribution reporting. - Find the three worst interaction targets.
- Record each in DevTools and locate the long task.
- Split the task, defer the update, or reduce the render.
- Re-measure in the field after deploying.
Performance work like this is part of my performance and PWA service, and you can see the results in my project work.
- Core Web Vitals
- INP
- React
- performance
- web-vitals