Reconciliation, Identity, and State Preservation
React compares a new render description with the previous committed React tree and decides what identities can be preserved, replaced, or removed.
Conceptual model: the stable application-facing rules matter more than private reconciler fields or exact heuristics.
Reconciliation is not DOM diffingβ
A component can render without causing a DOM mutation, and state preservation depends on React identity rather than DOM resemblance.
Identity controls state preservationβ
When the identity is preserved, React can preserve state for that subtree. When identity changes, state below that point is recreated.
Same type + same position can preserve stateβ
function Panel({ compact }) {
return compact
? <Card density="compact" />
: <Card density="comfortable" />;
}
Different type resets the subtreeβ
function App({ editing }) {
return <main>{editing ? <Editor /> : <Profile />}</main>;
}
Position matters among siblingsβ
Without stable keys, reordering sibling components can make identity follow position rather than domain meaning.
If those siblings represent durable domain entities, give React stable keys that represent those entities.
Keys are explicit sibling identityβ
{messages.map(message => (
<Message key={message.id} message={message} />
))}
Keys only need to be unique among siblings, not globally across the application.
Keys can intentionally reset stateβ
<Chat key={recipient.id} recipient={recipient} />
Key placement is architectural: a key too high resets too much; a key too low can preserve state that belongs to the previous domain identity.
Nested component definitions create unstable typesβ
function Dashboard() {
function SearchBox() {
const [query, setQuery] = useState('');
return <input value={query} onChange={e => setQuery(e.target.value)} />;
}
return <SearchBox />;
}
Each Dashboard render creates a new SearchBox function identity. Prefer stable module-level component definitions.
Render attempts and commits are differentβ
This is why render must be pure and why render logs are not proof that a result committed.
Identity debugging checklistβ
Senior mental modelβ
Reason from the stable behavior React documents. Treat internal implementation details as a way to understand Reactβnot as application dependencies.