Skip to main content

Module diff

Module diff 

Source
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:

  1. Stable Key Match: If .with_key() is used, it’s an absolute match (O(1)).
  2. CSS ID Match: If no key, use the CSS ID as key.
  3. Structural Key Match: nth-of-type-within-parent + parent’s key (recursive).
  4. Hash Match (Content Match): Check for identical DomNodeHash.
  5. Structural Hash Match: For text nodes, match by structural hash (ignoring content).
  6. Fallback: Anything not matched is a Mount (new) or Unmount (old leftovers).

Structs§

ChangeAccumulator
Unified change report that merges information from all three change paths:
DiffResult
The result of a DOM diff, containing lifecycle events and node mappings.
ExtendedDiffResult
Extended diff result that includes per-node change information.
NodeChangeReport
Per-node change report combining multiple information sources.
NodeChangeSet
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.
NodeDataFingerprint
Per-node hash broken into independent fields for fast change detection.
NodeMove
Represents a mapping between a node in the old DOM and the new DOM.
TextChange
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 NodeData instances field-by-field and return a NodeChangeSet describing 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.