🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

React Internals: Fibers, Diffing and Lanes

React AdvancedđŸŸĸ Free Lesson

Most React performance problems are not mysterious. They are the visible consequence of a small set of rules about how React schedules work, decides which parts of a tree to update, and yields to the browser. Learn those rules and a slow list stops being an unsolved puzzle and becomes a predictable outcome you can point at in a profiler.

â„šī¸The mental model

React builds a tree of lightweight objects describing what the screen should show, compares it with the tree it built last time, and then applies the smallest set of changes to the real DOM. Everything else, including Suspense, transitions and memoization, exists to make that comparison interruptible and correctly prioritized.

Two phases: render and commit

Render is pure. During it React calls your functions, evaluates JSX, and produces a description of the interface without touching the browser. Because nothing observable happens yet, React may throw the result away and start again. That is exactly what happens in concurrent rendering: an update can be paused partway through, a higher priority update can run to completion, and React then discards the abandoned work rather than showing the user a half-finished screen.

Commit is the point of no return. React takes the finished tree, computes the differences against what is on screen, mutates the DOM, runs layout effects, then paint effects, and finally passive effects such as data subscriptions scheduled for the next frame. If an error is thrown during render, nothing reaches the user, which is why an error boundary can still show the previous screen. If an error is thrown during commit, the DOM may already be inconsistent, and that is the case error boundaries exist to contain.

This split explains a rule people learn the hard way: never perform a side effect during render. Rendering can run twice, can be abandoned, and can run for a component the user never sees. Effects are the designated place for anything that touches the outside world, because they run only after React has committed to the output.

How React decides which elements changed

Reconciliation compares two trees by position and key. For children in an array, React walks the old and new lists in order and matches elements by their type first: if the type is identical, it reuses the existing DOM node and updates props; if the type differs, it tears the old subtree down and builds a new one. When keys are present on keyed children, React uses them to match elements across positions, so a reorder becomes a move instead of a full rebuild.

The consequence of a missing or index-based key is not theoretical. The demo below shows a list that is reversed after items have been typed into, where index keys cause React to hand each input the state belonging to a different row.

import { useState } from 'react';

function RowList({ reverse }) {
  const [text, setText] = useState({});
  const rows = ['alpha', 'beta', 'gamma'];
  const shown = reverse ? [...rows].reverse() : rows;

  return (
    <ul>
      {shown.map((label, index) => (
        <li key={reverse ? label : index}>
          <input
            aria-label={`Notes for ${label}`}
            value={text[label] || ''}
            onChange={(e) =>
              setText({ ...text, [label]: e.target.value })
            }
          />
          <span>{label}</span>
        </li>
      ))}
    </ul>
  );
}

When reverse flips, the element at position zero keeps the same key if you used the index, so React preserves the mounted input and simply rewrites its props. The typed text stays in the first slot while the label changes underneath it. With a stable key the identity follows the data, React moves the correct node, and the content stays attached to the row it belongs to. The rule generalizes: a key must identify the item, never its position in the current rendering.

What a fiber node actually is

The fiber is the internal object React creates for each element in the tree during render. It holds the component function, the props and state it received, a link to its parent, links to its first child and its next sibling, and a tag saying what kind of thing it is. Because each fiber points to its next sibling, React can pause work on one part of the tree, return to it later, or abandon it entirely without recursing through the whole structure on the stack.

Each fiber carries flags marking work that still needs to be performed: placement for a newly inserted node, update for changed props, and deletion for a node that must be removed. During render React walks the tree and sets these flags. During commit it walks a separate list of the fibers with pending work and applies the mutations. The separation is what allows the DOM writes to happen in one pass with layout effects interleaved correctly.

Lanes: the priority system underneath

Rather than a single update queue, React models priority as sets of bits called lanes. Typing in an input produces a continuous input lane with the highest urgency, a click produces a discrete lane that should never be interrupted, and a transition such as filtering a large list is marked as low priority so it can be deferred. When two updates arrive for the same component, React merges their lanes, and the resulting priority is the most urgent one present.

SituationLane React picksWhat the user perceives
Keystroke in a controlled inputDiscrete, highest priorityThe character appears in the same frame
Click that changes a booleanDiscreteImmediate visual response
Filtering a list of ten thousand rowsTransition, deferrableOld list stays visible, then swaps
Placeholder content while a query loadsDefaultSkeleton renders without blocking input
Effect cleanup and re-subscriptionPassive, next frameNo visible cost

Interruptible work in practice

Transitions are the public face of lanes. Wrapping a state update in startTransition tells React that the update can be interrupted, so the input keeps responding while the expensive list is still being built. useDeferredValue solves the mirror-image case, where the expensive child is a separate component: it hands you a stale copy of a prop that updates only when the main thread is free.

import { useState, startTransition, useDeferredValue, useMemo } from 'react';

function FilterableTable({ rows }) {
  const [query, setQuery] = useState('');
  const deferredQuery = useDeferredValue(query);
  const isStale = query !== deferredQuery;

  const visible = useMemo(() => {
    const q = deferredQuery.trim().toLowerCase();
    if (!q) return rows;
    return rows.filter((r) => r.name.toLowerCase().includes(q));
  }, [rows, deferredQuery]);

  function handleChange(e) {
    const value = e.target.value;
    startTransition(() => setQuery(value));
  }

  return (
    <div>
      <input value={query} onChange={handleChange} aria-label="Search rows" />
      <div style={{ opacity: isStale ? 0.6 : 1 }} aria-busy={isStale}>
        <Table rows={visible} />
      </div>
    </div>
  );
}

The opacity hint is not cosmetic. It tells the person typing that the results they are looking at belong to an earlier keystroke, which is more honest than a spinner that flashes for eighty milliseconds. A transition that resolves quickly never shows the stale state, and a transition that is slow shows it clearly instead of pretending the work already happened.

What these rules explain in daily debugging

Once you can name the phase and the lane, familiar bugs become diagnosable. A component that logs twice in development is either Strict Mode double-invoking render to surface impure logic, or an effect without a correct cleanup that resubscribes on every commit. A list that loses focus after typing is almost always an unstable key or a component that unmounts and remounts because its type changed. An input that lags behind the cursor is a synchronous expensive update that should have been wrapped in a transition. A layout effect that reports zero height is running before the browser has painted, which is the normal order rather than a bug.

Profiling confirms it. The React DevTools profiler shows which components re-rendered and why a commit happened, and the browser performance panel shows whether the main thread was blocked by script, style recalculation or layout. Reading them together answers the two questions that matter: what work ran, and whether it could have waited.

Common Mistakes

Using the array index as a key on a list that can be reordered or filtered

Fix: Key by a stable identifier from the data so React moves the right node instead of rewriting the wrong one.

Running side effects during render because the value is needed immediately

Fix: Keep render pure and move subscriptions, timers and fetches into effects that can be cleaned up.

Wrapping every update in startTransition because it sounds faster

Fix: Reserve transitions for expensive, replaceable work; discrete input and click updates should stay urgent.

Optimizing with memo before measuring which component actually costs time

Fix: Record a profile first, fix the hot path the numbers name, then re-measure.

Key Takeaways

  • Render builds a throwaway description and can be discarded; commit is where the DOM actually changes and effects run
  • Reconciliation matches by type and by key, so a key must identify the data rather than the position in the array
  • A fiber is a linked object holding props, state, child and sibling pointers plus flags describing the work still owed
  • Lanes model priority: keystrokes are urgent, transitions are deferrable, and merging lanes yields the most urgent priority
  • startTransition and useDeferredValue are the two public doors into that priority system, and both exist to keep input responsive
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert React Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement