Repository navigation
fix(hydration): replace exactly the server node at a component hole in another arm's adopted nodes - #1603
Merged
Conversation
…n another arm's adopted nodes When the server rendered another @if/@switch arm whose static roots match the client arm's, the client adopts the server arm's nodes through its template, and the server node at a component call's <!> hole is an element of the other arm rather than the component's range. - HydrationCapability.slotCursor: an element or text anchor is the server node at the call's position; the cursor moves to it and the call's first render remembers it (positional). renderInPlace drops the rebuilt tail for it, and renderUnframed discards only that node. - Lite (development compile) calls: a positional call whose callee is not stamped $$singleRoot renders unframed in that node's place (mountUnframedLite with an anchor) instead of in place, where a body of several roots, a fragment, or nothing lost the adopted node after the hole or left the stale element on screen. - adopt()'s single-root mismatch guard compares the cursor's parent with CURRENT_SCOPE.block.parentNode, the parent commitBag inserts into, which for a lite component is its host rather than CURRENT_BLOCK's parent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n-d5d423 # Conflicts: # packages/octane/src/runtime.ts
…n-d5d423 # Conflicts: # packages/octane/src/runtime.ts
trueadm
marked this pull request as ready for review
October 2, 2026 20:07
…n-d5d423 # Conflicts: # packages/octane/src/runtime.ts
2 of 5 tasks
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)
99 other measured values are unchanged. |
The benchmark report showed +65 raw bytes in every bundle with a component slot, including ones that never hydrate (root-static, context, js-framework), because componentSlotImpl resolved the positional anchor inline. Resolve it when renderUnframed settles the claim instead: an element or text anchor that is not the claiming block's end marker is the server node at the call's position, so the discard starts there and stops after it. Non-hydrating bundles are unchanged from main; hydrate-root and deferred-hydration grow by 81 raw bytes. The lite helper passes the node as the claim's anchor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n-d5d423 # Conflicts: # packages/octane/src/runtime.ts
This was referenced Oct 2, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the server rendered another
@if/@switcharm whose static roots match the client arm's, the client adopts the server arm's nodes through its template. The server node at a component call's<!>hole is then an element of the other arm, not the component's<!--[-->range. Main already renders a single-root call in place of that node (#1602). This PR fixes the calls that cannot render in place of a single server node, in both compiles:KeyedLastcase).HydrationCapability.renderUnframed: when a claim's anchor is an element or text node and not the claiming block's end marker, that anchor is the server node at the call's position. The discard starts at the anchor, whatever node the cursor rests on, and stops right after it, because the template claims the nodes that follow. Doing this when the claim settles, rather than inline incomponentSlotImpl, keeps it out of bundles that never hydrate. It composes with fix(hydration): adopt an unframed fragment component and continue after its last root #1597: the in-place adoption thatrenderUnframednow attempts also uses that node, so a matching body adopts it, and a mismatching one discards only it.renderLiteInPlacerendered such a call in place withLiteBlockImpl.endMarkerset to the server element, which only works for a single-root body:<i>after the hole.$$singleRootstamp now mounts unframed (mountUnframedLite, with that node as the claim's anchor), matchingcomponentSlotImpl. The branch is in the cold helper, so ordinary lite dispatch is unchanged.Earlier revisions of this PR carried a
slotCursor/positionaldesign and anadopt()guard change. Main's #1593, #1584 and #1602 superseded both, and the merge now takes main's versions. The PR's diff against main is a smallruntime.tschange, two test files with fixtures, and one changeset.Validation
pnpm format:check(not run;pnpm format:files:checkis clean on the changed files)pnpm typecheck(not run;pnpm typecheck:filesis clean onruntime.ts, both tests and both.tsrxfixtures)pnpm test(not run in full)arm-component-hole.test.tsandarm-lite-hole.test.ts: dev/prod compile × dev/prod runtime (vi.stubEnv('NODE_ENV', 'production')).renderUnframedpositional branch removed (24 failures across both files and all modes);$$singleRootcheck removed, which breaks the single-root adoption cases;root === anchorcheck removed, which breaks fix(hydration): adopt a component hole's own server node in a template adopted in place #1602'sin-place-fragment-holeand the existing EmptyFirstArm test.packages/octane/tests/hydration/passes inoctaneandoctane-prod: 280 file runs, 13,364 tests.Risk / follow-ups
An unstamped single-root lite callee at a positional hole now rebuilds (recoverable error 55) instead of adopting a matching server node. Prod already does the same for calls it cannot prove single-root.
The
renderUnframedchange applies to every anchored claim at an element or text node, not only in@ifarms. The full hydration directory covers that in both projects.No test covers two of its guards:
Bundle (
run-minimal.mjs, against main at 3ec43da):The first version of this fix added +65 raw to every component-slot bundle, as the bot's report showed.
hydrate-rootwas already over its committed budget on main.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches core hydration DOM adoption/discard logic in
runtime.ts; behavior changes for all anchored unframed claims at element/text nodes, though the hydration suite is expanded to cover it.Overview
Fixes client hydration when an
@if/@switcharm reuses the server’s other arm’s static DOM but places a component call in a template hole where the server left that arm’s own element (not a<!--[-->component range).HydrationCapability.renderUnframednow treats a claim anchored on an element/text node (the hole’s walk result, not the block end marker) as positional: discard starts at that node regardless of cursor position, so keyed/dynamic/multi-root/empty calls replace only the mismatched server node and do not delete adopted siblings before/after the hole.renderLiteInPlaceroutes the same positional-hole case for dev-compile lite calls that are not stamped$$singleRootthroughmountUnframedLiteinstead of in-place lite rendering, which previously corrupted multi-root, fragment, or empty bodies and could rebuild over adopted nodes.Adds
arm-component-holeandarm-lite-holefixtures/tests (dev/prod compile × runtime), asserting DOM cleanup, singleonRecoverableErrorreports, and stable updates when switching arms. Patch changeset foroctane.Reviewed by Cursor Bugbot for commit 7a8b67e. Bugbot is set up for automated code reviews on this repo. Configure here.