Repository navigation
fix(hydration): remove the server tail after a component root rebuilt over its range - #1614
Conversation
… over its range When a range's own single-root template did not match the range's first server node, adopt() rebuilt the root, but only a successful adoption recorded where the range's content ends (claimRoots). settleClaim then fell back to its last-slot heuristic and left the rest of the server range on screen, unreported. The single-root mismatch path now records the claim when it rebuilds the open claim's first node, under claimRoots' existing owner check, and settleClaim removes that tail with sweepRebuiltTail, without a second report. A lite component replayed by a <Hydrate> resume (#1598) sweeps the same tail before stepping past its range. 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: Replay sweep deletes adopted siblings
- Cleared rebuiltTail in settleClaim's else branch (when from !== rebuiltTail) so that a stale tail from a first render that settled without sweeping does not cause the lite replay path's unconditional sweepRebuiltTail call to delete an adopted sibling.
Or push these changes by commenting:
@cursor push bc16fb1d1a
Preview (bc16fb1d1a)
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
@@ -19482,6 +19482,8 @@
if (from === this.rebuiltTail && from !== null) {
this.sweepRebuiltTail(end);
if (this.node === end) return;
+ } else {
+ this.rebuiltTail = null;
}
if (from === undefined) {
// A slot that adopted a server node without a range parks the cursorYou can send follow-ups to the cloud agent here.
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)
All 20 timed operations (19 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)
96 other measured values are unchanged. |
…t was rebuilt The <Hydrate> resume path swept the rebuilt root's server tail whenever one was pending. When the rebuilt root came from a call in a fragment's leading hole, that tail was the fragment's own adopted static root, so the resume deleted it. The single-root mismatch path now records the scope whose range's whole content the rebuilt root is (claimRoots' owner check), and a lite replay sweeps only for that scope. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… component slots too A <Hydrate> resume of a wrapper whose only call inherits its range left the rebuilt root's server tail. The rebuild recorded the inheriting call's scope, but the wrapper's slot is what completes on the resume, and that wrapper renders in a full component slot, which never swept. The rebuild now records the start marker of the range whose whole content it is (rebuiltRange), and both the lite replay and componentSlotImpl's post-render step sweep when their range starts there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-cad2cc # 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.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Child-slot resume skips tail sweep
- Added rebuiltRange/sweepRebuiltTail checks and cursor advancement after renderBlock in both same-identity early-return paths of childSlot, matching the pattern componentSlotImpl already applies after every render.
Or push these changes by commenting:
@cursor push d79e18cc0f
Preview (d79e18cc0f)
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
@@ -37103,6 +37103,11 @@
state.block.body = comp;
renderBlock(state.block);
state.currentComp = comp;
+ if (hydration !== null && !state.borrowed && state.end !== null) {
+ const rebuilt = hydration.rebuiltRange;
+ if (rebuilt !== null && rebuilt === state.start) hydration.sweepRebuiltTail(state.end);
+ hydration.node = getNextSibling(state.end);
+ }
return;
}
if (state.block !== null && comp === state.currentComp) {
@@ -37128,6 +37133,11 @@
if (state.block.props !== props) journalRootProperty(state.block, 'props', state.block.props);
state.block.props = props;
renderBlock(state.block);
+ if (hydration !== null && !state.borrowed && state.end !== null) {
+ const rebuilt = hydration.rebuiltRange;
+ if (rebuilt !== null && rebuilt === state.start) hydration.sweepRebuiltTail(state.end);
+ hydration.node = getNextSibling(state.end);
+ }
return;
}
const signalInstanceKey =You can send follow-ups to the cloud agent here.
A <Hydrate> resume completes a range through whichever slot owns it, and each slot kind needed its own sweep of a rebuilt root's server tail. The root that is its range's whole content now takes the rest of that range when it commits (rebuiltAt), while the cursor still rests right after the node it replaces, so every slot kind and every resume path is covered. The sweeps in settleClaim, componentSlotLite's replay and componentSlotImpl are gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…/adoring-noether-cad2cc # Conflicts: # packages/octane/src/runtime.ts
…closing range #1622 lets claimRoots accept a markerless branch's claim (claimOwner), which has no open marker of its own. A rebuilt root that is such a branch's content recorded the node before it as its range's start, which can be an enclosing range's open marker. The commit-time take then removed the nodes after the branch up to that range's end, including a later call's server node (NotFoundError). Only a claim on a marker range records rebuiltRange. 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.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.
Reviewed by Cursor Bugbot for commit 1ca7bda. Configure here.
… it commits A <Hydrate> resume claims the range again when the component that rebuilt its single root suspended before committing it (a use() in setup, or in the template after the clone), so the root still takes its range's tail when the resume commits it. Pin that for lite and full slots. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Bugbot Autofix prepared a fix for the issue found in the latest run.
Or push these changes by commenting: Preview (27a76c90e8)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
@@ -19378,6 +19378,20 @@
return this.unframedClaims?.get(block);
}
+ /** Consume a suspended adopted-range claim for `block` and sweep its rebuilt tail after re-render. */
+ resumeSuspendedClaim(block: Block): boolean {
+ const claim = this.suspendedClaims?.get(block);
+ if (claim === undefined) return false;
+ this.suspendedClaims!.delete(block);
+ const tail = this.rebuiltTail;
+ renderBlock(block);
+ if (tail !== null && this.rebuiltTail === tail) {
+ this.node = tail;
+ this.sweepRebuiltTail(block.endMarker!);
+ }
+ return true;
+ }
+
/**
* Resume `source`, the block that a preserved activation suspended in. Inside
* a component whose unframed render suspended, it renders without adopting,
@@ -32994,8 +33008,13 @@
if (state.block.props !== renderProps)
journalRootProperty(state.block, 'props', state.block.props);
state.block.props = renderProps;
- if (claim === undefined) renderBlock(state.block);
- else hydration!.renderUnframed(renderBlock, state.block, state.block, claim);
+ if (claim === undefined) {
+ if (hydration !== null && hydration.resumeSuspendedClaim(state.block)) {
+ // The block re-rendered and its rebuilt tail was swept.
+ } else {
+ renderBlock(state.block);
+ }
+ } else hydration!.renderUnframed(renderBlock, state.block, state.block, claim);
}
// Hydration: advance the cursor PAST this component's adopted range so the next
// sibling adopts from the right node. The body itself doesn't reliably leave the
diff --git a/packages/octane/tests/hydration/_fixtures/rebuilt-fragment-suspended-child.tsrx b/packages/octane/tests/hydration/_fixtures/rebuilt-fragment-suspended-child.tsrx
--- a/packages/octane/tests/hydration/_fixtures/rebuilt-fragment-suspended-child.tsrx
+++ b/packages/octane/tests/hydration/_fixtures/rebuilt-fragment-suspended-child.tsrx
@@ -178,6 +178,30 @@
</div>
}
+function ParaCall(props: { leaf: Promise<string> }) @{
+ <Para leaf={props.leaf} />
+}
+
+export function RebuiltRootInheritedBranch(props: { server?: boolean; leaf: Promise<string> }) @{
+ <div>
+ <Hydrate split={false} when={load()}>
+ <section>
+ @if (props.server) {
+ <>
+ <BoldThenEm />
+ <Em />
+ </>
+ } @else {
+ <>
+ <ParaCall leaf={props.leaf} />
+ <Em />
+ </>
+ }
+ </section>
+ </Hydrate>
+ </div>
+}
+
function BoldThenItalic() @{
<>
<b class="server">{'server'}</b>
diff --git a/packages/octane/tests/hydration/rebuilt-fragment-suspended-child.test.ts b/packages/octane/tests/hydration/rebuilt-fragment-suspended-child.test.ts
--- a/packages/octane/tests/hydration/rebuilt-fragment-suspended-child.test.ts
+++ b/packages/octane/tests/hydration/rebuilt-fragment-suspended-child.test.ts
@@ -217,6 +217,26 @@
expect(warnings()).toHaveLength(dev ? 1 : 0);
});
+ it('completes a child of a rebuilt root inside an inherited call, as when its data is ready', async () => {
+ const name = 'RebuiltRootInheritedBranch';
+ render(name, { server: true, leaf: fulfilled('unused') });
+ await hydrate(name, { leaf: fulfilled('z') });
+ const ready = markup(section());
+ root!.unmount();
+ recoverable = [];
+ errSpy.mockClear();
+
+ render(name, { server: true, leaf: fulfilled('unused') });
+ const leaf = pending();
+ await hydrate(name, { leaf: leaf.promise });
+ await act(async () => leaf.resolve('z'));
+
+ expect(markup(section().querySelector('p')!)).toBe('<em>z</em><s>s</s>');
+ expect(markup(section())).toBe(ready);
+ expect(recoverable).toEqual([expect.stringMatching(MISMATCH)]);
+ expect(warnings()).toHaveLength(dev ? 1 : 0);
+ });
+
it('keeps the root a fragment adopted after a hole whose call rebuilt its root, as when its data is ready', async () => {
const name = 'RebuiltHoleBranch';
render(name, { server: true, leaf: fulfilled('unused') });You can send follow-ups to the cloud agent here. |
|
The Bugbot Autofix above (branch The "Resume leaves inherited rebuilt tail" finding was fixed in 9c2f392. That approach was then replaced by the commit-time take in ca0c638: a rebuilt root that is its range's whole content takes the range's tail in The Autofix's 🤖 Generated with Claude Code |
Resolve the conflict with #1614: its rebuilt-range tail removal (rebuiltRange / takeRangeTail) now runs inside HydrationCapability.insertRoot, which replaced rebuiltAt. A null from takeRangeTail still appends. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
When hydration rebuilds a component's single root over a server node that does not match it, the rest of the server content in that component's range now goes too. Before this fix, it stayed on screen after the rebuilt root, and nothing reported it.
Repro (pre-existing on main, no suspension needed): a lite
Para(<p>) adopts the range the server rendered forBoldThenEm(<b>+<em>tail</em>) in the other@ifarm. The section read<p>p</p><em>tail</em><em>e</em>. It now reads<p>p</p><em>e</em>. The followingEm's server<em>keeps its identity, and the mismatch is reported once.Cause. Only a successful adoption recorded where a range's content ends (
claimRoots, fromadopt()). When the range's own template rebuilt the range's first node instead, nothing recorded it.settleClaimthen fell back to its last-slot heuristic and left the tail in place. This affected every claim owner:componentSlotLite, andrenderClaimedin bothcomponentSlotImplandchildSlot.Fix (
packages/octane/src/runtime.ts):adopt()'s single-root mismatch path callsclaimRoots(cursor, null)when the rebuilt node is the open claim's first node. claimRoots' owner check limits this to the range's own content: the owning block, a call inheriting the range, or the lite component that adopted it. It then records that range's start marker (rebuiltRange). A markerless branch's claim (fix(hydration): end a markerless branch arm after every root its template adopted #1622'sclaimOwner) has no range of its own, so it records none.rebuiltAt), it takes the rest of the range with it (takeRangeTail), while the cursor still rests right after the node it replaced. This is quiet: the rebuild already reported the mismatch, as@if/@switcharms already do for a rebuilt root's tail. Because it happens at commit, every slot kind and every resume path is covered:componentSlotLite,componentSlotImpl,childSlot, a@tryretry, and a<Hydrate>resume (fix(hydration): resume a suspended child inside a rebuilt component fragment #1598).settleClaimand from each slot kind's resume path. Bugbot found three resume gaps that way: a hole whose call rebuilt its root, an inheriting call in a full slot, and a hole or return value. The commit-time take replaced all of them.RebuiltHoleBranchandStateRebuiltHoleBranchtests check that a resumed fragment keeps the static root it adopted after a hole whose call rebuilt its root.InheritedRootBranch,RebuiltHoleValueBranchandReturnBranchcheck that the tail goes for every slot kind.MarkerlessRebuiltcontrol covers fix(hydration): end a markerless branch arm after every root its template adopted #1622's markerless claim. Without theclaimOwnerguard, the merge would throwNotFoundErrorthere.Design note: a broader version, sweeping whenever the cursor rests on a rebuilt root's tail, deleted a fragment template's adopted static element after a hole whose call was rebuilt in place. The fragment's static roots do not move the cursor. The
HoleThenElementcontrol pins main's correct behavior there.Validation
pnpm format:check: not run. Ranpnpm format:files:checkon the changed files, which passes.pnpm typecheck: not run. Ranpnpm typecheck:filesonruntime.tsand both tests and.tsrxfixtures, which passes.pnpm test: not run locally. CI covers it.tests/hydration/rebuilt-root-tail.test.ts: 66 cases ×octane+octane-prod, run under dev compile, prod compile, and prod compile with prod runtime.@tryretry.ClaimedTailfails;HoleThenElementfails;rebuiltRangerecorded for a markerless claim:MarkerlessRebuiltfails (it throwsNotFoundError);RebuiltHoleBranchorStateRebuiltHoleBranchfails;RebuiltRootBranchand the newInheritedRootBranchfail.rebuilt-root-tail,rebuilt-fragment-suspended-child,branch-arm-claim-tail,in-place-tailandmarkerless-arm-retryinoctane, 232 pass. Before that merge,rebuilt-root-tail,rebuilt-fragment-suspended-childandin-place-tail×octane+octane-prod: 262 pass.octane: 1,385 pass, on an earlier head (5e57a13). Not re-run on this head because of local machine load; CI covers it.node benchmarks/bundle-size/run-minimal.mjs hydrate-rootRisk / follow-ups
<Hydrate>resume of a keyed array list item renders the arm's content twice. main does the same.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 mismatch recovery and DOM removal in
runtime.ts; wrong range boundaries could drop claimed nodes or leave stale markup, though broad tests and control cases target those edges.Overview
When mismatch recovery rebuilds a component’s single root over the first server node in that component’s claim range, hydration now drops the rest of the server markup inside that same range (e.g. trailing nodes from the server’s other component) at commit time, without a second mismatch report. Siblings after the range still reuse their server nodes.
The runtime tracks whether the rebuilt root is the range’s whole content (
rebuiltRange+claimRootson the mismatch path inadopt()), thentakeRangeTailinrebuiltAt()removes stale server nodes between the replaced node and the range end when nothing else has claimed them. That covers suspending retries and<Hydrate>resumes; fragments that only rebuild a hole and still adopt a static sibling are unchanged.Adds
rebuilt-root-tailcoverage (many slot shapes, suspension, and controls for claimed tails / markerless claims) and extends suspended-child hydration fixtures for inherited roots, holes, returns, and inline suspend paths. Patch changeset foroctane.Reviewed by Cursor Bugbot for commit ead75c8. Bugbot is set up for automated code reviews on this repo. Configure here.