Repository navigation
fix(hydration): keep a rebuilt clone where the server node it replaced stood - #1561
Conversation
…d stood When a component's template root did not match the server node at the cursor, hydration discarded that node and rebuilt the root, but inserted it at its range end. Server siblings that later client siblings adopted ended up before it, unclaimed server content after it stayed on the page, a @switch the server did not render published empty markers after it, and a text hole after it threw NotFoundError. A Suspense boundary resuming after the rebuild read the misordered DOM as server output, reported two false mismatches, and rebuilt the adopted sibling. The rebuilt root now goes before the server node that followed the one it replaced. An adopted @if/@switch arm quietly removes the rest of that server content when nothing claimed it. Unframed single roots step the cursor past a root they adopt and find a root rebuilt in the cursor's place. A markerless branch that hydrates without a server range takes its bounds from the cursor, and initial Suspense hydration attempts share the set of client-built nodes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)
7 other measured values are unchanged. Public-import reachability bundles (bytes)
37 other measured values are unchanged. |
…kerless arm throws A hydrating @switch/@if arm with no server range that adopted the server node at the cursor and then suspended published an empty marker pair before that node. The boundary's next attempt then read those markers as server output and rebuilt the node instead of adopting it. Such an arm now finalizes on a throw only when it rebuilt a root in the cursor's place, and otherwise leaves the DOM as it was. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ition Keep both sides in renderInitialSuspenseHydration: the attempt's capability is speculative (#1544) and shares the set of client-built nodes across attempts. Adapt the rebuilt-tail sweep to main's root hydration journal: save() the parent before removing the tail, and sweep only while the rebuilt root still stands right before it, so a rolled-back attempt's stale tail is never swept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
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: Markerless retry keeps stale bounds
- Changed
state.markerlessBefore = beforetostate.markerlessBefore = contentBeforeso that same-branch retry and branch-change abort paths use the cursor-adjusted content start instead of the static positional anchor.
- Changed
Or push these changes by commenting:
@cursor push 631049b2aa
Preview (631049b2aa)
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
@@ -41897,7 +41897,7 @@
env,
);
state.block = b;
- state.markerlessBefore = before;
+ state.markerlessBefore = contentBefore;
try {
renderBlock(b);
} catch (error) {You can send follow-ups to the cloud agent here.
…opted A deferred boundary retries a suspended activation through the same blocks. A hydrating @switch/@if arm with no server range that adopted the server node at the cursor, then suspended, was finalized on that retry from its static anchors. It published empty markers after the server siblings that later client siblings adopt. The next sibling then rebuilt its root and logged a false mismatch, and a later case change left the adopted node on the page. On such a throw the arm now records the cursor's bounds for a same-block retry, and leaves the DOM unchanged for a new attempt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…opted A hydrating @switch/@if arm with no server range that suspended with the cursor still on its element recorded that element's next sibling, a node a later sibling owns, as its end. A deferred boundary's retry could discard that node first, so finalizing the arm threw NotFoundError. The arm now self-marks the element instead. That adds no DOM, so a new attempt still adopts the element, while a same-block retry or a branch change finds the arm in place. A markerless slot that swaps branches while hydrating, such as a case change before a deferred boundary activates, now mounts the new branch as client DOM and moves the cursor past the old one. Before this, the next sibling adopted from a removed node and was rebuilt with a false mismatch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ition #1560 rolls back a speculative Suspense attempt's structural recovery, so a suspended attempt's rebuilt root no longer survives into the next attempt. Take main's InitialSuspenseHydration.stale, and drop this branch's set of client-built nodes shared across attempts, which is now unused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s arm fixes Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.
Autofix Details
Bugbot Autofix prepared fixes for all 3 issues found in the latest run.
- ✅ Fixed: Unframed root stamps leftover cursor
- Added
!isBlockClose(hydrationCursor)guard so that when clone() returns a fresh root without removing a close marker cursor, the finally block falls through to the freshAfter branch that correctly detects the rebuilt root.
- Added
- ✅ Fixed: Self-mark remount can throw NotFoundError
- Added a parentNode check in rebuiltPosition so that when endMarker has been detached by discardCursor during a retry, the method returns null instead of the dangling reference, preventing NotFoundError in insertBefore.
- ✅ Fixed: Abort start uses the wrong sibling
- Changed
state.markerlessBefore = beforetostate.markerlessBefore = contentBeforeso the abort sweep starts from the cursor's previousSibling (where content actually begins) instead of after's previousSibling, ensuring adopted prefixes are covered.
- Changed
Or push these changes by commenting:
@cursor push 5bdf044701
Preview (5bdf044701)
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
@@ -19896,9 +19896,9 @@
*/
rebuiltPosition(root: Node, parent: Node, end: Node | null): Node | null {
const next = this.rebuiltTail;
- return root === this.rebuiltRoot && next !== null && domNode(next).parentNode === parent
- ? next
- : end;
+ if (root === this.rebuiltRoot && next !== null && domNode(next).parentNode === parent)
+ return next;
+ return end !== null && (STAGED_DOM?.view(end) ?? end).parentNode !== parent ? null : end;
}
/**
@@ -31768,7 +31768,8 @@
if (
hydration !== null &&
hydrationCursor !== null &&
- (STAGED_DOM?.view(hydrationCursor) ?? hydrationCursor).parentNode === domParent
+ (STAGED_DOM?.view(hydrationCursor) ?? hydrationCursor).parentNode === domParent &&
+ !isBlockClose(hydrationCursor)
) {
// An unframed single-root return adopts the element that was already
// present, so the client-mount before/after probe cannot observe an
@@ -41953,7 +41954,7 @@
env,
);
state.block = b;
- state.markerlessBefore = before;
+ state.markerlessBefore = contentBefore;
try {
if (replacing) hydration!.suspend(() => renderBlock(b));
else renderBlock(b);You can send follow-ups to the cloud agent here.
… marker A component with no server frame whose cursor was the enclosing range's closing marker, such as a client sibling the server range lacked, stamped that marker as its own boundary. The root built at the range's end was not the boundary, so an HMR handoff declined the update. The block now takes a root rebuilt in the cursor's place first, then one built at its anchor, and a node it adopted in place only otherwise, never a closing marker. Remove this branch's deferred same-block retry handling for a markerless arm. The arm self-marked the element at the cursor when it suspended, and a markerless swap mounted under suspended hydration. Self-marking a node the arm had not adopted could throw NotFoundError when a retry discarded it. Text cursors and arms with more than one root still fell back to static bounds. Those paths return to main's behavior, which a follow-up addresses as a whole. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The signal-free root-chained-jsx bundle went 11 raw bytes over its committed budget, all of it from commitBag's ternary around rebuiltPosition. rebuiltAt returns undefined unless a rebuilt root has a recorded position, so commitBag inserts at `hydration?.rebuiltAt(root, parent) ?? block.endMarker`, 5 raw bytes over main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…built-clone-position # Conflicts: # packages/octane/src/runtime.ts
…ition Keep both sweeps after an adopted @if/@switch arm renders. This branch's sweepRebuiltTail runs first: the server content a rebuilt root left after it is the rest of what that root's mismatch replaced, and it goes quietly under that one report. #1564's discardArmTail then reports any other server range the arm left unclaimed. rebuilt-clone-blocks' ForeignListBranch therefore expects one diagnostic, not two, and both foreign tails are now asserted removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
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: Lite adopt leaves hydration cursor parked
- Added a rebuiltOpen variable to track the adopted server node in the rebuiltTail branch, then advance the hydration cursor past it after the body renders when clone() left it parked there, mirroring componentSlotImpl's stepPastRoot advance for full unframed single-root components.
Or push these changes by commenting:
@cursor push 0e5adf7600
Preview (0e5adf7600)
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
@@ -11660,6 +11660,9 @@
// The server node an anchorless call found where its range belonged (first
// hydration render only); undefined when it claimed a range or none.
let unframed: Node | null | undefined;
+ // The unframed server node a rebuilt root left at the cursor (first
+ // hydration render only) — consumed by the post-body cursor advance.
+ let rebuiltOpen: Node | null = null;
if (scope === undefined) {
scope = new ScopeImpl(parentScope, parentScope.block);
// Lite scope's `block` exposes the host/anchor as the body's DOM context
@@ -11704,6 +11707,7 @@
} else if (open === hydration.rebuiltTail) {
// The body may adopt this unframed server node as its root.
hydration.rebuiltTail = null;
+ rebuiltOpen = open;
}
}
scope.block = new LiteBlockImpl(host, endMarker, parentScope.block) as unknown as Block;
@@ -11775,6 +11779,8 @@
// its commitBag insert MOVES the previous sibling's root to the shared
// anchor. Mirrors componentSlot's post-render advance.
if (hydration !== null && adoptedClose !== null) hydration.node = getNextSibling(adoptedClose);
+ else if (hydration !== null && rebuiltOpen !== null && hydration.node === rebuiltOpen)
+ hydration.node = getNextSibling(rebuiltOpen);
}
// An anchorless lite call whose server range is missing: render it betweenYou can send follow-ups to the cloud agent here.
…commits
When a template root did not match the server node at the cursor, adopt()
removed that node as soon as it built the replacement. If the replacement
suspended before commitBag, the server content vanished while it waited,
and a deferred <Hydrate split={false}> boundary retried the arm from the
next server sibling. The retry mismatched that sibling's range, reported a
second mismatch and rebuilt it.
adopt() now steps past the mismatched node and records it; rebuiltAt
removes it when the rebuilt root commits, before inserting the root in its
place (a Document holds one element). A suspended deferred activation
resumes at the pending node (resumeAt), and a retry over it is not reported
again. A markerless arm that throws with its replacement pending is bounded
by a client marker pair around the node, so a retry puts its root there
and a case change removes the node with the arm; while hydrating, a swap
into a client-minted pair builds the new arm as client DOM.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ition #1567's renderInPlace steps the cursor past a node that an unframed component adopted in place, in both the lite and the singleRoot paths. It supersedes this branch's stepPastRoot and its lite-path rebuiltTail clear: an adopted node no longer leaves the cursor on the rebuilt tail, so the sweep cannot take it. The singleRoot boundary stamps the cursor only when the body adopted it or threw (#1567), no root was rebuilt in its place, and it is not a closing marker. The fallback still finds a root rebuilt in the cursor's place before probing the anchor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A hydrating @switch/@if arm with no server range of its own can adopt the server element at the cursor in place. A component inside that element leaves the cursor in it, or past its last child. markerlessEnd then fell back to the slot's static anchor, so the arm's range took in the server siblings after it, and a case change removed their DOM. When the cursor is not left in the arm's parent, the content now ends after the element it started at, while that element is still there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ition # Conflicts: # packages/octane/src/runtime.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Suspended rebuild stamps a doomed boundary
- In commitBag, after rebuiltAt removes the server node that was stamped as the block boundary, the block markers are now updated to point to the committed rebuilt root so subsequent unmounts and swaps correctly find the live DOM.
Or push these changes by commenting:
@cursor push eede0ad94c
Preview (eede0ad94c)
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
@@ -20892,10 +20892,20 @@
// which stays until now.
if (hydration === null || (STAGED_DOM?.view(root) ?? root).parentNode !== block.parentNode) {
const parent = block.parentNode;
- (STAGED_DOM?.view(parent) ?? parent).insertBefore(
- root,
- hydration?.rebuiltAt(root, parent) ?? block.endMarker,
- );
+ const at = hydration?.rebuiltAt(root, parent);
+ (STAGED_DOM?.view(parent) ?? parent).insertBefore(root, at ?? block.endMarker);
+ // rebuiltAt removed the server node the block stamped as its boundary
+ // (an unframed singleRoot that suspended before this commit). Update
+ // the markers to the root that replaced it so a later unmount or swap
+ // finds the live node.
+ if (
+ at !== undefined &&
+ block.startMarker != null &&
+ (STAGED_DOM?.view(block.startMarker) ?? block.startMarker).parentNode === null
+ ) {
+ block.startMarker = root;
+ block.endMarker = root;
+ }
}
}
scope.slots[0] = bag;You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 9ba872a. Configure here.
…undary An unframed singleRoot whose body rebuilt over the server node at the cursor and then suspended before its root committed stamped that node as its block boundary. The server node stays in place until the rebuilt root commits, and that commit removes it, which left the block's markers detached for a later identity change, return-shape switch or HMR remount. The probe now skips a node a not-yet-committed rebuilt root replaces, as the markerless arm already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Bugbot Autofix prepared fixes for both issues found in the latest run.
Or push these changes by commenting: Preview (820abeba7e)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
@@ -42306,7 +42306,8 @@
state.block = b;
state.markerlessBefore = before;
try {
- renderBlock(b);
+ if (cursor !== null) hydration!.renderInPlace(renderBlock, b, cursor);
+ else renderBlock(b);
} catch (error) {
// A branch that throws before inserting anything stays unfinalized so
// a same-branch retry finalizes it. One that already inserted its
@@ -42392,6 +42393,8 @@
state.block.body = body!;
state.block.extra = env;
renderBlock(state.block);
+ if (hydration !== null && hydration.rebuiltTail !== null)
+ hydration.sweepRebuiltTail(state.block.endMarker);
const markerlessBefore = state.markerlessBefore;
if (markerlessBefore !== undefined) {
finalizeMarkerlessBranch(You can send follow-ups to the cloud agent here. |
…without one is built (#1589) * fix(hydration): keep a later sibling's server range when a component without one is built A component call that finds no server range of its own renders between fresh markers, then hydration discards the server nodes in its place. The discard ran until a block close, so it consumed a later sibling call's range open marker and content and stopped at that range's close, which stayed behind as a stray marker. The sibling then rebuilt its server content without a report of its own. The discard now stops at any block marker or client-built node, leaving a later range for the sibling call that claims it. The fresh markers go where the discarded nodes stood (HydrationCapability.unframedBefore) rather than at the parent range's end, so the built component stays ahead of siblings that adopt their server ranges. componentSlot and the anchorless lite path both use it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(octane): rewrap the renderUnframed comment Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Te3NJRzy6R5Vkkc7KuJvys * fix(hydration): rename the unframed sweep predicate after merging main #1561 added a public HydrationCapability.replaces(node) for rebuilt roots. The merge kept both methods, so the later definition overrode the unframed sweep's private replaces(node, anchor). Name the sweep's predicate unframedReplaces. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Te3NJRzy6R5Vkkc7KuJvys --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Resolve runtime.ts against #1561, #1567 and #1576: keep main's adopted-range claims (renderClaimed) and in-place lite rendering (renderInPlace) beside the unframed-claim changes. #1567 renders a lite call that found no range against the cursor, so a hookless component that renders nothing leaves the server element to the next call. Drop this branch's routing of such calls through the missing-range path, which contradicted that. Fix the over-sweep where it happens instead: when such a call rebuilds its fragment, placeRebuilt now discards only the server content in its place, up to the next marker, and drainFrag inserts the fragment there, ahead of later siblings' ranges. The development diagnostic names the call site. renderUnframed shares the same bounded sweep (discardInPlace). The fixture's FragChild gets a hook so it is a full component call in both compiles, which is the path that case covers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LqA51dmsggKyu7uH3zc9N2
…ement in place (#1594) * test(hydration): cover a full component slot rebuilt over a server element in place A single-root call that renders through the full component slot (a hooked component, or in a production compile a call whose output reads only constants) and finds no server range of its own renders its template against the server element at the cursor. Before #1561, a mismatch there discarded that element while it was still the block's insert anchor, so commitBag threw NotFoundError and hydrateRoot left the container blank. Pin the recovered behavior in development compile, production compile, and production compile and runtime: the root is rebuilt in the server element's place, its server siblings stay adopted, the mismatch is reported once, and the arm unmounts, remounts and unmounts cleanly afterwards. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(hydration): run the constant-output in-place rebuild in a development compile too #1593 discards a mismatched node inside a lite component's host, so the development compile's lite call over the server `<u>` now rebuilds in place like the full component slot does. Cover it in all three modes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(hydration): say the lite slot's in-place rebuild is covered too The constant-output case's note read as if a development compile were left out. It runs in all three modes since #1593: say so. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>


Summary
When a component's template root doesn't match the server node at the hydration cursor,
HydrationCapability.adoptreports the mismatch, discards that node, and rebuilds the root.commitBagthen inserted the rebuilt root before its block's end marker. Several symptoms followed, in dev and prod:<em>e</em><i>ok</i>was rendered instead of<i>ok</i><em>e</em>.@switchthe server didn't render: it computed its range from the static anchor. It published empty markers after the rebuilt root, and the root stayed on screen after a case change. With a following sibling, the server<em>was left behind as well, a second diagnostic was logged, and a duplicate client<em>was built.NotFoundError.@tryresuming after the rebuild: each attempt gets a new capability, so the resume read the misordered DOM as server output. It logged two false mismatches ("expected but the server rendered ", "expected but the server rendered ") and rebuilt the adopted<em>.This change:
adoptrecords the server node that followed the discarded one, andcommitBaginserts a detached rebuilt root before it (rebuiltPosition).commitBagalso no longer moves a fresh root that is already in its block's parent.@if/@switcharm removes that recorded node and everything after it up to its end, quietly, when nothing claimed it (sweepRebuiltTail). The rebuild already reported this mismatch. An unframed lite component that renders at that node drops the record, so a later sibling that adopts the node is never swept.singleRootcomponent without a server frame steps the cursor past a root it adopted (stepPastRoot). It also finds a root rebuilt in the cursor's place (freshAfter).@switch/@ifthat hydrates with no server range takes its bounds from the cursor (markerlessCursor/markerlessEnd).finalizeMarkerlessBranchgains acontentEndseparate from the anchor that its root slots use.save(), so its removals roll back too.None of this touches the happy adoption path. The only addition there is one null check per hydrated arm.
Folded in: keep the mismatched server node until its rebuilt root commits (8d5ccb8)
adoptused to remove a mismatched server node as soon as it built the replacement. If the rebuilt root then suspended beforecommitBag(ause()after the clone), two things went wrong. The server content vanished while it waited. A deferred<Hydrate split={false}>boundary also retried the same blocks from its preserved cursor, which by then sat on the next sibling's server range, so the retry mismatched that range, reported a second mismatch and rebuilt the sibling. This change:adoptsteps the cursor past the mismatched node without removing it and records it (replaced).rebuiltAtremoves it when the rebuilt root commits, before returning the anchor, because a Document holds one element.commitBagkeeps the one-optional-call shape from 3c63981. The<Hydrate>wrapper insert uses the same call.resumeAt). A mismatch at that same node is not reported again.delimitMarkerlessBranch, extracted fromfinalizeMarkerlessBranch). A retry then puts the root there, and a case change removes the node with the arm. Self-marking the node can't work, because the node is removed at commit.isOpenstart): builds the new arm as client DOM instead of hydrating it against the client's own close marker.The happy adoption path is unchanged. Everything new runs only on a mismatch, a suspension, or a hydrating swap.
Validation
pnpm format:checkpnpm typecheckpnpm test: I ran theoctaneandoctane-prodprojects instead (results below). CI covers the remaining projects.tests/hydration/rebuilt-clone-order.test.ts(dev and prod compile). It covers sibling order and adopted identity, the stale tail, a later sibling that adopts the node after the rebuild, a text hole after the rebuilt root, and@switchwith and without a sibling, including case changes. It also covers a@tryresume with a suspending reader in the rebuilt subtree. It asserts final DOM, adopted-node identity, and exactly one structural diagnostic and recoverable error. All 14 cases fail on the base, and the text-hole case throwsNotFoundError.@switcharm the server didn't render adopts the server<u>in place, then suspends inside an initial Suspense boundary. The arm used to publish empty markers before the adopted node on the throw, so the resume rebuilt it. It now finalizes on a throw only when it rebuilt a root in the cursor's place. The new case asserts the<u>is adopted across the resume with no diagnostics, and that a case change removes it. It fails on afcdb05, and onmainit leaves a duplicate<em>.Leaf) fails on the previous head, where the hot update was declined. The block now takes a rebuilt root, then one built at its anchor, and an adopted node only otherwise.NotFoundErrorwhen a retry discarded a node the arm had not adopted, and that text cursors and multi-root arms were still uncovered. 5036800 takes that work back out, so those paths matchmainagain.tests/hydration/rebuilt-clone-suspended.test.ts(dev and prod compile, 16 cases), for the folded fix. A rebuilt@switcharm resumes in a deferred boundary, an initial@try, and a root attempt. The server node must stay on screen while suspended, the adopted<em>must keep its identity, exactly one structural diagnostic and recoverable error must be reported, and later case changes must work. The suite also covers a case change before the deferred arm resumes, a rebuilt component root, a root rebuilt over another component's range, and a rebuilt<Hydrate>wrapper. On 3c63981, 10 cases fail and the deferred ones report twice and rebuild<em>. I removed each of the 7 parts of the fix separately and each made 2 to 14 cases fail.root-container-contract's document-shell case caught an insert-before-remove ordering in an earlier draft.mainat fdf54fe): the fulloctaneandoctane-prodprojects passed, 37,101 tests in 1,342 files, with no failures.pnpm sync, format and typecheck of the changed files are clean. The--budgetsgate passes:root-chained-jsxis 85,938 raw / 28,504 gzip against 85,952 / 28,512. Against 3c63981, the folded fix measured −1 raw on client-only fixtures, +350 raw / +93 gzip onhydrate-root, and +396 / +113 ondeferred-hydration.tests/hmr.test.ts: a hot update to a root rebuilt during hydration ahead of an adopted sibling. It covers the boundary of the rebuilt unframed root, which only HMR can observe.SeedBranchfixture (fix(hydration): mount blocks inside a rebuilt clone as client content #1552): with fix(hydration): mount blocks inside a rebuilt clone as client content #1552 alone it shows the three diagnostics, two recoverable errors, and the rebuilt<em>. With this change it gets one diagnostic and keeps the original<em>.octaneandoctane-prodprojects: 36,503 passed and 44 failed, all timeouts or knock-ons from timeouts, with the machine at load average ~98. The 11 affected files pass in isolation with longer timeouts, except onebehavior-roottest with its own 15 s limit. That test also times out on basemain's runtime under the same load (15.2 s on main versus 15.5 s here). Before the rebase, the full run passed apart from load timeouts inbehavior-rootandvolar, which pass in isolation.Performance, measured against the pre-rebase base 3ffd8cc with the same commands. The code delta didn't change in the rebase.
Bundle size (
benchmarks/bundle-size/run-minimal.mjs):root-chained-jsx, re-measured on 3c63981 against currentmain)hydrate-rootdeferred-hydrationsuspense-transitionServer, behavior-root, and aria/motion/floating-ui bundles are unchanged. Hydration-only logic lives in
HydrationCapabilitymethods, so mainly hydrating apps carry it. An earlier draft calledisBlockClosefromcomponentSlotImpland pulled the marker parser (~1.3 KB) into client bundles; that is fixed.Branch slot work (
benchmarks/client-hot-paths/branches.mjs): hydration lookup counts and work guards are identical.Client mount DOM operations (
benchmarks/dom-template-mount): all 7 targets are identical, and the semantic controls pass.Hydration timing (
benchmarks/hydration-range-compaction): the base (0.797 / 0.829 ms per 100 wrappers) fell between two candidate runs (0.823 / 0.840 and 0.742 / 0.748), so any difference is within noise.Adopted-host markerless arm (e478664, from Bugbot): a markerless arm that adopted its host in place, with a component inside it, left the cursor outside the arm's parent. The range then fell back to the static anchor and took in later server siblings. The arm's content now ends after the host it adopted. New regression
keeps a server sibling out of a @switch arm that adopted its host in place; it runs in CI only, since Dominic asked sessions not to run tests locally.Merged with fix(hydration): continue after a component adopted in place without a range #1567 (204479b): fix(hydration): continue after a component adopted in place without a range #1567's
renderInPlacesteps the cursor past a node that an unframed lite orsingleRootcall adopted in place. It replaces this branch's narrowerstepPastRootand lite-path tail clear, which were removed. ThesingleRootboundary now stamps the cursor only when the body adopted it or threw, no root was rebuilt in its place, and it is not a closing marker. The fallback still finds a root rebuilt in the cursor's place before probing the anchor. Locally only the light gates ran (scoped typecheck, format, sync); CI covers the tests.Merged with fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564 (9f28db5): after an adopted arm renders, this branch's quiet
sweepRebuiltTailruns before fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564'sdiscardArmTail. Server content left after a rebuilt root goes under that root's single report, anddiscardArmTailstill reports any other unclaimed range.rebuilt-clone-blocks'ForeignListBranchnow expects one diagnostic instead of two, and both of its foreign tails are asserted removed. Locally, only the affected files ran on the merged head (branch-arm-tail, rebuilt-clone-blocks, rebuilt-clone-order and hmr, 103 tests in each project); CI covers the rest.Risk / follow-ups
@if/@switcharms only. A rebuilt root that is the last thing in a component frame,@trybody, or@foritem still leaves an unclaimed server tail.main's behaviour. A markerless@switcharm that adopts the server node in place, with no mismatch, and then suspends inside a deferred<Hydrate split={false}>goes wrong on resume. The switch markers land after the server sibling, and a second<em>is built with one false report. A case change before resolve loses the<u>and rebuilds the<em>. A rebuilt arm is now covered; an adopted one needs a bounds design of its own.renderUnframedon suspension: a component with no server range that suspends sweeps from the stale node into the next sibling's server range, and reports, while it waits. That blanks the region and rebuilds the sibling. It was found while probing this fix, and a separate session is working on it.rebuildFragmentalso still discards server nodes immediately, even though a fragment'suse()holes run beforedrainFrag.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
High Risk
Large, intricate changes to core hydration DOM adoption, insertion, and Suspense resume paths; wrong edge-case handling would reorder or duplicate live server markup.
Overview
Fixes hydration mismatch recovery so a client-rebuilt template root replaces the server node at the cursor instead of landing at the block end, and so suspension no longer drops the server DOM early.
On structural mismatch,
HydrationCapabilitynow keeps the mismatched server node (replaced), advances the cursor, and tracks a rebuilt tail;commitBag,<Hydrate>inserts, and related paths userebuiltAtto commit the fresh root in that slot and then remove the server range. Retries resume at the same node viaresumeAtwithout a second mismatch report. Adopted@if/@switcharms callsweepRebuiltTailso unclaimed server siblings after the rebuild are removed under the single existing diagnostic.Markerless control-flow arms gain cursor-based bounds (
markerlessCursor/markerlessEnd,contentEndinfinalizeMarkerlessBranch) so roots rebuilt where the server had no range stay inside the arm. UnframedsingleRootblocks detect roots rebuilt after the cursor (freshAfter) and avoid stamping wrong boundaries.Adds changesets, hydration fixtures/tests (
rebuilt-clone-order,rebuilt-clone-suspended), updatesrebuilt-clone-blocksexpectations (one report, tail swept quietly), and HMR cases for rebuilt roots beside adopted siblings.Reviewed by Cursor Bugbot for commit c161d68. Bugbot is set up for automated code reviews on this repo. Configure here.