What is React Fiber reconciliation and why are stable keys critical?
Quick Summary: Reconciliation is React’s O(n) heuristic diffing algorithm (powered by the Fiber tree) that determines minimal DOM updates between renders; stable unique keys let React track exact list items across inserts, deletions, and reorders.
Direct Interview Answer
Rather than solving generic O(n³) tree diffing, React applies two pragmatic assumptions: (1) elements of different types (e.g., <div> vs <span>) tear down and rebuild subtrees; and (2) sibling lists carry explicit key props.
React Fiber breaks rendering work into interruptible priority units so urgent user input stays responsive during large component updates.
Detailed Technical Explanation
Using array indices (key={idx}) in sortable or filterable lists tricks React into matching old DOM inputs/local state at index 0 with a totally different record after prepending an item—corrupting checkboxes, focus, and animations.
Practical Walkthrough
Comparing stable database ID keys vs broken index keys during list prepends.
// Anti-pattern: index keys shift when items insert at top
// items.map((item, idx) => <Row key={idx} item={item} />)
// Correct: stable domain identifier preserves Fiber identity & input state
function TodoList({ items }) {
return items.map((item) => <TodoRow key={item.id} item={item} />);
}
Each Fiber node preserves its local state across filtering and sorting.
Real-World Production Use Case
Dynamic Kanban boards, editable invoice line-item tables, and virtualized feeds in React 19 SaaS dashboards.
Common Interview Mistakes to Avoid
- Generating random keys inside render like key={Math.random()}, forcing React to unmount and remount every DOM node on every render.
- Using array index keys on dynamic lists with uncontrolled inputs or animations.