Skip to content

fix(core): hide the subtree of a deleted node - #308

Draft
marcus-pousette wants to merge 1 commit into
mainfrom
fix/hide-deleted-subtrees
Draft

marcus-pousette wants to merge 1 commit into
mainfrom
fix/hide-deleted-subtrees

Conversation

@marcus-pousette

Copy link
Copy Markdown
Collaborator

A delete hid only the node itself, so its descendants could still be read by id, were counted by nodeCount() and stayed live in changedSince and events. In em, a deleted thought's unloaded descendants came back in superscripts and context views after a reload.

The cached tombstone flag now covers nodes under a tombstoned ancestor. A refresh carries a change into the subtree and reports a delete, or a restore with its payload, for each node it hides or shows. Descendants deleted on their own stay hidden, so re-inserting a deleted node, as em's undo does, brings back the rest of its subtree.

A full catch-up now also patches the unaffected descendants of a node whose visibility changed, and the node of every replayed op, since a late delete of a hidden node changes nothing visible. A local delete is reported from the tombstone change, so deleting an already hidden node reports nothing, as on peers.

The new conformance scenarios fail on main. Databases written before this keep their stale flags until they are reset.

A delete hid only the node itself, so its descendants could still be read
by id, were counted by nodeCount() and stayed live in changedSince and in
events. The cached tombstone flag now also covers nodes under a tombstoned
ancestor: a refresh carries a change into the subtree and reports a delete,
or a restore with its payload, for each node it hides or shows again.
Descendants deleted on their own stay hidden.

A full catch-up patches the unaffected descendants of a node whose
visibility changed, and the node of every replayed op, since a delete of a
hidden node changes nothing visible. A local delete is reported from that
change too, as a remote apply reports it.
marcus-pousette added a commit that referenced this pull request Nov 25, 2026
createTreecrdtView (@treecrdt/interface/views) orders groups of nodes
as subtrees of the document. A group is a key of a payload index,
passed in or opened from the view's options. Its members are read from
the index with each call, so membership always matches the payloads
and nothing derives or stores it, and each member's rank and data are
read from its payload alike.

A member lists at a default key (rank digits, then the member's id, or
with reference: 'parent' its parent's, then 0001) until someone places
it, and nothing is stored for it. place, createFolder and removeFolder
write only what a drop needs: the view root under the root and the
group's node, create-only, if missing; the item's reference, a plain
insert when it has none, else a move; and when an item goes under a
member without a reference, that member's reference, create-only 'at'
its default key, so devices that nest under it at once agree and a drag
of the member wins wherever it falls in the operation order. A group's
top level merges the group node's children, by order key, with the
members that have no reference, by default key, so a drop between two
members takes a key between theirs, and a drop at the last spot stays
below the default keys of later ranks. Below the top level the order is
TreeCRDT's: references and folders as ordinary siblings, walked depth
first. A reference whose member left the group shows its children in
its place, and applies again when the member returns.

The group node holds its key as its payload, so a change under it maps
back to the group: onChange reports the index's keys and the groups
whose subtree changed. View node ids hash the doc id, the view name and
their parts; folder ids are random, with a bit after VIEW_NODE_PREFIX
set.

Once anyone places something, the view root sits among the root's
children on every replica, so readers of the root's children, tree
walks and onMaterialized listeners must skip VIEW_NODE_PREFIX, and a
writer whose capability covers only a subtree cannot order a group.
Members under a deleted node stay members until the engine hides
deleted subtrees (#308). With a local authSession, reads and onChange
share the payload index's limit until #284.

This replaces the earlier views, which derived membership into a
treecrdt_view_members table with onMaterializedDurable, pinned every
member on the first drag (102 ops for a group of 100) and repaired
after writes.

At 10k nodes on sqlite-node: the first drag in a group of 100 writes 3
ops in 1.9 ms, a later drag takes 1.4 ms; reads of 1 key take 0.05 ms,
50 keys 1.8 ms and the 100 members 0.29 ms, or 0.06, 2.1 and 0.36 ms
once every group read is ordered; an edit until onChange reports both
groups 0.17 ms.

This branch has not been deployed

No deployments
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