LearnNewsExamplesServices
Frontmatter
id19916
titleA throwing afterSetMounted makes the next update re-insert its siblings
stateClosed
labels
bugaicore
assigneesneo-opus-grace
createdAtOct 20, 2026, 3:30 PM
updatedAtOct 20, 2026, 7:57 PM
githubUrlhttps://github.com/neomjs/neo/issues/19916
authorneo-opus-grace
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtOct 20, 2026, 7:57 PM

A throwing afterSetMounted makes the next update re-insert its siblings

neo-opus-grace
neo-opus-grace commented on Oct 20, 2026, 3:30 PM

Context

Found while fixing realworld2 on 2026-10-20 (#19891, #19892). Its home view rendered twice, with 23 duplicate element ids and one uncaught TypeError reading subscribe. The trigger was app-level: PreviewList, a list.Base, calls Neo.main.addon.Navigator.subscribe() in afterSetMounted (src/list/Base.mjs:343), and realworld2's addon list had dropped Navigator. #19892 restored the addon. The engine defect it exposed is still on dev: one component whose afterSetMounted throws corrupts the vdom state of its parent's subtree.

Observed: the doubled view, the 23 duplicate ids and the TypeError (realworld2 before #19892). Inferred from source, below: the mechanism. AC-1 and AC-2's red arms are its isolated reproduction.

The Problem

VdomLifecycle#syncVnodeTree hands an adopted vnode to every child component in one loop (src/mixin/VdomLifecycle.mjs:1196-1211). Setting component.mounted = true runs the child's afterSetMounted inside that loop. When it throws:

  • the loop stops, so every later sibling keeps its previous vnode or none, and stays unmounted;
  • the unmount pass (:1219-1223) and the receiver's own _vnode and afterVnodeSync (:1226-1228) never run;
  • the error leaves syncVnodeTree and reaches executeVdomUpdate's catch (:502), which treats it as a failed flight. It skips the remaining roots and rejects every root's callbacks, although the main thread has already applied the deltas.

The parent's next update then diffs against a vnode tree without the nodes the DOM already holds, and inserts them again.

The Architectural Reality

  • syncVnodeTree (:1155) runs for each adopted root from executeVdomUpdate (:476), and from afterSetVnode (:134).
  • mounted is a reactive config. Components wire main-thread addons and DOM listeners in afterSetMounted (src/list/Base.mjs:330-346), so subclass and app code runs inside the loop.
  • The same file already isolates callbacks that may throw, each with a try/catch and console.error: initVnode callback rejection failed (:849), initVnode deferred update failed (:856), vdom callback rejection failed (:1107).
  • Design authority: the catch's own comment, "Rejection releases every root without acknowledging a vnode it did not receive." A hook that throws after the vnode arrived and its deltas were applied is not that case.

The Fix

In syncVnodeTree's second pass, wrap each child's mount (component.mounted = true and component.afterVnodeSync(deltas)) in a try/catch that logs console.error('syncVnodeTree: a mount hook failed', component.id, error) and continues. The sync then completes: later siblings get their vnodes, the unmount pass runs, the receiver adopts its vnode, and the flight resolves.

Acceptance Criteria

  • AC-1: A unit arm: a child whose afterSetMounted throws during its parent's update leaves its later siblings synced (vnode set, mounted: true) and the parent's vnode adopted. Red on dev.
  • AC-2: A browser e2e (vdom behavior changes need one, per #19499): the parent's update promise resolves, and its next update inserts no node twice, so the page has no duplicate ids. Red on dev.
  • AC-3: The thrown error still reaches the console and names the component.

Out of Scope

  • The render paths that mount the rendered component itself (:821, :1016); a throw there concerns only that component.
  • App code that throws in afterSetMounted; #19892 fixed realworld2's.

Avoided Traps

  • Re-throwing after the loop: executeVdomUpdate's catch would still reject a flight whose deltas are applied.
  • Catching around syncVnodeTree in executeVdomUpdate: the throwing child's later siblings would still stay unsynced.

Related

#19891 · #19892 (the realworld2 trigger) · #19478 (the sibling path: a mount callback that throws in initVnode must not strand later updates) · #19831 (a functional component destroyed mid-update; the same flight-settlement code)

Live latest-open sweep: latest 20 open issues at 2026-10-20T13:28Z, plus gh search issues --owner neomjs for "afterSetMounted" and "syncVnodeTree"; no equivalent (#19478 covers initVnode, not this loop) A2A claim sweep: last 30 messages, all read-states; no claim on this scope MC sweep: "component afterSetMounted throws, later siblings never mount, next update inserts the view twice, duplicate element ids", 6 results; only this morning's realworld2 diagnosis, no prior decision Own-assignment sweep: 15 open; #19898/#19899 touch worker/App and the theme counter, not this loop

Retrieval Hint: "afterSetMounted throws syncVnodeTree duplicate DOM ids realworld2" Origin Session ID: fe0fefcd-99fe-4eb2-b4c4-b8a4fbe2d92c

tobiu referenced in commit c50ca30 - "fix(vdom): a mount hook that throws leaves its siblings synced (#19916) (#19921) on Oct 20, 2026, 7:57 PM
tobiu closed this issue on Oct 20, 2026, 7:57 PM