Expand description
Algorithms to create git-like diffs between two doms in linear time 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§
- Diff
Result - The result of a DOM diff, containing lifecycle events and node mappings.
- Node
Move - Represents a mapping between a node in the old DOM and the new DOM.
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:
- 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 all nodes 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.
- transfer_
states - Executes state migration between the old DOM and the new DOM based on diff results.