docs/solutions/best-practices/2026-05-09-lexical-docs-traversal-harvest-rows-need-query-shape-contracts.md
Lexical's docs traversal tests are useful, but the useful part is not the caret helper API. The portable part is the document shape: sibling order, descendant order, and how a partial range maps to included leaves or elements.
$iterSiblings, $iterCaretsDepthFirst, and
$iterNodesDepthFirst together.Editor.before,
Editor.after, and Editor.positions, but that does not automatically prove
node traversal shape.Node.children, Node.descendants, and state.nodes.match(...) behavior.Map the Lexical traversal doc shape onto Slate's public query APIs:
Node.children(editor, path);Node.children(editor, path, { reverse: true });Node.descendants(editor);state.nodes.match({ at: range, mode: 'lowest' });state.nodes.match({ at: range, match: isElement, mode: 'lowest' }).The compact proof landed in
.tmp/slate-v2/packages/slate/test/query-contract.ts and uses the same nested
paragraph/link document shape as the Lexical docs test.
Slate callers observe traversal through paths and node entries. Proving those paths through the public query APIs covers the portable behavior while avoiding Lexical's caret implementation model.
The mode: 'lowest' split is important: leaf traversal and element traversal
answer different questions. Keeping both assertions prevents a future query
change from preserving point movement while breaking caller-visible node
selection.
mode: 'lowest' output explicitly.