Skip to main content

A 400 ms click where React's render was not the problem

Updated 6 min readMarkdown

I built react-inp-blame, a dev badge that says where the time in a slow React click went. On the demo's sign-in page, almost none of a 400 ms click was React rendering.

The click

The demo is a fake sign-in page called Framely. Type an email and a password, click Log in, and nothing leaves the page, the sign-in is simulated. The badge in the corner reads 400 ms, amber, and the report's verdict for the click, the report.verdict text the library hands your code in a development build, reads:

400 ms click on button "Log in" in SignInPage. The click handler handleLogin ran for
about 399 ms; React's own render took under 1 ms. A second React render landed 295 ms
after the screen updated: 81 ms rendering 260 components from SignInDemo down, 241 of them
inside ProfilePage, mostly PhotoTile (240 of the 260, 72 ms). INP doesn't count it, and
what started it can't be told.

Two renders, then, and only one of them is the click.

The demo sign-in page: an email and a password typed in, a click on Log in, the badge showing the page's INP, the panel opening, and the login row expanding into the explanation

The recording is another run of the same click and ends on 408 ms, 401 ms of it working, with 264 components in the second render. The cover is a third run, 400 ms again, with the second render 294 ms after the screen updated and 256 components. The numbers drift a few ms between runs.

What INP counts

INP times an interaction from the input to the next paint. That is three parts: waiting for the main thread, running the handlers, and updating the screen. On a page with few interactions, INP is just the slowest one, so this one click is the page's number.

The panel splits the click along those lines. In the run on the cover, also 400 ms, waiting was 1 ms, working was 399 ms and updating the screen was 0 ms. Almost all of the 400 was working, and the working was the handler.

The handler is the culprit

Here is the demo's code for the click. It is slow on purpose, and the page says so in its header. burn(400) is a busy loop standing in for work real apps do, like hashing a password on the main thread before the request goes out.

// Mistake 3: the click hashes the password synchronously before the request goes out.
function handleLogin() {
  hashPassword(passwordRef.current);
  setStatus('loading');
  const at = performance.now();
  fetchProfile(email).then((p) => {
    journey.wait('Waiting for the server', performance.now() - at, at);
    onSignedIn(p);
  });
}

function hashPassword(pw: string): string {
  burn(400);
  let h = 0;
  for (let i = 0; i < pw.length; i++) h = (h * 31 + pw.charCodeAt(i)) | 0;
  return h.toString(16);
}

The render caused by that click was tiny. The panel says React re-rendered only 2 components in it. If you open a profiler on this click and look only at React, you find almost nothing to fix, cause the cost isn't in React.

The render that came later

The demo fakes a 200 ms server round trip. When it answers, ProfilePage mounts with 240 photo tiles, and that is the second render in the report. It cost 81 ms for 260 components, and 72 ms of that was PhotoTile.

It landed 295 ms after the screen had already updated, so it belongs to the page and not to the click. INP doesn't count it. People still wait for it though, which is why the panel lists it separately instead of hiding it.

The panel at the end of the recording, as a still you can read: 408 ms, working 401 ms, and a second render 286 ms after the screen updated, 264 components, 240 of them PhotoTile

The last frame of the recording above: 408 ms, working 401 ms, and the second render 286 ms after the screen updated, 264 components, 240 of them PhotoTile.

This is the trap. The loud thing in a React profile of the whole sign-in is the 81 ms commit, with its long list of components, and PhotoTile is an obvious suspect (the demo marks it as a mistake: each tile forces a layout in a layout effect, 240 of them). You could make PhotoTile free and the click would still measure about 400 ms.

Piece of the click Time Counted in INP
Click handler handleLogin about 399 ms Yes
React's own render for the click under 1 ms Yes
Second render, 295 ms after the screen updated 81 ms, 260 components No
Of those, PhotoTile 72 ms, 240 components No

Run it on your own app

It is a development tool first. Install react-inp-blame and add the plugin. For Vite:

// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { inpBlame } from "react-inp-blame/vite";

export default defineConfig({
  plugins: [react(), inpBlame({ runtime: { overlay: true } })],
});

Next.js 14.2 or later has withInpBlame from react-inp-blame/next, and the README has the one extra line some versions need. Restart the dev server and a small dark badge sits in the corner. It reads INP with a dash until you interact, then shows the page's INP so far: green at 200 ms or under, amber up to 500, red above. Click the badge for a panel of recent slow interactions, newest first, and click a row for the full explanation. Any click, tap or key press of 40 ms or more gets a row.

What to check today

Click your slowest button with the badge on. Read the three parts before anything else. If working is most of the time, look at the handler before the render. Then read what rendered after the paint, which is where the second render shows up.

A name in the report is a lead, check it against the profiler. React's development build is slower than production, so confirm anything amber or red in a production build before you act on it.

The demo is at reactinpblame.com/demo, every scenario slow on purpose, and the code is on GitHub.


About the author. Aditya Reddy built react-inp-blame. Three of his fixes are merged in Google's web-vitals library.

About the author

  • Senior Software Engineer focused on web performance, browser instrumentation, and observability. OpenTelemetry Browser approver, IEEE Senior Member, OTCA, and GitLab Level 3 Contributor. Built System Designer, Desk Studio, and react-inp-blame.

The split between the handler time and the later render is the useful part. Once the handler is the 399 ms, a common fix is to paint the loading state first and then run the heavy bit after a yield (scheduler.yield or a setTimeout 0), or move it to a worker, so the next paint is not waiting on it. Also good to see INP ignoring the late commit called out, that is the one people end up chasing in the profiler.