Skip to main content

Module diff

Module diff 

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

  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§

DiffResult
The result of a DOM diff, containing lifecycle events and node mappings.
NodeMove
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.