Reconciliation is React's diffing algorithm that compares the new virtual DOM tree with the previous one to determine minimal DOM updates. It uses heuristics: different element types trigger full subtree replacement, keys identify items in lists, and same-type elements update attributes.
What is Reconciliation:
Key Heuristics:
Different element types:
Same element type:
Keys for lists:
Fiber Architecture:
// BEFORE
<div>
<Counter />
</div>
// AFTER: Different root element type
<span>
<Counter />
</span>
// React will:
// 1. Unmount old <div> and <Counter>
// 2. Counter's componentWillUnmount / useEffect cleanup runs
// 3. Mount new <span> and fresh <Counter>
// 4. All Counter state is LOST!
// Same element type - just updates attributes
<div className="before" title="old" />
<div className="after" title="new" />
// React updates className and title on same DOM node
// Same component type - instance is kept
<Counter count={1} />
<Counter count={2} />
// Same Counter instance, state preserved, just re-renders