Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 26.1 — React Internals: Fiber, Lanes and the Scheduler
React · Example 3 of 4

Render, then the commit sub-phases, in order

Render goes parent → child. The commit then runs effects child → parent (children complete first). On the update, the inline ref callback is a new function, so React detaches the old one with null and attaches the new one. Layout cleanups run in the mutation step; passive cleanups run just before the new passive effects.

Inside React every component instance is a fiber, a plain object linked into a tree; a work loop renders fibers one unit at a time, lanes decide which updates go first, and a finished tree is swapped in during a commit that cannot be interrupted.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a function countFibers(fiber) that walks a fiber subtree using only child, sibling and return (no recursion) and returns how many fibers it has.

02

Predict the console order for a component A with a useLayoutEffect and a useEffect, rendering a child B with the same two effects, on first mount.

Explain it without notes

01

What is a fiber and what does it store?

02

Walk through the render phase and the commit phase. Which one can be interrupted, and why does that matter for your code?

03

What is double buffering in React?

04

What are lanes, and how does React decide which update renders first?

05

How does the scheduler keep the page responsive during a big render?

Render, then the commit sub-phases, in order

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

render Parent 0
render Child 0
insertion effect Child
ref attached
layout effect Child
layout effect Parent
passive effect Child
passive effect Parent
--- click ---
render Parent 1
render Child 1
ref detached (null)
insertion effect Child
layout cleanup Child
ref attached
layout effect Child
layout effect Parent
passive cleanup Child
passive effect Child
passive effect Parent