Repository navigation
fix(octane): commit custom host props before connecting the slot - #2085
domgan-oai wants to merge 11 commits into
Conversation
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
9 other measured values are unchanged. Public-import reachability bundles (bytes)
38 other measured values are unchanged. |
trueadm
left a comment
There was a problem hiding this comment.
Thanks. The direction fits next's rule that a render writes no committed DOM, and custom-element callbacks running at commit match React's timing. CI shows a real regression in this change, though, so it needs another pass before merging.
Failing on this head and green on next:
packages/octane/tests/focus-restoration.test.ts, "restores a focused native editor relocated by its host update at the 'first' / 'last' position", inoctaneandoctane-prod:expected [ 2, 4 ] to deeply equal [ 2, 9 ]. The focused input keeps focus but loses its selection range.packages/octane/tests/browser/mobile-input/mobile-input.test.ts, "restores a relocated native …", in real Chromium, on the same two orders ([2, 1, 3, 4]and[2, 3, 4, 1]).test (24)andCI provenancefail only because of the jobs above.
Why it's probably related. The fixture (tests/_fixtures/relocating-native-editor.ts) is a custom element whose attributeChangedCallback moves its own host into an external container when data-relocate goes 0 → 1, and the focus-restoration path brings it back. Deferring a custom host's props through DeoptOrder changes when that callback runs relative to the keyed move and its focus/selection snapshot. The restore now seems to run against a selection captured after the relocation (2–4), not before it (2–9). I haven't traced it to the exact line, so treat that as a hypothesis.
What I'd check:
- Does the deferral reach these hosts at all? The PR only intends newly created custom hosts in
reconcileDeoptNode. If existing relocating editors also take the deferred path, for example throughdesc = deoptRecord(...), that's the bug, and narrowing the condition to genuinely new elements would fix it. - If it's ordering: the deferred props op has to run where the old render-time write ran relative to
moveNativeNodeBefore's focus capture and restore. That could mean queueing it before the move, or making the restore capture the selection once per commit before any custom-host op. - Re-run
focus-restoration.test.tsand the browsermobile-inputsuite, plus your two newanchorless-hostcases.
Reviewed with Claude Code
trueadm
left a comment
There was a problem hiding this comment.
Thanks for the follow-up commits. Two things to confirm on the current head (0e26b42), where CI is still running:
-
Work counters. The last benchmark report on this PR (head 8b89b2f, run 38743397122) failed the js-framework gate with 8 increases, one extra call per mounted row:
- tsrx
calls_run/calls_replace/calls_addeach +1,000, andcalls_runlots+10,000; - the same four on jsx.
"skip absent custom-host receipts on list placement" looks aimed at exactly this. Please check that the new report puts every counter back at or below
next. The gate fails on any increase, and these rows have no custom hosts, so ordinary list placement shouldn't pay anything for this fix. - tsrx
-
Focus restoration. Earlier heads failed
focus-restoration.test.ts("restores a focused native editor relocated by its host update", with selection[2, 4]instead of[2, 9]) and the Chromiummobile-inputrelocation cases. Please confirm both suites pass on this head.
On size: the last report also showed roughly +70–110 B gzip on the full-surface bundles (shell_, full_fw, hydrate-frame). If the final number stays there, a note in the PR body on where those bytes go would help, since next is size-focused.
Reviewed with Claude Code
trueadm
left a comment
There was a problem hiding this comment.
Thanks. The work counters are back to next's on all 64, and the focus-restoration and mobile-input relocation cases pass, so both earlier concerns are resolved. The root-cause write-up (connectedCallback reading uninitialized attributes) is helpful.
The remaining blocker is size. By your own numbers this now costs about 990 B raw on the full-surface bundles:
- js-framework TSRX +108 B gzip and JSX +263 B;
- full framework +300 B, shell JS +261 B, hydrate-frame +299 B;
- bindings +341 B, Threadline +133–141 B, Pagecraft +294–322 B.
next is a size-focused branch, and this is paid by every app, including the large majority that never render a custom element, to handle a rare edge case: a custom element's setter unmounting the root during its first render.
Could the cost be made pay-for-use?
- Compiled templates: the compiler knows statically when a template contains a custom-element tag (a hyphenated name). The fresh-custom-host commit path (initial props before connect, the receipt, the interrupted-commit guard) could live behind a driver that only those templates install, the same way other optional features install their drivers. Shared slot and list commit paths would then test the driver by truthiness and fold away when it's absent.
- Descriptors / JSX: install the same driver lazily from the descriptor path when it first creates a hyphenated element, so a JSX app that never makes a custom element doesn't retain it either.
- Target: close to 0 B on apps without custom elements. If that can't be reached, please keep it under about 100 B gzip on those apps, and give the remaining cost per bundle.
The bundle gates you already have (no descriptor renderer or hydration in compiled-only roots) are a good model for a gate that keeps the custom-host path out of apps without custom elements.
Reviewed with Claude Code
trueadm
left a comment
There was a problem hiding this comment.
Thanks for the extra coverage. The two new anchorless-host cases (a compiled @if child and a plain createElement parent/child mounting into a retained section, each with an unmounting attribute callback) are useful evidence that initial props land before connectedCallback and that cancellation empties the root.
The blocker from the last review is still open, though. 729a875 changes tests only (git diff 31c7e68bb..729a875e6 touches just tests/_fixtures/anchorless-host.tsrx and tests/anchorless-host.test.ts), so the runtime cost is the same. The benchmark on this head (run 38752742759) shows it falling on apps that never create a custom element:
| bundle | raw | gzip |
|---|---|---|
js-framework TSRX (js_*) |
+408 | +134 |
js-framework JSX (js_*) |
+989 | +321 |
| todo / chat / weather TSRX | +408 | +133 / +140 / +133 |
| Threadline Oxc / esbuild | +408 / +414 | +130 / +135 |
| Pagecraft Oxc / esbuild | +990 / +1,010 | +294 / +281 |
| bindings / full_fw | +989 / +991 | +329 / +381 |
reachability: hooks-state, root-static-local, component-owned-effects |
+405–406 | +113–135 |
80 application values and 84 reachability values grew; none shrank. All 64 work counters are unchanged, which is good. The paired timings flag one slower op: TSRX add at +8.9% (95% CI +3.2% … +20.0%). It may be noise, but add goes through placeRun, which now reads frag.$$next and calls commitFrontierMembers on every run.
Why it isn't pay-for-use yet. The cost lands in two places:
-
Paid by everyone, about 408 B raw / 130 B gzip. These run unconditionally on shared commit paths that compiled-only apps already use:
runtime/engine.tsplaceRun: the(frag as any).$$nextread and thenext.writestest.runtime/commit.ts:- the
COMMITTING_GENERATIONchecks added toapplySlotNextand to every iteration ofapplyOutgoing; - the extra
nextparameter threaded throughapplyOutgoing→placeRoots; commitFrontierMembersitself.
- the
With no custom element anywhere, none of this does anything.
-
Paid by any descriptor or JSX app, a further ~580 B raw / ~190 B gzip. The
placementargument now threads through everyreconcileDeoptNode/reconcileDeoptChildrencall, along with theisHtmlCustomElementbranch, the frontier-search loop overparentBlockandforSlot.next, andqueueFrontierHost(runtime/deopt.ts,runtime/child-slots.ts).
What I'd need in order to approve:
- A driver for the frontier receipt. Move
commitFrontierMembers, the receipt grouping and the interrupted-commit generation checks behind a driver, sayCUSTOM_HOST_COMMIT, that the descriptor path installs the first time it creates a hyphenated element during a root render (and that a compiled template with a hyphenated tag installs at module init, if those need it). The shared paths then test it by truthiness:if (CUSTOM_HOST_COMMIT !== null && next.writes !== undefined) …. That lets compiled-only bundles fold all of it away. - No
placementon ordinary nodes. Rather than threadingplacementthrough everyreconcileDeoptNodecall, compute it only on the branch that has just created a custom element, since that branch already walksownerBlockfor the frontier. Then ordinary descriptor nodes pay nothing. - A bundle gate. Add one to the existing set, as you did for the descriptor renderer and hydration: a compiled-only root and a JSX root with no hyphenated tags must not contain
commitFrontierMembersorqueueFrontierHost. - Targets. About 0 B on the TSRX js-framework, todo/chat/weather and reachability rows, and under about 100 B gzip on JSX/descriptor bundles without custom elements, with the remaining per-bundle cost listed in the PR body.
CI. website integration suite failed on this head in website/tests/ssr-hydration.e2e.test.ts ("/devtools never showed the TanStack Devtools trigger"). The page errors are Vite 504 (Outdated Optimize Dep) for node_modules/.vite/deps/RVI7YCPX-*.js, which looks like a dep-optimizer race rather than this change; test (24) and CI provenance fail only as its rollups. Please rerun it with the next push.
The correctness direction (props before connect, committing at the actual frontier, revoking the rest of the commit after a reentrant unmount) still looks right to me. This is purely about who pays for it.
Reviewed with Claude Code
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Reviewed by Cursor Bugbot for commit 171ee7d. Configure here.
|
@trueadm Following up on your size review: the current head is This is not fully pay-for-use: the placement argument still passes through descriptor reconciliation, some shared placement checks remain, and root-generation cancellation stays general because ordinary cleanup can replace a root. The current-head benchmark reports full JS gzip at +96 B TSRX and +160 B JSX (Oxc), Threadline +93 B Oxc / +87 B esbuild, and Pagecraft +323 B with both. Pagecraft retains the writer through a genuinely dynamic public All 64 work counters are unchanged. The report did not flag any timing at its ±3% decision threshold, but JSX update and remove had slower intervals, so I cannot claim unchanged performance. The current-head CI run passed, including the website and Chromium suites; all 30 PR checks are green. The website case now waits for its client effect rather than network idle, while keeping the router event and DOM identity assertions. |

Summary
A fresh custom element created by a host descriptor could connect after its initial setter synchronously unmounted the root, or connect before its initial attributes were visible. Prepare the initial props during render and apply them at commit immediately before the exact fragment or compiled single-host row connects, after outgoing deletion cleanup. Replacing or disposing the root cancels the rest of that commit. A caught render can leave an abandoned host's queued order behind, so commit clears the matching order and skips it if its owner was disposed.
The compiler enables this handling for literal custom tags and tags that can be dynamic. Proven native tags, immutable local function components and Octane boundaries do not enable it; public element factories remain conservative. Each fresh fragment or row owns its own receipt, so ordinary list rows make no additional callback calls. The root-generation check remains general because ordinary cleanup callbacks can also replace a root.
Validation
connectedCallback, reentrant unmount/root replacement, async abort/retry with retained native input identity and draft, and a caught render that discards one custom host while another commits. The latter failed in both development and production before the disposed-owner check; 212 targeted tests passed after it.82d615210(30 alternating pairs, fixed base and production builds): all 64 work metrics were identical. TSRX selection sampled +2.3% (95% CI +1.2% to +4.0%); the other 19 timing intervals included parity. The final discarded-owner check adds a descriptor-commit branch, so this pre-fix comparison does not establish final-head timing.Whole production JavaScript, gzip level 9; every emitted JS asset is counted. Each three-way comparison uses frozen source snapshots and the same fixture/dependency/toolchain within that row, with source-map provenance checked. Baseline is fixed
nextee7d52073, previous is82d615210, and current production source is38fce06e4(unchanged in9739a18a0; its only later change is the website test).The hosted benchmark separately compared the current PR merge against
next5370a3161: JS Framework Oxc TSRX +96 B and JSX +160 B; Threadline Oxc +93 B / esbuild +87 B; Pagecraft Oxc +323 B / esbuild +323 B. Bindings grew +391 B, Wayfinder +162 B, Todo +95 B, Chat +90 B, and Weather +94 B. Its baseline and toolchain differ from the controlled local table.The requested ~100 B ceiling is still exceeded by JSX and Pagecraft. Pagecraft's Lexical integration calls public
createElement(props.ErrorBoundary, ...), whose runtime value can be a host, so it conservatively retains the writer. General cancellation and connection-point checks remain shared correctness costs. The reachability gate proves Oxc exclusion for its measured fixtures, not esbuild exclusion or zero cost for every application.Origin: Codex task · host
com-79386Need help on this PR? Tag
@codesmith-botwith what you need.Note
High Risk
Changes core commit/deopt timing for custom elements and root-generation cancellation during DOM insertion—easy to regress hydration, lists, and reentrant unmount behavior.
Overview
Fixes custom-element host descriptors so initial attributes and props are applied at commit time immediately before the host is inserted, instead of while the node is still off-document. That way
connectedCallbacksees the right initial state, and a setter that synchronously unmounts or replaces the root does not leave a stale host connected afterward.Adds an opt-in
enableDescriptorCustomHostspath (descriptorCustomHosts/prepareFrontierHostwith$$initialHostsreceipts on slot frontiers, list runs, andplaceRoots). Commit now bails out when the committing root’s generation changes or a disposed owner abandons a queued order. The compiler turns the capability on for dynamic or custom tags (and spreads); proven native tags and immutable components can omit it from bundles.Tests and benchmarks add anchorless-host custom-element scenarios, compiler capability coverage, and minimal JSX fixtures that prove the
queueFrontierHostwriter is dropped or retained via the bundle reachability gate. The SSR hydration e2e waits on the homepage effect log instead of a fixed post–network-idle delay before the first router event.Reviewed by Cursor Bugbot for commit 9739a18. Bugbot is set up for automated code reviews on this repo. Configure here.