Skip to content

fix(octane): skip retired hosts when removal dispatches focusout - #1548

Merged
trueadm merged 7 commits into
mainfrom
fix/retired-event-hosts
Oct 2, 2026
Merged

trueadm merged 7 commits into
mainfrom
fix/retired-event-hosts

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • When a focused input is removed, Chromium dispatches focusout synchronously, after Octane has already disposed the component that owns it. Delegated dispatch no longer starts handlers on hosts whose component has unmounted.
  • A signal write from such an onBlur used to report ScopeDisposedError (production error 151). A plain onBlur used to run for an unmounted component, which React never does.

Closes #1472

Why

Teardown disposes a Block before detaching its DOM. This order is deliberate: deletion cleanups observe attached DOM, as in React. Removing a focused host makes Chromium dispatch focusout while the removal is in progress, and Octane's delegation still invoked the retired handlers. The bug reproduced on current main for:

  • root unmount and root.render(null);
  • portal unmount and nested-root unmount;
  • an @if arm unmounting the input's owning component;
  • keyed @for row removal.

Changes

  • setEventHandler records the Block that rendered each event host in $$eventOwner, seeded on Element.prototype. A live claim is never replaced, because lite @for rows republish bare handlers under their list's Block. A disposed claim is replaced, because a hydration retry adopts the same server node under a new Block.
  • A disposed Block records the event-route epoch at which its hosts leave dispatch (retireEventOwner). This applies to Block unmount and to both list-clear paths. A ViewTransition deletion records it only when it publishes, so its committed hosts stay interactive until then.
  • snapshotDelegatedSlots skips a host only if it retired before the native delivery began, using the delivery's existing EVENT_ROOT_EPOCH stamp.
  • The following behavior is unchanged:
    • Live ancestors still receive the event; React suppresses every event during its commit instead. Documented in docs/differences-from-react.md.
    • Other roots and handlers already in a snapshot still run.
    • A delivery already in flight keeps its route through the end of that delivery (perf: reduce remaining DOM and event overhead #1068).
  • blur-during-teardown/discrete-flush-reentrancy previously asserted that a disposed @if arm's onBlur runs. The counted handler now sits on a live ancestor, so the no-re-entrant-flush purpose is unchanged, and the test asserts that the disposed arm's handler does not run.

Differences from the fix proposed in the issue

  • A plain disposed check broke two existing contracts:
  • The epoch comparison keeps both contracts.
  • "Republishing outside rendering clears the owner" was not adopted. Only the internal setEventHandler compiler target can reach it, so it is speculative and untestable through a public path.

Validation

  • pnpm typecheck:files and pnpm format:files:check on the changed files
  • pnpm format:check (repo-wide): not run
  • pnpm typecheck (repo-wide): not run
  • pnpm test, replayed locally as CI's four shards (vitest.ci-sharded.config.js, CI excludes), on the pre-merge branch:
    • Shards 3 and 4 were clean (9,245 and 12,901 tests).
    • Shards 1 and 2 had 21 failures, all at timeout bounds or a cascade from one, while other worktrees' suites loaded the machine. All 8 affected files pass when run alone.
    • The single-process pnpm test ran out of the Vitest main process's 4 GB heap after 29 minutes, which is why the shards were replayed.
  • octane-events-browser and octane-signals-browser: 28 files, 365 tests, before the merge.
  • After merging main (fab9c74), re-ran the closest suites: retired-event-hosts, discrete-flush-reentrancy, portal-events, view-transition-staging, event-signal-owner, and the hydration retry suites (octane and octane-prod, 348 tests), plus the browser retired-event-hosts and event-metadata (26 tests). All pass. A broader post-merge run hit timeouts at load average ~72; CI covers the full suite.
  • New Chromium suite tests/browser/retired-event-hosts: 11 scenarios, each in dev and prod builds.
    • On main's runtime, all 18 removal cases fail and the 4 controls pass.
  • New jsdom regression tests/retired-event-hosts.test.ts (octane and octane-prod) covers a deletion cleanup that moves focus. It fails on main.
  • Mutation checks:
    • Always overwriting the claim fails the @for row-update case.
    • Never replacing a disposed claim fails 8 hydration-retry tests.
  • CI's bundle checks pass locally on the branch merged with current main (3f1a7b2): run-minimal.mjs --budgets ..., behavior-root (unchanged), and binding-apollo-client.
    • Budget change: root-chained-jsx needs +75 gzip / +115 brotli over current main (28,324 → 28,399 gzip) for the Block field, the inline disposal stamp, and the dispatch check, while main had only 60 gzip bytes of headroom left. Its gzip and brotli ceilings rise by one 32-byte step (28,384 → 28,416 and 25,248 → 25,280); raw stays within 85,728 and every other budget is unchanged.
  • benchmarks/view-transitions/effect-cleanup.mjs (function-call budget) passes; clears are back to baseline (tsrx cold clear 47,088 calls against 47,089) because the disposal stamp is inline rather than a per-Block call.
  • Bugbot: batchClearItems' immediate path now disposes items before clearing their DOM.
  • Performance: same-page interleaved Chromium A/B (both runtimes in one page, both load orders, 48 samples each).
    • Mount of 10,000 rows with 30,000 handler hosts and 20,000 click dispatches are within the A/A spread (about ±3%).
    • Republishing a bare-function handler during a lite-row update costs about 6ns (+12% on an op that only republishes 50,000 handlers).

Risk / follow-ups

  • A pure-host node dropped from a value hole of a still-mounted component ({editing && <input onBlur={commit} />}) still runs its onBlur on removal, because its owner Block stays live. A stacked follow-up PR covers it.
  • Each Block gains one numeric field (retired). A ViewTransition deletion retires its Blocks through one deferred-layout-driver action per capture, so that code ships only with ViewTransition. The global event-route epoch now advances per retired Block, so a delivery that spans an unmount takes the general (portal-aware) path builder for its remaining phases.

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 core delegated event dispatch and teardown ordering during unmount; behavior is well-tested but touches hot paths and ViewTransition staging.

Overview
Fixes #1472: when teardown removes a focused element, Chromium fires synchronous focusout, and Octane no longer runs delegated handlers on hosts whose component was already disposed.

Each event host records its rendering Block in $$eventOwner. On unmount (and staged ViewTransition publish), blocks get a retired event-route epoch before DOM is detached. snapshotDelegatedSlots drops handlers on hosts retired before the current native delivery started (using EVENT_ROOT_EPOCH), while in-flight dispatches and still-mounted ancestors keep working—unlike React, which suppresses all commit-time events.

batchClearItems and related teardown paths now dispose/retire items before bulk DOM removal, with teardown error boundaries aligned to unmountBlock. Docs note the React difference; bundle budget for root-chained-jsx rises slightly. New browser and jsdom tests cover unmount, portals, @if/@for, and signal onBlur cases.

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

trueadm and others added 2 commits October 2, 2026 08:44
Teardown disposes a Block before it detaches the Block's DOM, and Chromium
dispatches focusout synchronously while it removes a focused host. Delegated
dispatch then started handlers on hosts whose component had unmounted: a
signal write reported ScopeDisposedError (production error 151) and plain
onBlur handlers ran for unmounted components.

setEventHandler records the rendering Block on each event host, a disposed
Block records the event-route epoch at which its hosts leave dispatch (staged
for a ViewTransition deletion), and a phase snapshot skips hosts that retired
before the native delivery began. Live ancestors, other roots, snapshotted
handlers, and in-flight deliveries keep their existing behavior.

Closes #1472

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 2, 2026
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 08:34
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 36 value(s) increased
  • 🔴 bundle-reachability: 70 value(s) increased

Compares 3f1a7b266 with 839fcc7a5 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)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 3.33 3.45 +3.6% ±10% ⚪ within noise
octane-tsrx replace 7.02 7.95 +13.2% ±28% ⚪ within noise
octane-tsrx add 4.12 3.69 −10.4% ±31% ⚪ within noise
octane-tsrx update 0.55 0.40 −27.3% ±56% ⚪ within noise
octane-tsrx select 0.20 0.13 −35.0% ±75% ⚪ within noise
octane-tsrx swap 0.39 0.37 −5.1% ±49% ⚪ within noise
octane-tsrx remove 0.33 0.34 +3.0% ±45% ⚪ within noise
octane-tsrx runlots 30.96 29.66 −4.2% ±17% ⚪ within noise
octane-tsrx select_lots 0.26 0.21 −19.2% ±74% ⚪ within noise
octane-tsrx clear 40.66 40.83 +0.4% ±8% ⚪ within noise
octane-jsx run 3.87 3.48 −10.1% ±19% ⚪ within noise
octane-jsx replace 8.29 7.33 −11.6% ±32% ⚪ within noise
octane-jsx add 3.34 3.29 −1.5% ±18% ⚪ within noise
octane-jsx update 0.56 0.55 −1.8% ±43% ⚪ within noise
octane-jsx select 0.36 0.40 +11.1% ±44% ⚪ within noise
octane-jsx swap 0.63 0.59 −6.3% ±34% ⚪ within noise
octane-jsx remove 0.59 0.55 −6.8% ±45% ⚪ within noise
octane-jsx runlots 26.96 28.71 +6.5% ±14% ⚪ within noise
octane-jsx select_lots 2.38 2.13 −10.5% ±24% ⚪ within noise
octane-jsx clear 44.10 43.98 −0.3% ±17% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 126,052 126,449 +397 (+0.3%) 🔴
octane-tsrx js_gzip 41,685 41,848 +163 (+0.4%) 🔴
octane-tsrx js_brotli 36,731 36,840 +109 (+0.3%) 🔴
octane-tsrx app_gzip 2,563 2,562 −1 (−0.0%) 🟢
octane-tsrx app_brotli 2,222 2,235 +13 (+0.6%) 🔴
octane-tsrx fw_raw 118,540 118,937 +397 (+0.3%) 🔴
octane-tsrx fw_gzip 39,122 39,286 +164 (+0.4%) 🔴
octane-tsrx fw_brotli 34,509 34,605 +96 (+0.3%) 🔴
octane-tsrx todo_js_raw 140,401 140,799 +398 (+0.3%) 🔴
octane-tsrx todo_js_gzip 46,327 46,504 +177 (+0.4%) 🔴
octane-tsrx todo_js_brotli 40,584 40,742 +158 (+0.4%) 🔴
octane-tsrx todo_app_brotli 2,118 2,122 +4 (+0.2%) 🔴
octane-tsrx todo_fw_raw 135,291 135,689 +398 (+0.3%) 🔴
octane-tsrx todo_fw_gzip 43,851 44,028 +177 (+0.4%) 🔴
octane-tsrx todo_fw_brotli 38,466 38,620 +154 (+0.4%) 🔴
octane-tsrx chat_js_raw 139,646 140,044 +398 (+0.3%) 🔴
octane-tsrx chat_js_gzip 46,280 46,438 +158 (+0.3%) 🔴
octane-tsrx chat_js_brotli 40,616 40,782 +166 (+0.4%) 🔴
octane-tsrx chat_app_gzip 2,976 2,980 +4 (+0.1%) 🔴
octane-tsrx chat_app_brotli 2,634 2,640 +6 (+0.2%) 🔴
octane-tsrx chat_fw_raw 132,993 133,391 +398 (+0.3%) 🔴
octane-tsrx chat_fw_gzip 43,304 43,458 +154 (+0.4%) 🔴
octane-tsrx chat_fw_brotli 37,982 38,142 +160 (+0.4%) 🔴
octane-tsrx weather_js_raw 175,886 176,285 +399 (+0.2%) 🔴
octane-tsrx weather_js_gzip 57,427 57,612 +185 (+0.3%) 🔴
octane-tsrx weather_js_brotli 49,941 50,105 +164 (+0.3%) 🔴
octane-tsrx weather_app_brotli 7,606 7,605 −1 (−0.0%) 🟢
octane-tsrx weather_fw_raw 149,151 149,550 +399 (+0.3%) 🔴
octane-tsrx weather_fw_gzip 48,383 48,568 +185 (+0.4%) 🔴
octane-tsrx weather_fw_brotli 42,335 42,500 +165 (+0.4%) 🔴
octane-jsx js_raw 224,338 224,739 +401 (+0.2%) 🔴
octane-jsx js_gzip 71,476 71,651 +175 (+0.2%) 🔴
octane-jsx js_brotli 61,858 62,128 +270 (+0.4%) 🔴
octane-jsx app_gzip 2,943 2,944 +1 (+0.0%) 🔴
octane-jsx app_brotli 2,501 2,503 +2 (+0.1%) 🔴
octane-jsx fw_raw 215,871 216,272 +401 (+0.2%) 🔴
octane-jsx fw_gzip 68,533 68,707 +174 (+0.3%) 🔴
octane-jsx fw_brotli 59,357 59,625 +268 (+0.5%) 🔴

7 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 115,861 116,137 +276 (+0.2%) 🔴
cli-spa-starter gzip 39,101 39,222 +121 (+0.3%) 🔴
cli-spa-starter brotli 34,179 34,234 +55 (+0.2%) 🔴
root-static-specialized raw 76,671 76,775 +104 (+0.1%) 🔴
root-static-specialized gzip 25,397 25,459 +62 (+0.2%) 🔴
root-static-specialized brotli 22,602 22,679 +77 (+0.3%) 🔴
root-chained-jsx raw 85,537 85,641 +104 (+0.1%) 🔴
root-chained-jsx gzip 28,324 28,399 +75 (+0.3%) 🔴
root-chained-jsx brotli 25,143 25,258 +115 (+0.5%) 🔴
root-static raw 200,661 201,062 +401 (+0.2%) 🔴
root-static gzip 63,645 63,824 +179 (+0.3%) 🔴
root-static brotli 55,276 55,370 +94 (+0.2%) 🔴
root-static-local raw 76,674 76,778 +104 (+0.1%) 🔴
root-static-local gzip 25,385 25,449 +64 (+0.3%) 🔴
root-static-local brotli 22,641 22,709 +68 (+0.3%) 🔴
hooks-state raw 88,719 88,943 +224 (+0.3%) 🔴
hooks-state gzip 29,429 29,528 +99 (+0.3%) 🔴
hooks-state brotli 26,221 26,321 +100 (+0.4%) 🔴
prop-attributes raw 96,873 97,097 +224 (+0.2%) 🔴
prop-attributes gzip 32,156 32,246 +90 (+0.3%) 🔴
prop-attributes brotli 28,523 28,624 +101 (+0.4%) 🔴
context raw 109,419 109,645 +226 (+0.2%) 🔴
context gzip 36,195 36,273 +78 (+0.2%) 🔴
context brotli 31,977 32,059 +82 (+0.3%) 🔴
hydrate-root raw 160,598 160,703 +105 (+0.1%) 🔴
hydrate-root gzip 51,436 51,496 +60 (+0.1%) 🔴
hydrate-root brotli 44,808 44,899 +91 (+0.2%) 🔴
deferred-hydration raw 222,853 223,080 +227 (+0.1%) 🔴
deferred-hydration gzip 70,885 70,971 +86 (+0.1%) 🔴
deferred-hydration brotli 61,229 61,261 +32 (+0.1%) 🔴
suspense-transition raw 165,924 166,151 +227 (+0.1%) 🔴
suspense-transition gzip 53,281 53,376 +95 (+0.2%) 🔴
suspense-transition brotli 46,495 46,569 +74 (+0.2%) 🔴
component-owned-effects raw 81,167 81,391 +224 (+0.3%) 🔴
component-owned-effects gzip 26,732 26,817 +85 (+0.3%) 🔴
component-owned-effects brotli 23,834 23,908 +74 (+0.3%) 🔴
binding-hooks raw 87,231 87,456 +225 (+0.3%) 🔴
binding-hooks gzip 29,191 29,267 +76 (+0.3%) 🔴
binding-hooks brotli 25,993 26,083 +90 (+0.3%) 🔴
binding-base-ui-vite raw 210,855 211,256 +401 (+0.2%) 🔴
binding-base-ui-vite gzip 67,201 67,361 +160 (+0.2%) 🔴
binding-base-ui-vite brotli 58,282 58,449 +167 (+0.3%) 🔴
binding-base-ui-esbuild raw 208,838 209,235 +397 (+0.2%) 🔴
binding-base-ui-esbuild gzip 67,194 67,379 +185 (+0.3%) 🔴
binding-base-ui-esbuild brotli 58,335 58,467 +132 (+0.2%) 🔴
binding-aria-esbuild brotli 3,009 3,013 +4 (+0.1%) 🔴
binding-radix-vite raw 212,784 213,185 +401 (+0.2%) 🔴
binding-radix-vite gzip 67,771 67,953 +182 (+0.3%) 🔴
binding-radix-vite brotli 58,830 58,880 +50 (+0.1%) 🔴
binding-radix-esbuild raw 210,726 211,123 +397 (+0.2%) 🔴
binding-radix-esbuild gzip 67,773 67,932 +159 (+0.2%) 🔴
binding-radix-esbuild brotli 58,791 59,032 +241 (+0.4%) 🔴
binding-mantine-hooks-vite raw 97,507 97,732 +225 (+0.2%) 🔴
binding-mantine-hooks-vite gzip 32,387 32,470 +83 (+0.3%) 🔴
binding-mantine-hooks-vite brotli 28,765 28,838 +73 (+0.3%) 🔴
binding-mantine-hooks-esbuild raw 97,101 97,324 +223 (+0.2%) 🔴
binding-mantine-hooks-esbuild gzip 32,568 32,647 +79 (+0.2%) 🔴
binding-mantine-hooks-esbuild brotli 28,920 29,003 +83 (+0.3%) 🔴
binding-apollo-client-vite raw 355,904 356,305 +401 (+0.1%) 🔴
binding-apollo-client-vite gzip 111,322 111,507 +185 (+0.2%) 🔴
binding-apollo-client-vite brotli 97,188 97,347 +159 (+0.2%) 🔴
binding-apollo-client-esbuild raw 358,891 359,290 +399 (+0.1%) 🔴
binding-apollo-client-esbuild gzip 113,553 113,740 +187 (+0.2%) 🔴
binding-apollo-client-esbuild brotli 98,873 99,099 +226 (+0.2%) 🔴
binding-usehooks-ts-vite raw 98,140 98,365 +225 (+0.2%) 🔴
binding-usehooks-ts-vite gzip 32,549 32,637 +88 (+0.3%) 🔴
binding-usehooks-ts-vite brotli 28,910 28,995 +85 (+0.3%) 🔴
binding-usehooks-ts-esbuild raw 97,723 97,946 +223 (+0.2%) 🔴
binding-usehooks-ts-esbuild gzip 32,720 32,807 +87 (+0.3%) 🔴
binding-usehooks-ts-esbuild brotli 29,081 29,191 +110 (+0.4%) 🔴

35 other measured values are unchanged.

CI job durations

  • 🟡 3 job(s) slower than every recent main run: heavy integration (package builds, eval corpus, runtime loaders, Astro), validate publishable packages, example apps (1/3)

Compares the CI run for 5ab6b8479 (run) with the last 5 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s. Job time excludes runner setup.

job main median main range this PR Δ
wall clock (first job start to last job end) 12m 39s 11m 55s–15m 07s 12m 10s −29s (−4%) ⚪ within noise
total job time 140m 36s 134m 18s–156m 28s 138m 12s −2m 24s (−2%) ⚪ within noise
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 43s 5m 21s–5m 45s 6m 51s +1m 08s (+20%) 🟡 slower
validate publishable packages 3m 58s 3m 51s–4m 29s 4m 41s +43s (+18%) 🟡 slower
example apps (1/3) 3m 10s 3m 04s–3m 14s 3m 43s +33s (+17%) 🟡 slower
All 26 timed jobs
job main median main range this PR Δ
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 43s 5m 21s–5m 45s 6m 51s +1m 08s (+20%) 🟡 slower
validate publishable packages 3m 58s 3m 51s–4m 29s 4m 41s +43s (+18%) 🟡 slower
example apps (1/3) 3m 10s 3m 04s–3m 14s 3m 43s +33s (+17%) 🟡 slower
heavy integration (browser - chromium) 11m 08s 10m 58s–12m 54s 11m 40s +32s (+5%) ⚪ within noise
React parity shard (4/4) 10m 52s 10m 08s–12m 06s 11m 14s +22s (+3%) ⚪ within noise
website integration suite 5m 46s 5m 43s–7m 00s 6m 03s +17s (+5%) ⚪ within noise
lint checks 7m 52s 7m 43s–9m 37s 8m 02s +10s (+2%) ⚪ within noise
example apps (3/3) 3m 37s 3m 19s–3m 41s 3m 47s +10s (+5%) ⚪ within noise
Three compatibility 2m 42s 2m 38s–2m 56s 2m 44s +2s (+1%) ⚪ within noise
test shard (Node 24, 1/4) 11m 23s 10m 36s–12m 46s 11m 25s +2s (+0%) ⚪ within noise
classify changeset release 13s 12s–13s 13s ±0s (±0%) ⚪ within noise
Lynx compatibility 1m 32s 1m 29s–2m 04s 1m 32s ±0s (±0%) ⚪ within noise
test shard (Node 24, 3/4) 9m 31s 9m 24s–10m 50s 9m 31s ±0s (±0%) ⚪ within noise
typecheck 3s 3s–3s 3s ±0s (±0%) ⚪ within noise
test (24) 3s 2s–4s 3s ±0s (±0%) ⚪ within noise
CI provenance 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
examples 3s 3s–4s 2s −1s (−33%) ⚪ within noise
lint 3s 3s–4s 2s −1s (−33%) ⚪ within noise
React parity checks 11s 10s–12s 10s −1s (−9%) ⚪ within noise
example apps (2/3) 3m 43s 3m 38s–3m 49s 3m 38s −5s (−2%) ⚪ within noise
typecheck checks 2m 13s 1m 56s–9m 11s 2m 03s −10s (−8%) ⚪ within noise
test shard (Node 24, 2/4) 11m 17s 10m 38s–14m 29s 10m 59s −18s (−3%) ⚪ within noise
React parity shard (3/4) 10m 25s 10m 08s–12m 02s 9m 56s −29s (−5%) ⚪ within noise
React parity shard (1/4) 10m 51s 10m 23s–11m 04s 10m 10s −41s (−6%) ⚪ within noise
React parity shard (2/4) 10m 30s 9m 52s–11m 18s 9m 36s −54s (−9%) ⚪ within noise
test shard (Node 24, 4/4) 11m 03s 10m 21s–13m 56s 10m 01s −1m 02s (−9%) ⚪ within noise

@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 retires hosts after detach
    • Added a retireEventOwner pre-pass loop before the DOM removal in batchClearItems so synchronous focusout during detach sees every row as retired, matching the ordering in unmountBlockInner and deferRootOwnedListClear.

Create PR

Or push these changes by commenting:

@cursor push 63293cf0b6
Preview (63293cf0b6)
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
@@ -44260,6 +44260,12 @@
 		return;
 	}
 	const p = domNode(state.start).parentNode!;
+	// Retire event owners before the DOM detach so that synchronous focusout
+	// (or any other removal-triggered event) sees every row as retired.
+	// Mirrors unmountBlockInner and the deferred owned-clear commit path.
+	for (let b: Block | null = state.head; b !== null; b = b.nextSibling) {
+		retireEventOwner(b);
+	}
 	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.

Comment thread packages/octane/src/runtime.ts Resolved
trueadm and others added 4 commits October 2, 2026 12:52
Stamp a disposed Block's retirement inline where Blocks are disposed instead
of calling a helper per Block: the ViewTransition effect-cleanup gate allows
no extra call per removed row. A staged deletion now retires its Blocks
through one deferred-layout-driver action per capture, so the batching code
ships only with ViewTransition. The snapshot check is inlined and the Block
field is renamed `retired`, keeping root-chained-jsx within its committed
byte budget.

batchClearItems' immediate path now disposes the items before it clears
their DOM, matching every other deletion: cleanups observe attached hosts,
and removing a focused row finds its hosts already retired.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Move the $$eventOwner prototype seed into delegateEvents so handler-free
bundles skip it, and read the owner's retirement through optional chaining.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Branch on the staged capture by truthiness and shorten the driver method to
`retireHosts`. root-chained-jsx still needs 75 gzip / 115 brotli bytes over
current main for the Block field, the inline disposal stamp, and the dispatch
check, which exceeds the 60-byte gzip headroom main had left. Raise only its
gzip and brotli ceilings by one 32-byte step (28416 / 25280); raw stays within
85728 and every other budget is unchanged.

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

@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: Missing disposal check after list teardown
    • Wrapped the unmount loop and DOM manipulation in batchClearItems in a single teardown bracket (TEARDOWN_DEPTH++/try/finally) so that dispatchTeardownErrors is deferred until both phases complete and the markers are consistent, matching the pattern used by resetScopeChildren and unmountBlock.

Create PR

Or push these changes by commenting:

@cursor push 7c69a60f9c
Preview (7c69a60f9c)
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
@@ -44806,41 +44806,57 @@
 	// 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 (b.cleanups !== null || b.children !== null || b._slots !== null) {
-			unmountBlock(b, false);
+	//
+	// The bracket spans the unmount walk AND the DOM removal so that a cleanup
+	// error is deferred until the markers are consistent: without it each
+	// unmountBlock installs its own bracket at TEARDOWN_DEPTH 0, and the dispatch
+	// between items can activate a boundary that disposes the list while the DOM
+	// clear still needs state.start.
+	const firstItem = state.head;
+	if (firstItem !== null && TEARDOWN_DEPTH === 0) {
+		TEARDOWN_HANDLER = findTryHandler(firstItem.parentBlock) ?? rendererRegionTryHandler(firstItem);
+		TEARDOWN_BLOCK = firstItem;
+	}
+	if (firstItem !== null) TEARDOWN_DEPTH++;
+	try {
+		for (let b: Block | null = firstItem; b !== null; b = b.nextSibling) {
+			if (b.cleanups !== null || b.children !== null || b._slots !== null) {
+				unmountBlock(b, false);
+			} else {
+				// Pure-host de-opt item (deoptItemBody with no component descendants):
+				// nothing to unmount scope-wise, but its subtree may carry stamped refs
+				// that must not keep pointing at the batch-removed DOM. Guarded so the
+				// common template-row clear stays a single null check; `deoptRefs`
+				// additionally skips the subtree scan for ref-free items.
+				if (b.deoptNode !== null && b.deoptRefs) detachDeoptTreeRefs(b.deoptNode, null);
+				b.disposed = true;
+				if (STAGED_COMMIT_CAPTURE) DEFERRED_LAYOUT_DRIVER!.retireHosts(b);
+				else b.retired = ++eventRootEpoch;
+			}
+		}
+		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 = '';
+			(STAGED_DOM?.view(p) ?? p).appendChild(state.start);
+			(STAGED_DOM?.view(p) ?? p).appendChild(state.end);
+		} else if (oldItems.size < RANGE_CLEAR_MIN_ITEMS) {
+			// Shared parent (other JSX interleaved) — detach the marker span directly.
+			// Each removal takes a whole item subtree, so this is one call per ITEM,
+			// not per node.
+			removeRange(getNextSibling(state.start), state.end);
+		} else if (STAGED_DOM !== null) {
+			STAGED_DOM.clearBetween(state.start, state.end);
 		} else {
-			// Pure-host de-opt item (deoptItemBody with no component descendants):
-			// nothing to unmount scope-wise, but its subtree may carry stamped refs
-			// that must not keep pointing at the batch-removed DOM. Guarded so the
-			// common template-row clear stays a single null check; `deoptRefs`
-			// additionally skips the subtree scan for ref-free items.
-			if (b.deoptNode !== null && b.deoptRefs) detachDeoptTreeRefs(b.deoptNode, null);
-			b.disposed = true;
-			if (STAGED_COMMIT_CAPTURE) DEFERRED_LAYOUT_DRIVER!.retireHosts(b);
-			else b.retired = ++eventRootEpoch;
+			// Large shared-parent clear — one bulk DOM call amortizes the Range setup.
+			const range = document.createRange();
+			range.setStartAfter(state.start);
+			range.setEndBefore(state.end);
+			range.deleteContents();
 		}
+	} finally {
+		if (firstItem !== null && --TEARDOWN_DEPTH === 0) dispatchTeardownErrors();
 	}
-	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 = '';
-		(STAGED_DOM?.view(p) ?? p).appendChild(state.start);
-		(STAGED_DOM?.view(p) ?? p).appendChild(state.end);
-	} else if (oldItems.size < RANGE_CLEAR_MIN_ITEMS) {
-		// Shared parent (other JSX interleaved) — detach the marker span directly.
-		// Each removal takes a whole item subtree, so this is one call per ITEM,
-		// not per node.
-		removeRange(getNextSibling(state.start), state.end);
-	} else if (STAGED_DOM !== null) {
-		STAGED_DOM.clearBetween(state.start, state.end);
-	} else {
-		// Large shared-parent clear — one bulk DOM call amortizes the Range setup.
-		const range = document.createRange();
-		range.setStartAfter(state.start);
-		range.setEndBefore(state.end);
-		range.deleteContents();
-	}
 	oldItems.clear();
 }

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

Reviewed by Cursor Bugbot for commit 46a8577. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
Since batchClearItems disposes items before clearing their DOM, each item's
unmountBlock was an outermost teardown that dispatched queued cleanup errors
on return. An ancestor @catch could then re-render and dispose the list while
the clear still wrote through state.start. Hold one teardown bracket across
the items and the DOM clear, as unmountBlock does for its own range, so errors
reach their boundary only after the list is cleared and its map emptied.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit d5030cf into main Oct 2, 2026
31 checks passed
@trueadm
trueadm deleted the fix/retired-event-hosts branch October 2, 2026 12:53
trueadm added a commit that referenced this pull request Oct 2, 2026
Take main's blur-during-teardown fixture from #1548 and format it, with the
fixtures main added, using @tsrx/prettier-plugin 0.5; each compiles to the
same output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 3, 2026
* fix(octane): retire a deletion's hosts before its cleanups run

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]>

* fix(octane): classify the focused-row climb and retire every portal teardown

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]>

* fix(octane): retire a non-parkable list clear's rows before any row's 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]>

* fix(octane): keep an interleaved independent portal live when its Fragment 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]>

* perf(octane): drop the blockless de-opt retirement hook

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]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Native blur runs against a disposed component during removal

1 participant