Skip to content

Bug: <ViewTransition> on a list of a few hundred items blocks the main thread for seconds on every transition #38444

Backlog

Description

@pszmurlo

React version: react-dom 19.3.1 (production build)

What happens

We wrap each card of a board in a named <ViewTransition> so card moves animate. With 300 cards, moving one card blocks the main thread for about 2–3 s; with 1,000 cards, for minutes. Two places in react-dom-client account for it:

  1. The transition.ready handler calls document.documentElement.getAnimations({ subtree: true }). In Chromium that call is roughly cubic in the number of view-transition pseudo-elements: 92 ms for 100 named elements, 5.1 s for 400, 43.6 s for 800, in a plain page with no React. Because React names every <ViewTransition> in the updated part of the tree on each transition, a moderately long list reaches that range even when only one item moves. Memoizing the items doesn't reduce the count: commitNestedViewTransitions still names every nested boundary under a re-rendered parent, and the unchanged ones are only cancelled after measuring.

  2. applyViewTransitionName writes a name and then calls getComputedStyle on the same element, one element at a time (and applyViewTransitionToHostInstancesRecursive calls measureInstance, which reads getBoundingClientRect, before each write). Interleaving writes and reads forces a style recalc, and here a layout, per element. In our app, naming 1,000 elements this way took 3,840 ms, against 43 ms when all names are written first and read afterwards. We avoided most of it with CSS (cards as stacking contexts, no :root:has() on card state), but any app can hit it.

Ideas, if useful

  • For 2: write all names in one pass, then do the inline-element check (getComputedStyle(...).display === "inline") in a second pass.
  • For 1: avoid the document-wide getAnimations when it isn't needed (for example when no <ViewTransition> in the transition changes size), or collect the animations some other way. In Chromium, document.getAnimations() is just as slow.

Repro for 1 without React: save this as a file, open it with ?n=400, and click Run. It starts a view transition with 400 named elements and times documentElement.getAnimations({ subtree: true }) on ready.

getanimations-repro.html
<!doctype html>
<meta charset="utf-8">
<title>getAnimations with many view-transition groups</title>
<style>
  body { font: 14px system-ui; margin: 16px; }
  #list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .item { padding: 6px; border: 1px solid #ccc; background: #f6f6f6; }
</style>
<p>N = <span id="n"></span>. Click "Run" or call run(mode).</p>
<button onclick="run('subtree')">Run</button>
<pre id="out"></pre>
<div id="list"></div>
<script>
const n = Number(new URLSearchParams(location.search).get("n") ?? 300);
document.getElementById("n").textContent = n;
const list = document.getElementById("list");
for (let i = 0; i < n; i++) {
  const el = document.createElement("div");
  el.className = "item";
  el.textContent = "item " + i;
  el.style.viewTransitionName = "item-" + i;
  list.append(el);
}
// mode: "subtree" = documentElement.getAnimations({ subtree: true }) (what React calls),
// "document" = document.getAnimations().
window.run = (mode) => new Promise((resolve) => {
  const transition = document.startViewTransition(() => {
    list.append(list.firstElementChild); // move one item
  });
  transition.ready.then(() => {
    const t0 = performance.now();
    const all = mode === "document"
      ? document.getAnimations()
      : document.documentElement.getAnimations({ subtree: true });
    const ms = performance.now() - t0;
    const vt = all.filter((a) => String(a.effect?.pseudoElement).startsWith("::view-transition")).length;
    const line = `${mode}: ${all.length} animations (${vt} view-transition) in ${ms.toFixed(1)} ms`;
    document.getElementById("out").textContent += line + "\n";
    transition.skipTransition();
    transition.finished.then(() => resolve({ mode, ms: Math.round(ms), animations: all.length }));
  });
});
</script>

Numbers from it (Chromium 159.0.8154.6, headless, macOS): 100 elements 92 ms, 200 → 595 ms, 400 → 5.1 s, 800 → 43.6 s. document.getAnimations() costs the same.

Activity

  1. pszmurlo commented on Nov 29, 2026

    @pszmurlo
    Author

    Chromium issue for the getAnimations() cost, with the same standalone repro: https://issues.chromium.org/issues/591290408

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions