Skip to content

Outline rows read their node from the store by id; callback props replace dispatched events - #4415

Merged
mstomar125 merged 4 commits into
mainfrom
outline-rows-by-id
Dec 2, 2026
Merged

mstomar125 merged 4 commits into
mainfrom
outline-rows-by-id

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

NodeSpace task: "Outline rows read their node from the store by id, with callback props instead of dispatched events" (7ec78f96-1bb1-421a-b9bc-cbe0c486449f). Builds on #4414 (no wrapper content writes, no viewer fallbacks, effect cap 6, unchanged).

One PR, three reviewable commits (the callbacks and the store-by-id change touch the same files, so splitting would mean editing every wrapper twice):

  1. Remove stored node depth; depth comes from the structure tree
  2. Replace node event dispatchers with typed callback props
  3. Outline rows read their node from the store by id (+ the row-read test)

Per criterion

  1. Per-row derived value holds ids and depth only. The viewer's visibleRows is { id, depth }[]; there is no row object copying node data (ViewerRenderNode is deleted). The list is returned as the same array when no id or depth changed, so a content edit leaves the rows' props alone.
  2. Row and every node wrapper read the node by id. NodeRow takes an id; RowNode (row-node.svelte.ts) is a set of $derived reads of the store by id (node, content, type, child rows, metadata). Text, header, task, issue, checkbox, code-block, quote-block, ordered-list, date, person, query, table and horizontal-line wrappers take nodeId, autoFocus and callbacks only. NodeComponentProps (the extension-facing props) is now the same.
  3. Editing one node does not re-evaluate another row's derived node. outline-row-reads.test.ts (Chromium) counts calls to readRowNode, which is the row's derived node read (one per evaluation, tagged by id): after an edit (and after successive keystrokes) the edited row's count is >0 and the other rows' is 0. Mutation-checked: reading the whole map in readRowNode, and reading sibling rows in RowNode.node, each fail both tests.
  4. No dispatcher on the path from the base node to the viewer. createEventDispatcher is gone from BaseNode and all 13 wrappers; they use NodeCallbackProps (typed, in node-row-types.ts), and NodeRow binds the viewer's handlers. Dispatches nothing listened to are dropped (focus, blur, nodeReferenceSelected, an iconClick pass-through, a keydown binding BaseNode never fired). The quote-block and ordered-list wrappers sent nodeTypeChanged with { nodeId, newNodeType, cleanedContent } on Enter; the viewer reads detail.nodeType, so it never changed anything, and it is dropped rather than retyped. base-node-reference.svelte still uses a dispatcher but is an inline reference component, not on this path.
  5. Stored depth deleted; depth comes from the structure tree. NodeUIState.depth, computeDepth (3 copies), updateDescendantDepths, the optimistic depth writes in indent/outdent/promote-children and the matching rollbacks are gone, plus originalUIState capture/restore in those rollbacks (nothing writes UI state there any more). ReactiveStructureTree.getDepth answers depth; promoteChildren uses it. visibleNodes()/getVisibleNodesForParent had no production caller (the viewer flattens the tree itself) and are deleted with their tests; split-pane-isolation.test.ts only tested that method and is deleted.
  6. Same node in two panes. outline-viewer-rows.test.ts mounts two viewers (panes pane-left, pane-right) over one store: both show the node, an edit in one appears in the other, and the other pane stays a view (no editor).
  7. Tests. test:changed passes (Happy-DOM 5810, scripts, Chromium 261); svelte-check, eslint, design tokens, effect allowlist (cap unchanged, no effect added) clean.

Unsaved placeholder decision

The blank row of an empty page is not in the store until the first keystroke (two panes on the same empty node must not share one id, so it stays viewer-local rather than being written to the store). A row for it reads as an empty text node: readRowNode(id) returns the stored node, else blankRowNode(id), in row-node-read.ts. That function is the only definition of what a placeholder is; the viewer calls it too to build the node it stores on promotion, so the row and the promoted node cannot drift. The viewer keeps only the placeholder's id (placeholderId). Store-held placeholders (createUnsavedPlaceholder) are in the store and read normally. A code comment in row-node-read.ts states this.

Behaviour check

outline-viewer-rows.test.ts drives the real viewer in Chromium: typing, Enter split, Backspace merge and delete, ArrowDown, Tab/Shift+Tab, collapse, - [ ] type conversion, empty-page placeholder promotion, two panes. It was written against current main first and passes there unchanged, then after each commit. Mutation-checked by removing NodeRow's onCreateNewNode, onNavigateArrow, onIndentNode, onDeleteNode and onCombineWithPrevious bindings (each fails its test) and by changing the blank node's content.

What is left / notes

  • The viewer's row-list derivation still walks the children and reads each child's nodeType (to hide types owned by the parent's viewer), so it re-runs, in O(rows), on a content edit; it returns the same array so nothing downstream changes. Removing that read needs a per-node type source in the store (a design decision), so it is not done here.
  • Observed, not changed: MergeNodesCommand decides merge vs delete from the textarea's textContent (always empty for a real textarea), so Backspace at the start of a non-empty row goes through onDeleteNode, not onCombineWithPrevious. The browser test sets textContent to reach the merge branch.
  • Tests that passed content/nodeType props to wrappers now seed the store (seedStoredNode, changeStoredNode in test helpers); the test-extension fixture node reads via nodes.getNode.
  • pin-guard allowlist: row-node-read.ts replaces the person-node/checkbox-node entries (they no longer call getNode).

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE at 99ff026

Independent review of all 4 commits (de8a3de, 4a49072, f598dc6, 99ff026) and the whole. No blocking issue.

What I ran (in a detached worktree at the head sha, removed afterwards): bun run test:scripts 1729 pass (effect allowlist cap unchanged, the diff adds no $effect); svelte-check 0 errors / 0 warnings; full Happy-DOM vitest 347 files / 5810 tests pass; full Chromium suite 21 files / 261 tests pass. Mutation checks, each reverted with git checkout:

  • readRowNode also reads the edited row's siblings: both outline-row-reads tests fail (2 and 6 extra reads).
  • RowNode.node wrapped in untrack: the two-pane test, the - [ ] conversion test and both read-count tests fail.
  • visibleRows identity guard forced to "always changed": both read-count tests fail, so the same-array return is covered.
  • flatten(id, depth + 1, ...) changed to depth: the Tab/Shift+Tab margin test fails.

Dropped dispatches, checked against the base (cb11b0e)

  • focus, blur, nodeReferenceSelected: NodeRow bound none of them and no other component mounts a node wrapper, so there was no listener.
  • iconClick: NodeRow forwarded it to an optional onIconClick, and the base viewer never passed one. Task and checkbox consume it in their own wrapper, as before.
  • code-block on:keydown: BaseNode's dispatcher type list has no keydown, so isTyping and the .typing class were dead.
  • quote-block / ordered-list nodeTypeChanged { nodeId, newNodeType, cleanedContent } on Enter: the viewer reads detail.nodeType, which was undefined. Dropping it is not a regression and probably removes a latent bug (with default structural rules typeChangeAllowed(undefined) passes, so the base path then called updateNodeType(id, undefined); I did not run that path on base).
  • taskStateChanged.content was never read by the viewer. data-has-children has no CSS or test reader.

Depth. promoteChildren is the only production caller of getDepth. For a consistent tree it gives the same numbers the stored depth did (both are absolute from the root); cycles are guarded, and orphans return 0. It has no cache to invalidate. It is O(depth x siblings) because getParent scans siblings, but it runs only on Backspace-merge child promotion, not per render. Row indentation does not use it: visibleRows carries the traversal depth, so indent/outdent/delete cannot leave it stale.

Backspace oddity. MergeNodesCommand is untouched by this PR (no diff under lib/commands); the textContent branch is pre-existing. Not made worse: handleDeleteNode and handleCombineWithPrevious both end in combineNodes, and the merge-point position is still read before the merge.

Extension contract (plain answer). NodeComponentProps is exported from @nodespace/extension-api. It is a breaking change for extension-supplied node components: they no longer receive content / nodeType / children / metadata props, and anything they emit with createEventDispatcher is no longer heard (callback props instead). It fails silently (empty content, edits go nowhere). Only consumer found: the in-repo test-extension fixture, which the PR updates to nodes.getNode(nodeId). The sync repo has no node components. docs/architecture/extension-points.md only names the type, not its shape. With no users and the ADR rule of no compat shims, this is acceptable.

Blocking

None.

Should-fix (non-blocking)

  1. row-node.svelte.ts:27 (children = $derived(outlineChildIds(getId())), built on row-node-read.ts:51). outlineChildIds reads every child's node, so a parent row re-runs this derived on any child edit and gets a new array each time. By reading, not measured. Scenario: type in a child, and its parent's children prop to BaseNode changes on every keystroke. The read-count test uses three flat siblings, so it cannot see this. Add a nested case to the test, or say in the comment that the "no other row" claim holds for non-ancestors only. Two RowNode instances per row (NodeRow and the wrapper) also do this work twice.
  2. Extension break is undocumented. A line in nodespace-docs extension-points.md saying node components get nodeId, autoFocus and callbacks, and read the rest through nodes.getNode, would save the first plugin author an afternoon.

Nit

  • tests/unit/props-driven-components.test.ts:204 still asserts a "NodeComponentProps" object with content / nodeType / children; it is an untyped literal and now tests nothing.
  • Not covered by the Chromium rows test: Enter on a quote-block / ordered-list whose prefix was removed (the dropped nodeTypeChanged path), slash-command and heading-marker conversion on the empty-page placeholder, and two panes on the same empty node (the PR text discusses it, no test). I read the placeholder path (placeholderId, isPromoting, resetPlaceholderId) and it matches the base ordering, including the one-tick row removal while isPromoting is true.
  • Behaviour that is the same as base, so not a finding: expanded defaults, autoFocus only for the unsaved placeholder row, {#key id-nodeType} remount on type change.

🤖 Generated with Claude Code

mstomar125 and others added 4 commits December 2, 2026 11:48
NodeUIState no longer carries depth and ReactiveNodeService no longer
maintains it by hand: the depth walk in initializeNodes/setExpanded/
peekUIState, the optimistic depth writes in indent, outdent and child
promotion, updateDescendantDepths, and the depth rollback in the indent/
outdent/promotion rollbacks are deleted. ReactiveStructureTree.getDepth
answers depth from the parent chain, and promoteChildren uses it.

visibleNodes()/getVisibleNodesForParent had no production caller (the
viewer flattens the tree itself) and are deleted with their tests; the
split-pane isolation test only exercised that method.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
BaseNode and the node wrappers (text, header, task, issue, checkbox, code
block, quote block, ordered list, date, person, query, table, horizontal
line) report through NodeCallbackProps instead of createEventDispatcher,
and NodeRow binds the viewer's handlers to those props. Wrappers that only
forward spread the callbacks to BaseNode; the ones that transform an event
(header, task, query, checkbox, code block, quote block, ordered list,
date) override the one callback they change.

Dispatches nothing listened to are dropped: focus, blur,
nodeReferenceSelected, the iconClick pass-through, a keydown binding BaseNode
never fired, and the malformed nodeTypeChanged detail the quote-block and
ordered-list wrappers sent on Enter (it carried newNodeType, which the
viewer's handler does not read, so it changed nothing). The unused
NodeViewerEventDetails type is deleted.

outline-viewer-rows.test.ts mounts BaseNodeViewer in Chromium over a seeded
store and drives typing, the Enter split, Backspace merge and delete, arrow
navigation, indent/outdent, collapse, type conversion, the empty-page
placeholder and the same node in two panes. It passes unchanged on the
dispatcher-based code.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The viewer derives only an id and a depth per visible row; no row object is
a copy of node data. NodeRow takes a row id and reads the node through
RowNode, a set of $derived reads of the store by id (node, content, type,
child rows, metadata), and every node wrapper does the same instead of
receiving content, nodeType, children and metadata as props. The viewer's
handlers take the row id and read the node from the store when they need
it, and the row list returns the previous array when no id or depth changed.

An unsaved placeholder row (the blank row of an empty page, not in the store
until the first keystroke) reads as the empty text node built by
blankRowNode in row-node-read.ts. The same function builds the node the
viewer stores when it promotes the placeholder, so that is the only place
that says what a placeholder is. The viewer keeps only the placeholder's id.

NodeComponentProps is now nodeId, autoFocus and the callback props. The
data-has-children attribute on the row container, which nothing read, is
removed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
outline-row-reads.test.ts mounts BaseNodeViewer in Chromium over three rows
and counts the reads of a row's derived node (readRowNode, one call per
evaluation, tagged by id). Editing one node re-reads that row and none of
the others, for a single edit and for successive keystrokes.

The empty-page test also asserts that an unsaved placeholder row reads as an
empty text node.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 merged commit 186493e into main Dec 2, 2026
@mstomar125
mstomar125 deleted the outline-rows-by-id branch December 2, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant