Expand description
Linear-time DOM diffing for incremental updates. DOM Reconciliation Module
This module provides the reconciliation algorithm that compares two DOM trees and generates lifecycle events. It uses stable keys and content hashing to identify moves vs. mounts/unmounts.
The reconciliation strategy is:
- Stable Key Match: If
.with_key()is used, it’s an absolute match (O(1)). - CSS ID Match: If no key, use the CSS ID as key.
- Structural Key Match: nth-of-type-within-parent + parent’s key (recursive).
- Hash Match (Content Match): Check for identical
DomNodeHash. - Structural Hash Match: For text nodes, match by structural hash (ignoring content).
- Fallback: Anything not matched is a
Mount(new) orUnmount(old leftovers).
Structs§
- Change
Accumulator - Unified change report that merges information from all three change paths:
- Diff
Result - The result of a DOM diff, containing lifecycle events and node mappings.
- Extended
Diff Result - Extended diff result that includes per-node change information.
- Node
Change Report - Per-node change report combining multiple information sources.
- Node
Change Set - Bit flags describing what changed about a node between old and new DOM. Multiple flags can be set simultaneously. Uses manual bit manipulation instead of bitflags crate to avoid adding a dependency.
- Node
Data Fingerprint - Per-node hash broken into independent fields for fast change detection.
- Node
Move - Represents a mapping between a node in the old DOM and the new DOM.
- Text
Change - Text change info for cursor/selection reconciliation.
Functions§
- calculate_
contenteditable_ key - Calculate a stable key for a contenteditable node using the hierarchy:
- calculate_
reconciliation_ key - Calculate the reconciliation key for a node using the priority hierarchy:
- compute_
node_ changes - Compare two matched
NodeDatainstances field-by-field and return aNodeChangeSetdescribing what changed. - create_
migration_ map - Migrate state (focus, scroll, etc.) from old node IDs to new node IDs.
- get_
node_ text_ content - Get the text content from a NodeData if it’s a Text node.
- precompute_
reconciliation_ keys - Precompute reconciliation keys for every node in a DOM tree.
- reconcile_
cursor_ position - Reconcile cursor byte position when text content changes.
- reconcile_
dom - Calculates the difference between two DOM frames and generates lifecycle events.
- reconcile_
dom_ with_ changes - Perform a full reconciliation with change detection.
- transfer_
states - Executes state migration between the old DOM and the new DOM based on diff results.