Skip to content

fix(octane): retire a deletion's hosts before its cleanups run - #1627

Merged
trueadm merged 6 commits into
mainfrom
fix/retired-host-anchor
Oct 3, 2026
Merged

trueadm merged 6 commits into
mainfrom
fix/retired-host-anchor

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

#1548 and #1549 were two mechanisms for one defect (#1472): a focused host's removal, or a deletion cleanup that moves focus, dispatches focusout synchronously at hosts being torn down. This keeps only #1549's DOM-root stamp and applies it where a deletion is committed, before any of its cleanups run. The stamp therefore covers child components the teardown has not reached yet.

That fixes E1 from the 2026-10-02 review. Deletion cleanups run parent first, so under #1548's per-Block epoch:

  • a dialog that restores focus in its own layout cleanup still ran onBlur on an input owned by a child <Field>;
  • a value-hole input in a removed @for row did the same when an earlier component in the row moved focus.

Removed (#1548): Block.retired, the $$eventOwner write on every handler publication and its prototype seed, the four inline stamps, the dispatch owner check, and DeferredLayoutDriver.retireHosts.

Stamp sites. Root transactions defer deletions into several commit forms. Some detachDom=false teardowns retain their DOM (hydration retries, adoption), so stamping by Block markers at the outermost teardown is not safe. Each committed removal stamps its own saved nodes instead:

  • the deferRootRange commit stamps its nodes;
  • unmountParkedItem stamps the row, only when the scheduler captured focus for this pass (or when called outside a flush). An unfocused bulk removal does no per-row work.
  • root.unmount stamps the container's content;
  • teardownPortalState stamps a portal's own range: its DOM sits outside every enclosing range, and a returned portal's logical parent is the live host. A portal compiled into a template routes its events through a host element inside its owner, which the enclosing deletion has already stamped. (Stamping every portal Block in unmountBlockInner instead also stamped an independent portal parked inside a Fragment owner's markers.)
  • the inert owned-list clear makes one climb from the captured focus to the list parent's child, instead of N per-row stamps;
  • the non-parkable (immediate) list clear stamps the whole span between its markers before any row's cleanup, under the same captured-focus rule as parked rows.

The deferRootUnmount commit is deliberately unstamped: its nodes already left the document (with any focus) during render, or the caller clears them at render time.

Kept (#1549): the $$retiredEpoch stamp, the per-task window, the outermost-stamp path scan, the tag-swap stamp and the ViewTransition staging. stampRetiredHostTree is merged into retireEventHostTree.

Removed (#1549): the blockless de-opt hook in detachDeoptTreeRefs (and its detachDeoptSubtreeRefs split). Every transactional blockless removal commits through deferRootRange, which now stamps its nodes before their cleanup. The removal also keeps root-chained-jsx within the 84,352-byte raw budget main set in #1637.

Also: docs/differences-from-react.md now mentions deletion cleanups that move focus, and a changeset is added.

Size

Measured locally against main 0d91b93, which is two hydration commits behind the current base; the gated budgets were re-checked on the current base.

Full applications, framework chunk (bundle-size/run.mjs, octane targets):

app raw gzip brotli
js-framework rows −74 +13 +48
js-framework jsx −77 −32 +62
todomvc −74 −1 +56
chat-stream −74 −14 +20
weather-app −74 0 −61

Minimal scenarios (run-minimal.mjs):

scenario raw gzip brotli
hooks-state / prop-attributes / context −91 −41 / −32 / −8 −96 / −54 / +11
component-owned-effects −91 −47 −46
binding-radix (vite / esbuild) −77 −33 / −41 −47 / +12
root-static −79 −6 +120
root-static-specialized / root-static-local +30 −2 / 0 −48 / −4
root-chained-jsx +30 +10 +3
hydrate-root +30 +21 +27
cli-spa-starter +46 +43 +70

The review estimated −80…−150 gzip per app. In practice the per-commit-site stamps cost about what #1548's claim did, so the result is about −75 raw and roughly flat gzip/brotli (within ±60). Handler-free bundles never paid for the removed claim, so they grow slightly.

CI-gated budgets (--budgets root-static-local root-chained-jsx hooks-state prop-attributes context) pass on the current base. root-chained-jsx is 84,347 / 27,875 / 24,838 against 84,352 / 27,904 / 24,864 at 29ba34b, with main at #1637. Main alone measures 84,344 raw there.

Timing (for CI to confirm, not measured locally):

The ViewTransition effect-cleanup call gate should be unchanged. An instrumented local count showed 0 extra calls for an unfocused 100-row removal and an unfocused 1,000-row clear of effectful rows, and 1 call per removed row when something is focused.

Validation

  • pnpm format:check (scoped pnpm format:files:check on changed files: clean)
  • pnpm typecheck (scoped pnpm typecheck:files on changed files: clean)
  • pnpm test (not run locally per machine-load rules; CI covers it)
  • targeted tests, octane and octane-prod:
    • retired-event-hosts, discrete-flush-reentrancy, portal-events, view-transition-*, focus-*, for-batch-clear, keyed-removal-lifetime, deopt-*, portal-*, unmount-detach: 37 files / 435 tests in each project;
    • hydration-retry suites (dev): 22 files / 1,496 tests.
  • New regressions in tests/retired-event-hosts.test.ts. The first three fail on main in dev and prod:
    • a child component's input when the deleted dialog restores focus (main: ['field', 'parent']);
    • a value-hole input in a removed row when an earlier sibling restores focus (main: ['row', 'parent']);
    • a portaled dialog's child, both a returned portal and a portal compiled in a template (main: ['field', 'parent']; fix(octane): skip retired hosts when removal dispatches focusout #1548 also missed this);
    • a focused live sibling of the removed range keeps its handlers in the same task. This one passes on main and fails if the stamp is made too broad.
  • New Chromium scenarios in tests/browser/retired-event-hosts cover the three E1 orderings plus a 20-row inert list clear with a focused row. They were not run in a browser locally. I validated all 34 browser scenarios under a jsdom harness that emulates Chromium's synchronous blur-on-removal, in dev and prod. Under that harness the three new E1 scenarios fail on main, and disabling any one stamp site fails at least one scenario.

Risk / follow-ups

  • A cleanup that moves focus into another range being removed is not covered, as with fix(octane): skip retired hosts when removal dispatches focusout #1548.
  • Parked keyed rows are stamped one at a time before each row's own teardown, so one row's cleanup that moves focus off a later removed row still runs that row's onBlur; fix(octane): skip retired hosts when removal dispatches focusout #1548 had the same per-row order. Stamping the whole batch first fixes it (a jsdom test confirms: ['row 2', 'parent'] today). It costs about +20 gzip / +27 brotli in root-chained-jsx, which is past that bundle's committed budget, so it is left for a separate decision. The non-parkable batchClearItems path already stamps its whole span first.
  • A ViewTransition-staged clear of a large inert list, or a drain spanning several focused documents, may not stamp the focused row. The handler of an inert row belongs to its live list owner, so this cannot raise ScopeDisposedError.
  • Raw headroom on root-chained-jsx is 5 bytes; main itself has 8.
  • Without the blockless hook, two render-time de-opt removals that bypass deferRootRange no longer stamp: a mapped item switching from a host to a component, and the fallback when a moved de-opt host has no receiving slot. The same applies to the non-transaction else branches, which createRoot trees do not reach. Restoring the hook costs about 27 raw bytes, past that budget. Equivalent spellings move brotli by ±60, so a concurrent PR can tip it. The in-flight A7 work (closeNativeEventBatch gating) measures −133 brotli there.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes teardown ordering and delegated focus/blur dispatch across lists, portals, and root unmount; behavior is heavily regression-tested but touches core commit paths.

Overview
Fixes #1472 by retiring removed DOM hosts for delegated events before any deletion cleanups run, so a parent layout cleanup that restores focus no longer runs onBlur on inputs owned by child components (or value-hole rows) that teardown has not reached yet.

The PR drops block-level retirement (Block.retired, $$eventOwner on handler publish, retireHosts) and relies on $$retiredEpoch stamps on detached node roots at each committed removal path (deferRootRange, focused parked rows, root unmount, portal ranges, list clears). Dispatch skips handlers under the outermost stamp in the capture path; live siblings and ancestors still fire.

Docs note deletion cleanups that move focus; new jsdom and Chromium scenarios cover dialog/portal/@for focus-restore orderings and focused list clears.

Reviewed by Cursor Bugbot for commit 29ba34b. Bugbot is set up for automated code reviews on this repo. Configure here.

Deletion cleanups run parent first. A dialog that restored focus in its own
layout cleanup started onBlur on an input owned by a child component the
teardown had not reached yet, and the same happened for a value-hole input in
a removed @for row: #1548 retired each Block only when its own unmount began.

Replace #1548's per-host owner claim and per-Block epoch with #1549's DOM-root
stamp, applied before any cleanup at every committed deletion: the deferred
range removal, parked keyed rows, root.unmount, and a portal's own content.
An inert list clear retires only the row holding the scheduler's captured
focus, and parked rows are stamped only when focus was captured, so an
unfocused bulk removal does no per-row work. Handler publication no longer
writes an owner expando on every host.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 3, 2026
@github-actions
github-actions Bot marked this pull request as draft October 3, 2026 07:31

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/octane/src/runtime.ts Resolved
Comment thread packages/octane/src/runtime.ts Resolved
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 4 timed operation(s) possibly slower
  • 🔴 bundle-size: 14 value(s) increased
  • 🔴 bundle-reachability: 19 value(s) increased

Compares 421287457 with 5a124c1b0 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

target operation base head Δ noise
octane-tsrx replace 6.29 8.42 +33.9% ±15% 🟡 slower
octane-tsrx update 0.32 0.54 +68.7% ±45% 🟡 slower
octane-tsrx swap 0.29 0.43 +48.3% ±34% 🟡 slower
octane-jsx swap 0.58 0.85 +46.6% ±17% 🟡 slower
All 20 timed operations (16 within noise)
target operation base head Δ noise
octane-tsrx run 3.33 3.53 +6.0% ±8% ⚪ within noise
octane-tsrx replace 6.29 8.42 +33.9% ±15% 🟡 slower
octane-tsrx add 3.13 3.87 +23.6% ±33% ⚪ within noise
octane-tsrx update 0.32 0.54 +68.7% ±45% 🟡 slower
octane-tsrx select 0.13 0.19 +46.2% ±72% ⚪ within noise
octane-tsrx swap 0.29 0.43 +48.3% ±34% 🟡 slower
octane-tsrx remove 0.26 0.45 +73.1% ±53% ⚪ within noise
octane-tsrx runlots 28.67 29.38 +2.5% ±12% ⚪ within noise
octane-tsrx select_lots 0.20 0.19 −5.0% ±62% ⚪ within noise
octane-tsrx clear 37.66 41.42 +10.0% ±11% ⚪ within noise
octane-jsx run 3.36 3.54 +5.4% ±7% ⚪ within noise
octane-jsx replace 6.25 7.52 +20.3% ±20% ⚪ within noise
octane-jsx add 3.02 3.19 +5.6% ±7% ⚪ within noise
octane-jsx update 0.49 0.55 +12.2% ±28% ⚪ within noise
octane-jsx select 0.27 0.45 +66.7% ±52% ⚪ within noise
octane-jsx swap 0.58 0.85 +46.6% ±17% 🟡 slower
octane-jsx remove 0.60 0.69 +15.0% ±24% ⚪ within noise
octane-jsx runlots 27.18 29.68 +9.2% ±11% ⚪ within noise
octane-jsx select_lots 2.51 2.41 −4.0% ±24% ⚪ within noise
octane-jsx clear 39.44 42.59 +8.0% ±8% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 125,203 125,146 −57 (−0.0%) 🟢
octane-tsrx js_gzip 41,356 41,372 +16 (+0.0%) 🔴
octane-tsrx js_brotli 36,465 36,512 +47 (+0.1%) 🔴
octane-tsrx app_gzip 2,562 2,563 +1 (+0.0%) 🔴
octane-tsrx app_brotli 2,226 2,227 +1 (+0.0%) 🔴
octane-tsrx fw_raw 117,691 117,634 −57 (−0.0%) 🟢
octane-tsrx fw_gzip 38,794 38,809 +15 (+0.0%) 🔴
octane-tsrx fw_brotli 34,239 34,285 +46 (+0.1%) 🔴
octane-tsrx todo_js_raw 140,590 140,534 −56 (−0.0%) 🟢
octane-tsrx todo_js_gzip 46,407 46,386 −21 (−0.0%) 🟢
octane-tsrx todo_js_brotli 40,640 40,685 +45 (+0.1%) 🔴
octane-tsrx todo_app_gzip 2,477 2,476 −1 (−0.0%) 🟢
octane-tsrx todo_app_brotli 2,119 2,121 +2 (+0.1%) 🔴
octane-tsrx todo_fw_raw 135,480 135,424 −56 (−0.0%) 🟢
octane-tsrx todo_fw_gzip 43,930 43,910 −20 (−0.0%) 🟢
octane-tsrx todo_fw_brotli 38,521 38,564 +43 (+0.1%) 🔴
octane-tsrx chat_js_raw 139,799 139,743 −56 (−0.0%) 🟢
octane-tsrx chat_js_gzip 46,353 46,344 −9 (−0.0%) 🟢
octane-tsrx chat_js_brotli 40,785 40,801 +16 (+0.0%) 🔴
octane-tsrx chat_app_gzip 2,978 2,980 +2 (+0.1%) 🔴
octane-tsrx chat_app_brotli 2,639 2,637 −2 (−0.1%) 🟢
octane-tsrx chat_fw_raw 133,146 133,090 −56 (−0.0%) 🟢
octane-tsrx chat_fw_gzip 43,375 43,364 −11 (−0.0%) 🟢
octane-tsrx chat_fw_brotli 38,146 38,164 +18 (+0.0%) 🔴
octane-tsrx weather_js_raw 176,764 176,708 −56 (−0.0%) 🟢
octane-tsrx weather_js_gzip 57,763 57,776 +13 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,323 50,291 −32 (−0.1%) 🟢
octane-tsrx weather_app_brotli 7,584 7,562 −22 (−0.3%) 🟢
octane-tsrx weather_fw_raw 150,029 149,973 −56 (−0.0%) 🟢
octane-tsrx weather_fw_gzip 48,718 48,731 +13 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 42,739 42,729 −10 (−0.0%) 🟢
octane-jsx js_raw 226,680 226,621 −59 (−0.0%) 🟢
octane-jsx js_gzip 72,367 72,332 −35 (−0.0%) 🟢
octane-jsx js_brotli 62,726 62,649 −77 (−0.1%) 🟢
octane-jsx app_brotli 2,497 2,495 −2 (−0.1%) 🟢
octane-jsx fw_raw 218,221 218,162 −59 (−0.0%) 🟢
octane-jsx fw_gzip 69,432 69,397 −35 (−0.1%) 🟢
octane-jsx fw_brotli 60,229 60,154 −75 (−0.1%) 🟢

7 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 114,895 114,958 +63 (+0.1%) 🔴
cli-spa-starter gzip 38,762 38,787 +25 (+0.1%) 🔴
cli-spa-starter brotli 33,916 33,961 +45 (+0.1%) 🔴
root-static-specialized raw 77,026 77,029 +3 (+0.0%) 🔴
root-static-specialized gzip 25,574 25,563 −11 (−0.0%) 🟢
root-static-specialized brotli 22,778 22,800 +22 (+0.1%) 🔴
root-chained-jsx raw 84,344 84,347 +3 (+0.0%) 🔴
root-chained-jsx gzip 27,881 27,875 −6 (−0.0%) 🟢
root-chained-jsx brotli 24,833 24,838 +5 (+0.0%) 🔴
root-static raw 203,008 202,947 −61 (−0.0%) 🟢
root-static gzip 64,558 64,551 −7 (−0.0%) 🟢
root-static brotli 55,969 56,001 +32 (+0.1%) 🔴
root-static-local raw 77,029 77,032 +3 (+0.0%) 🔴
root-static-local gzip 25,560 25,557 −3 (−0.0%) 🟢
root-static-local brotli 22,776 22,797 +21 (+0.1%) 🔴
hooks-state raw 89,190 89,072 −118 (−0.1%) 🟢
hooks-state gzip 29,633 29,582 −51 (−0.2%) 🟢
hooks-state brotli 26,389 26,352 −37 (−0.1%) 🟢
prop-attributes raw 95,796 95,678 −118 (−0.1%) 🟢
prop-attributes gzip 31,774 31,735 −39 (−0.1%) 🟢
prop-attributes brotli 28,217 28,206 −11 (−0.0%) 🟢
context raw 109,201 109,083 −118 (−0.1%) 🟢
context gzip 36,119 36,078 −41 (−0.1%) 🟢
context brotli 32,026 31,945 −81 (−0.3%) 🟢
hydrate-root raw 172,836 172,839 +3 (+0.0%) 🔴
hydrate-root gzip 54,795 54,796 +1 (+0.0%) 🔴
hydrate-root brotli 47,808 47,869 +61 (+0.1%) 🔴
deferred-hydration raw 236,221 236,102 −119 (−0.1%) 🟢
deferred-hydration gzip 74,695 74,644 −51 (−0.1%) 🟢
deferred-hydration brotli 64,439 64,418 −21 (−0.0%) 🟢
suspense-transition raw 165,145 165,026 −119 (−0.1%) 🟢
suspense-transition gzip 53,003 52,962 −41 (−0.1%) 🟢
suspense-transition brotli 46,418 46,399 −19 (−0.0%) 🟢
component-owned-effects raw 81,638 81,520 −118 (−0.1%) 🟢
component-owned-effects gzip 26,931 26,872 −59 (−0.2%) 🟢
component-owned-effects brotli 23,981 23,933 −48 (−0.2%) 🟢
binding-hooks raw 87,703 87,585 −118 (−0.1%) 🟢
binding-hooks gzip 29,336 29,324 −12 (−0.0%) 🟢
binding-hooks brotli 26,130 26,070 −60 (−0.2%) 🟢
binding-base-ui-vite raw 213,239 213,178 −61 (−0.0%) 🟢
binding-base-ui-vite gzip 68,137 68,133 −4 (−0.0%) 🟢
binding-base-ui-vite brotli 59,057 59,065 +8 (+0.0%) 🔴
binding-base-ui-esbuild raw 211,196 211,135 −61 (−0.0%) 🟢
binding-base-ui-esbuild gzip 68,119 68,098 −21 (−0.0%) 🟢
binding-base-ui-esbuild brotli 59,070 58,987 −83 (−0.1%) 🟢
binding-aria-esbuild brotli 3,014 3,012 −2 (−0.1%) 🟢
binding-radix-vite raw 215,169 215,110 −59 (−0.0%) 🟢
binding-radix-vite gzip 68,709 68,690 −19 (−0.0%) 🟢
binding-radix-vite brotli 59,589 59,606 +17 (+0.0%) 🔴
binding-radix-esbuild raw 213,086 213,027 −59 (−0.0%) 🟢
binding-radix-esbuild gzip 68,708 68,677 −31 (−0.0%) 🟢
binding-radix-esbuild brotli 59,547 59,621 +74 (+0.1%) 🔴
binding-mantine-hooks-vite raw 96,431 96,313 −118 (−0.1%) 🟢
binding-mantine-hooks-vite gzip 31,991 31,965 −26 (−0.1%) 🟢
binding-mantine-hooks-vite brotli 28,434 28,413 −21 (−0.1%) 🟢
binding-mantine-hooks-esbuild raw 96,030 95,912 −118 (−0.1%) 🟢
binding-mantine-hooks-esbuild gzip 32,165 32,131 −34 (−0.1%) 🟢
binding-mantine-hooks-esbuild brotli 28,613 28,602 −11 (−0.0%) 🟢
binding-apollo-client-vite raw 358,254 358,193 −61 (−0.0%) 🟢
binding-apollo-client-vite gzip 112,253 112,252 −1 (−0.0%) 🟢
binding-apollo-client-vite brotli 97,970 98,030 +60 (+0.1%) 🔴
binding-apollo-client-esbuild raw 361,203 361,142 −61 (−0.0%) 🟢
binding-apollo-client-esbuild gzip 114,461 114,429 −32 (−0.0%) 🟢
binding-apollo-client-esbuild brotli 99,684 99,594 −90 (−0.1%) 🟢
binding-usehooks-ts-vite raw 97,064 96,946 −118 (−0.1%) 🟢
binding-usehooks-ts-vite gzip 32,156 32,137 −19 (−0.1%) 🟢
binding-usehooks-ts-vite brotli 28,573 28,583 +10 (+0.0%) 🔴
binding-usehooks-ts-esbuild raw 96,652 96,534 −118 (−0.1%) 🟢
binding-usehooks-ts-esbuild gzip 32,316 32,289 −27 (−0.1%) 🟢
binding-usehooks-ts-esbuild brotli 28,719 28,742 +23 (+0.1%) 🔴

35 other measured values are unchanged.

…eardown

The owned-list clear read row.parentNode directly; read it through domNode so
the staged-DOM boundary check classifies it (lint checks).

Stamp a portal's own range in unmountBlockInner rather than only in
teardownPortalState, so a portal torn down through unmountSlot's portal
branch, such as one detaching under a retained hydration parent, retires its
content before its cleanups run too. A non-parkable list clear stamps each row
before its cleanup under the same captured-focus rule as parked rows. Add a
regression for a portal compiled in a template.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 3, 2026 07:46

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: List clear stamps rows too late
    • Split batchClearItems into two passes—first retire all rows' host ranges, then unmount—so an earlier row's cleanup cannot dispatch events on not-yet-retired hosts in later rows.

Create PR

Or push these changes by commenting:

@cursor push b003c91ccb
Preview (b003c91ccb)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -46519,13 +46519,21 @@
 	const retire = renderingFocus !== null || !inFlush;
 	TEARDOWN_DEPTH++;
 	try {
+		// Retire every row's hosts BEFORE any row's cleanups run: an earlier
+		// row's layout cleanup can move focus, which dispatches on a later row's
+		// hosts. If those hosts are not yet retired, the handler runs against a
+		// scope the clear is about to dispose.
+		if (retire) {
+			for (let b: Block | null = state.head; b !== null; b = b.nextSibling) {
+				retireHostRange(b.startMarker, b.endMarker);
+			}
+		}
 		// Dispose the items before their DOM leaves, like every other deletion:
 		// cleanups observe attached hosts. Walk the intrusive item chain (head →
 		// nextSibling) rather than the Map's iterator: zero allocation and a
 		// monomorphic pointer chase. Callers reset head/tail only AFTER this returns,
 		// so the chain still covers exactly the old items here.
 		for (let b: Block | null = state.head; b !== null; b = b.nextSibling) {
-			if (retire) retireHostRange(b.startMarker, b.endMarker);
 			if (b.cleanups !== null || b.children !== null || b._slots !== null) {
 				unmountBlock(b, false);
 			} else {

You can send follow-ups to the cloud agent here.

Comment thread packages/octane/src/runtime.ts Resolved
trueadm and others added 4 commits October 3, 2026 08:58
… cleanup

batchClearItems stamped each row just before that row's own teardown, so an
earlier row's cleanup that moved focus could still start onBlur on a later row
the same clear was removing. Stamp the whole span between the list's markers
first, under the same captured-focus rule as parked rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gment owner unmounts

Stamping every portal Block's range in unmountBlockInner also stamped a
foreign portal range parked between a Fragment owner's markers, so a click on
that still-mounted portal in the same task started no handler
(conformance/fragment-future-children). Retire a portal's range in
teardownPortalState again: a portal compiled into a template routes its
events through a host element inside its owner, which the enclosing deletion
has already retired before any cleanup runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every transactional blockless de-opt removal now commits through
deferRootRange, which retires its nodes before their cleanup runs, so the
stamp detachDeoptTreeRefs added for #1549 repeats it. Removing it returns
detachDeoptTreeRefs to its single recursive form and keeps root-chained-jsx
within the budget main tightened to 84,352 raw bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cursor

cursor Bot commented Oct 3, 2026

Copy link
Copy Markdown

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Deferred unmounts skip host retirement
    • Added nodes.forEach(retireEventHostTree) in deferRootUnmount's commit callback after reconnection and before unmountBlock, and added retireHostRange(val.start, val.end) in the portalSlotSlot branch of unmountSlot before calling unmountBlock on the portal block, matching the patterns already established by deferRootRange and teardownPortalState.
  • ✅ Fixed: List clear drops retirement stamps
    • Added focused-row retirement in batchClearItems before the unmount loop, walking from the scheduler's captured focused element to the list parent's direct child and stamping it with retireEventHostTree, matching the pattern already used by deferRootOwnedListClear.

Create PR

Or push these changes by commenting:

@cursor push 0ff26217f3
Preview (0ff26217f3)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -4107,6 +4107,8 @@
 				if ((STAGED_DOM?.view(node) ?? node).parentNode !== parent)
 					(STAGED_DOM?.view(parent) ?? parent).insertBefore(node, anchor);
 		}
+		// Retire the outgoing nodes before any cleanup can move focus off them.
+		nodes.forEach(retireEventHostTree);
 		const previousSuppression = REF_DETACH_SUPPRESSION;
 		REF_DETACH_SUPPRESSION = suppressedRefs;
 		try {
@@ -12367,6 +12369,8 @@
 		// Portal DOM lives in a FOREIGN target — the root-level batched clear
 		// never reaches it, so portals must always self-detach individually.
 		const childDetach = k === 'portalSlotSlot' ? true : detachDom;
+		// Its DOM lies outside every enclosing deletion's range: retire it here.
+		if (k === 'portalSlotSlot' && val.block) retireHostRange(val.start, val.end);
 		if (val.block) unmountBlock(val.block, childDetach);
 		if (k === 'portalSlotSlot' && val.target) {
 			unregisterPortalEventRange(val.target, val);
@@ -46516,6 +46520,12 @@
 	}
 	TEARDOWN_DEPTH++;
 	try {
+		// Retire the focused row before any cleanup can blur it: only removing a
+		// focused row dispatches focusout during a synchronous batch clear.
+		const p = domNode(state.start).parentNode!;
+		let row: Node | null | undefined = (renderingFocus as FocusSelectionSnapshot | null)?.focused;
+		while (row != null && row.parentNode !== p) row = row.parentNode ?? (row as ShadowRoot).host;
+		if (row != null) retireEventHostTree(row);
 		// Dispose the items before their DOM leaves, like every other deletion:
 		// cleanups observe attached hosts. Walk the intrusive item chain (head →
 		// nextSibling) rather than the Map's iterator: zero allocation and a
@@ -46534,7 +46544,6 @@
 				b.disposed = true;
 			}
 		}
-		const p = domNode(state.start).parentNode!;
 		if (domNode(state.start).previousSibling === null && getNextSibling(state.end) === null) {
 			// forBlock owns the parent — nuke everything in one DOM op, then re-add markers.
 			(STAGED_DOM?.view(p as Element) ?? (p as Element)).textContent = '';

You can send follow-ups to the cloud agent here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: De-opt teardown no longer retires hosts
    • Restored the root-level retireEventHostTree(node) call inside detachDeoptTreeRefs for teardown paths (out === null), ensuring non-transactional removals (clearChildContent immediate sweep, clone() adoption, unmountSlot hostNode teardown, and reconciler else-branches) retire hosts before detach so focusout cannot fire on a non-retired node.

Create PR

Or push these changes by commenting:

@cursor push 34762d6738
Preview (34762d6738)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -44438,7 +44438,11 @@
 	ownerScope?: Scope,
 	uncommitted: UncommittedRefAttaches | null = null,
 	activityRefs: WeakMap<Element | FragmentInstance, ActivityRefState> | null = null,
+	// Only the removed subtree's root carries the retirement stamp.
+	root: boolean = true,
 ): void {
+	// Teardown runs just before every blockless de-opt removal detaches `node`.
+	if (root && out === null) retireEventHostTree(node);
 	// No de-opt descriptor ref was ever stamped → nothing to detach or collect
 	// anywhere; skip the subtree scan. (Monotone flag — see noteDeoptRef.)
 	if (!DEOPT_REFS_STAMPED) return;
@@ -44472,7 +44476,7 @@
 			c = nodeAfterPortalRange(c, rangeEnd);
 			continue;
 		}
-		detachDeoptTreeRefs(c, out, shouldDetach, ownerScope, uncommitted, activityRefs);
+		detachDeoptTreeRefs(c, out, shouldDetach, ownerScope, uncommitted, activityRefs, false);
 		c = getNextSibling(c);
 	}
 }

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 29ba34b. Configure here.

uncommitted: UncommittedRefAttaches | null = null,
activityRefs: WeakMap<Element | FragmentInstance, ActivityRefState> | null = null,
): void {
// Teardown runs just before every blockless de-opt removal detaches `node`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De-opt teardown no longer retires hosts

Medium Severity

detachDeoptTreeRefs no longer stamps a host before teardown detach. Immediate blockless removals — value-hole hosts outside a root transaction, clearChildContent's non-deferred sweep, and clone() adoption replaceChild/replaceChildren — can dispatch focusout at a host that still starts its handler.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 29ba34b. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional trade-off in 29ba34b, pending a maintainer decision, so I'm leaving this open. Restoring the hook costs about 27 raw bytes on root-chained-jsx, which is past the 84,352 budget #1637 set; main alone measures 84,344.

What is actually exposed without it:

  • Non-transaction branches. The 'outside a root transaction' value-hole removals and clearChildContent's immediate sweep only run without a root transaction, and createRoot renders always open one. Their transactional twins commit through deferRootRange, which stamps the same nodes before the cleanup runs.
  • clone(). It replaces mismatched server nodes during hydration adoption, before Octane publishes any handler on them, so no handler can start.
  • Reachable gap. Two render-time de-opt removals bypass deferRootRange: a mapped item switching from a host to a component (mappedDeoptItemBody), and the deoptItemBody transfer fallback. Both are listed in the PR's risk section.

If the budget can move one 32-byte step, the hook goes back as it was.

🤖 Addressed by Claude Code

@trueadm

trueadm commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

Not adopting the Bugbot Autofix branch (cursor/octane-host-retirement-issues-4297, based on bc9ad49). Both issues are already handled on this branch, and parts of that patch would regress:

  • portalSlotSlot: stamping val.start..val.end in unmountSlot walks into an independent portal parked inside a Fragment owner's markers. That is the conformance/fragment-future-children failure fixed in 8713081. A template portal routes its events through a host element inside its owner, which the enclosing deletion has already retired.
  • batchClearItems: 870e6c4 stamps the whole span between the list's markers before any row's cleanup. The proposed version stamps only the focused row and reads row.parentNode directly, which fails the staged-DOM check.
  • deferRootUnmount: intentionally unstamped at commit. With detachDom its nodes already left the document, and took focus with them, during render; otherwise the caller clears them at render time.

🤖 Addressed by Claude Code

@trueadm
trueadm merged commit a9594d0 into main Oct 3, 2026
35 checks passed
@trueadm
trueadm deleted the fix/retired-host-anchor branch October 3, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant