Repository navigation
fix(octane): retire value-hole hosts when their removal dispatches focusout - #1549
Conversation
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]>
…cusout
A pure host in a value hole, such as `{show && <div onBlur={…}><input /></div>}`,
has no Block of its own: the live Block that rendered it stays mounted when
the hole removes it. Chromium dispatches focusout synchronously during that
removal, so the removed host's handler still ran.
Every Block-less de-opt removal already calls detachDeoptTreeRefs just before
detaching the node. Its teardown entry now stamps the removed root with a new
event epoch. While a stamp from the current task exists, snapshotDelegatedSlots
skips handlers at or below the outermost stamped path node whose stamp is no
newer than the delivery. A component-bearing host whose tag changes retires
its old element before its children leave it. View Transition captures stage
the stamp with the removal, and a delivery already in flight keeps its route.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
|
Base update:
The change keeps #1548 within the vt-effect-cleanup call budget and the root-chained-jsx byte budget. root-chained-jsx is now 85,641 raw / 28,379 gzip against 85,728 / 28,384, so this residual's bytes may need trimming or a budget update. 🤖 Posted by Claude Code |
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]>
…/octane into fix/retired-value-hole-hosts # Conflicts: # packages/octane/src/runtime.ts
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]>
|
Follow-up: #1548 head is now 46a8577, merged with main 3f1a7b2.
🤖 Posted by Claude Code |
Stage removed host roots through the deferred-layout driver, batched into one action per capture like retireEventHosts, so the staging code ships only with ViewTransition. Inline the path scan into snapshotDelegatedSlots and drop the element check: only the root of a removed subtree is stamped, and text nodes never appear on an event path. Behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
…/octane into fix/retired-value-hole-hosts # Conflicts: # packages/octane/src/runtime.ts
…e-hosts # Conflicts: # docs/differences-from-react.md # packages/octane/src/runtime.ts # packages/octane/tests/browser/retired-event-hosts/retired-event-hosts.test.ts
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)
All 20 timed operations (19 within noise)
Application bundle size (bytes)
7 other measured values are unchanged. Public-import reachability bundles (bytes)
35 other measured values are unchanged. CI job durations
Compares the CI run for
All 26 timed jobs
|
…irement `root.render(<JSX/>)` links both the de-opt removal paths and the delegated dispatcher, so this fixture carries the value-hole host retirement even though it renders no handlers. Against main (85,641 / 28,399 / 25,258), it adds +292 raw / +95 gzip / +48 brotli bytes. Trimming moved the ViewTransition staging into the deferred-layout driver, and the rest cannot shrink without per-event dispatch cost. Raise the ceilings by whole 32-byte steps to 85,952 / 28,512 / 25,312; every other budget is unchanged. 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]>
* 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]>
Summary
Follows #1548 (the #1472 fix, now merged), which skips hosts whose rendering Block retired before a native delivery began. This PR closes its residual gap: a host rendered into a value hole has no Block of its own, so the hole can remove it while the Block that rendered it stays live.
With focus in the input, setting
showtofalsemade Chromium dispatchfocusoutwhile the hole was removing thediv, anddroppedran. React runs no handler during its commit. After this PR the removed host starts no handler,parentstill receives the event, and a delivery that began before the removal keeps its route, as in #1472.Why
#1472 retires hosts through their owning Block (
retireEventOwner). Pure de-opt hosts (createElementoutput in a value hole, nestedcreateElementchildren, a root that renders a descriptor) claim the live parent Block, so nothing retired them. Ternary holes compile toifBlockand were already covered.Changes
detachDeoptTreeRefs(node, null)is the teardown hook that every Block-less de-opt removal already calls right before detaching the node, both directly and in root-transaction commit callbacks. It now callsretireEventHostTree(node), which stamps the removed root's$$retiredEpochwith a new event epoch. No removal site changes, and nothing changes at mount. Under a View Transition capture the deferred-layout driver'sretireHostTreequeues one action per capture that stamps every removed root before the DOM removals queued after it, matching fix(octane): skip retired hosts when removal dispatches focusout #1548'sretireHosts, so that code ships only with ViewTransition.snapshotDelegatedSlotsskips handlers at or below the outermost stamped path node whose stamp is no newer than the delivery's epoch.retiringHostsSincelimits that scan to the task in which a removal happened; onequeueMicrotaskcloses it. Idle dispatch pays one global read; the scan is inlined.hostElementBody(a host with component children whose tag changes) keeps its Block, and its children leave the old element before the element does. It now retires that element first. In a root transaction this runs as the first commit action.docs/differences-from-react.md: the Native blur runs against a disposed component during removal #1472 bullet now covers removed hosts as well as hosts of unmounted components.benchmarks/bundle-size/minimal-budgets.json: root-chained-jsx raised (see Risk).octanepatch.Validation
pnpm format:check(scopedformat:files:checkon the changed files passes)pnpm typecheck(scopedtypecheck:fileson the changed files passes)pnpm test(see below)targeted tests:
tests/browser/retired-event-hosts(Chromium): 50/50, dev and prod. The 14 new scenarios cover a value-hole host,<input onBlur>as the removed root, a nested de-opt child, a tag swap, a component-bearing tag swap, a component-bearing hole, mapped de-opt rows, root descriptor replacement, removal by the owner's state update, View Transition publication (host live before publish, skipped at publish), and two in-flight controls (bubble snapshot, capture-phase removal). Five of the shapes, ten tests across dev and prod, ran the dropped handler before this change.hostElementBodybranch, the staged stamp, the scan window, ancestor propagation, or the delivery-epoch comparison each turns at least one scenario red.tests/browser/event-metadata(including "keeps a removed portal route through the end of its native dispatch"),portal-events,retired-event-hosts(jsdom),discrete-flush-reentrancy,stable-event-authority(octane + octane-prod): all pass.octane,octane-prod, andoctane-events-browserrun, while other worktrees were also running suites (load average about 58), had timeout failures. Each failing file passed when re-run alone with a longer timeout, exceptbehavior-root.test.ts, which timed out on the Native blur runs against a disposed component during removal #1472 baseline as well. With a 60 s timeout its retirement-cleanup tests pass in the same 1.5–2.3 s as onmain.Performance: the Native blur runs against a disposed component during removal #1472 runtime and this change were loaded into one Chromium page and alternated, 60 rounds per workload, in both load orders. A run with the baseline loaded twice stayed within ±2%.
createElement('ul', null, rows), 1000 rows mount + clearThe stamp alone measures about 20 ns per removed de-opt root, which shows only when many de-opt siblings leave together.
node benchmarks/view-transitions/effect-cleanup.mjs: every case is at or below its committed call budget; de-opt rows here are Block-owned, so the hook adds no call per removed row.PR benchmark report (CI, ca2b1d7 vs
main95421bb): all 20 js-framework timed operations are within noise. Every application and reachability bundle grows by the same code, +292 raw bytes (about +0.2%; for example octane-tsrxjs_gzip+102 and octane-jsxjs_gzip+135).node benchmarks/bundle-size/run-minimal.mjs --budgets root-static-local root-chained-jsx hooks-state prop-attributes context(the CI step) passes with the raised budget. Againstmain203be41 (85,641 / 28,399 / 25,258 raw/gzip/brotli), root-chained-jsx measures 85,933 / 28,494 / 25,306, which is +292 / +95 / +48. The other four scenarios are unchanged and within their budgets.Risk / follow-ups
root.render(<JSX/>), which links the de-opt removal paths and the delegated dispatcher, so this fix's code is reachable there even though the fixture has no handlers. After trimming, the rest can't shrink without per-event dispatch cost. With maintainer approval, this PR raises that budget by whole 32-byte steps to 85,952 / 28,512 / 25,312 (from 85,728 / 28,416 / 25,280), leaving 19 / 18 / 6 bytes of headroom. No other budget changes.hostElementBodychange has no scenario: every root and state-driven render runs inside a root transaction. It mirrors that function's existing synchronousdetach()branch.hostElementBody's child-first teardown and hydration'sreplaceChildrenafter hooking each child.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes core delegated event dispatch during synchronous DOM removal and focusout; behavior is broad but heavily browser-tested, with a small bundle-size increase on a chained-JSX budget.
Overview
Extends the #1472 retired-host event fix so DOM hosts removed without disposing their renderer (value holes like
{show && <div onBlur={…}>…</div>}, nestedcreateElement, tag swaps, root descriptor replacement, and View Transition–staged removals) no longer run delegated handlers forfocusoutfired while the node is being torn down.The runtime stamps removed subtree roots with
$$retiredEpochviaretireEventHostTree(hooked from blockless de-opt teardown and host tag replacement), queues batched stamps under staged commits likeretireHosts, andsnapshotDelegatedSlotssuppresses handlers at or below the outermost stamped node on the capture path for the current delivery. In-flight dispatches that already captured handlers still run through to the end; mounted ancestors keep receiving the event.Docs and a patch changeset describe the behavior;
root-chained-jsxminimal bundle budgets are bumped slightly. Chromium Playwright coverage adds many de-opt/value-hole scenarios (including view transitions and capture-phase removal).Reviewed by Cursor Bugbot for commit 073f7bc. Bugbot is set up for automated code reviews on this repo. Configure here.