LearnNewsExamplesServices
Frontmatter
id19190
titlemoveNode into an inserted subtree uses the logical child index
stateClosed
labels
bugaicore
assigneesneo-opus-ada
createdAtSep 24, 2026, 8:19 PM
updatedAtSep 24, 2026, 8:59 PM
githubUrlhttps://github.com/neomjs/neo/issues/19190
authorneo-opus-ada
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtSep 24, 2026, 8:59 PM

moveNode into an inserted subtree uses the logical child index

neo-opus-ada
neo-opus-ada commented on Sep 24, 2026, 8:19 PM

Context

I found this while fixing #19187 and promoted it from defect-note 2f45fa099d0c29d5 on a triage decision: I own the adjacent lane, and the fix is a single index translation. In the Workstation film, the tear-out vessel's Metrics tab reads "⠿Metrics", with the stack handle before the text, while its vdom orders [text, handle]. The freshly rendered Commits tab reads "Commits⠿", which is correct.

The Problem

  • Captured in the film. This was at the vessel's DeltaUpdates#update, #19182 head e7f95d9043. The text span was first inserted as <!-- neo-vtext-2 -->Metrics<!-- /neo-vtext -->, followed by {action: 'moveNode', id: 'neo-dock-stack-handle-metrics', index: 1, parentId: <that span>}. DOM index 1 is the text node inside the vtext's comment wrapper, so the handle lands inside the wrapper.
  • Reproduced with pure VdomHelper.
    • The old tree holds the handle in another span. The new tree inserts span#new-label with [vtext, handle].
    • The deltas are insertNode new-label (markup without the handle) and then moveNode handle {index: 1, parentId: 'new-label'}.
    • The physical index is 3.
  • Beyond the order. DeltaUpdates#updateVtext writes startComment.nextSibling.nodeValue. With the handle trapped behind the opening comment, that sibling is the handle element, and setting nodeValue on an element does nothing. Later text updates for that label are therefore silently dropped.

The Architectural Reality

  • Helper#insertNode builds the inserted subtree's markup or pruned vnode without the moved nodes. It then pushes one moveNode per moved node with index: details.index, which is the logical index within the new parent.
  • Helper#moveNode, the standalone path, translates the logical index with getPhysicalIndex(parentNode, index). A text child counts as three DOM nodes, and a fragment counts as its anchors plus its children.
  • DeltaUpdates#moveNode inserts before parentNode.childNodes[index], which is a DOM index.

The Fix

  • Translate the index. In Helper#insertNode's moved-node loop, emit index: me.getPhysicalIndex(details.parentNode, details.index). Moves apply in order, so sibling moved nodes see the DOM that the earlier moves built.
  • Red-first test. Add a unit case to Helper.spec.mjs: a node moved into a freshly inserted subtree after a text child gets index 3.

Acceptance Criteria

  • AC-1 A unit case moves a node into a freshly inserted subtree after a text child and expects physical index 3. The case fails on dev.
  • AC-2 The film's tear-out vessel labels its Metrics tab "Metrics⠿", with the handle after the text and outside the text's wrapper. Evidence is a headless film probe receipt.
  • AC-3 The vdom unit directory and the full unit suite are green.

Out of Scope

  • The removeAll that erased the label after the compose: #19187, PR #19189.
  • Which tab carries the stack handle.

Related

#19187 · #19189 · #19182 · #15252

Sweeps (at filing):

  • Live latest-open: latest 20 open issues, none equivalent.
  • A2A: the 30 latest messages hold no claim on this scope.
  • MC: no prior decision on moved-node indices inside inserted subtrees.
  • Own assignments: #19186–#19188 are adjacent, not equivalent.
  • Structure map: not applicable, since this is not ai/.

Origin Session ID: 101d2ce9-9f43-4f5a-9ae2-3c75bf8f6fcf Retrieval Hint: "vdom moveNode logical index inserted subtree vtext comment wrapper stack handle"

tobiu referenced in commit e92451b - "fix(vdom): a node moved into an inserted subtree lands at its DOM index (#19190) (#19191) on Sep 24, 2026, 8:59 PM
tobiu closed this issue on Sep 24, 2026, 8:59 PM