Repository navigation
fix(hydration): build a deferred retry's update content on the client - #1596
Merged
Merged
Conversation
A suspended deferred Hydrate boundary keeps its attempt's blocks and retries from where it stopped. When a mounted parent changed its captures while it was pending, the retry reconciled the adopted slots as updates under active hydration. A component swapped in by a dynamic call, a row inserted into a keyed list, or a renderable hole's new value then adopted or rebuilt over server nodes that other blocks owned. Rows went missing, a sibling's server node was replaced, the hole leaked its old block, and the swap reported a false mismatch. Content an update creates where its slot already rendered now builds on the client. componentSlot swaps and childSlot's new blocks render through HydrationCapability.renderUpdate, which records the block. owns() refuses recorded blocks, so later renders of them stay client-side, including a retry that resumes a block that suspended inside one. reconcileKeyed marks its inserts so mountItem skips adoption. childSlot no longer adopts text or a list on a hydrating update. 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 prepared a fix for the issue found in the latest run.
- ✅ Fixed: Inserted rows skip update ownership
- Added
hydration.recordUpdate(block)after the suspended mount wheninsertedis true, so thatowns()correctly returns false for inserted keyed-list rows on a later retry, preventing them from adopting a sibling's server nodes.
- Added
Or push these changes by commenting:
@cursor push bb76ca11ae
Preview (bb76ca11ae)
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
@@ -45831,7 +45831,7 @@
: '',
);
}
- return hydration.suspend(() =>
+ const block = hydration.suspend(() =>
mountItem(
parentBlock,
parentNode,
@@ -45845,6 +45845,8 @@
ssrMarkerless,
),
);
+ if (inserted) hydration.recordUpdate(block);
+ return block;
}
if (
singleRoot === true ||You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 1e7bf8d. Configure here.
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)
8 other measured values are unchanged. Public-import reachability bundles (bytes)
69 other measured values are unchanged. |
An inserted keyed row built with hydration suspended, but owns() still treated it as hydration-owned. When a later retry opened the row and its new content suspended, the retry after that resumed the suspended block under hydration and placed it at the cursor, ahead of the row's own text. Record inserted rows like renderUpdate's blocks, so every later render of the row stays on the client. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 19:16
This was referenced Oct 2, 2026
trueadm
added a commit
that referenced
this pull request
Oct 4, 2026
… inside it Main has failed stale-deferred-retry.test.ts since #1702 landed next to #1596. #1702 made a client @if/@switch arm that suspends before inserting anything keep no bound and read it from its insertion anchor whenever it renders. A deferred <Hydrate> retry resumes the suspended leaf before its ancestors reconcile, so the leaf inserts its content inside the unbounded arm first. The arm then bounded itself after that content, and closing the arm later left the leaf's output in the document. The resume now records where the leaf's content starts on each unbounded arm around it (the arm block's startMarker). The arm's next render, its root-render journal, and its sweep when superseded read that bound (pendingArmBefore), so the arm owns the content its leaf inserted and still never relies on a sibling's node. The added test closes the row in the same retry that resumes it, which reaches the superseded-arm sweep; each test fails with its half of the fix reverted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
A suspended deferred
<Hydrate>boundary keeps its first attempt's blocks and retries from where it stopped. When a mounted parent changed the boundary's captures while it was pending, the retry reconciled the already-adopted slots as updates while hydration was still active. Anything those updates created then adopted or rebuilt over server nodes that other blocks owned:<C />): the swapped-in block rebuilt over a later sibling's server node (Pend's<u>), landed after the list, and reported a false mismatch.mountItemadopted the list's own range marker as the new row's range, so an adopted row (<s>x</s>) disappeared.{node}): an identity swap skippedclearChildContent, so the old block stayed mounted and the new one stole a sibling's node. An empty→text update took over a neighbouring static text node. A switch to a list adopted rows from other slots.sourceunder active hydration, so it stole again.Content an update creates where its slot already rendered now builds on the client, beside the adopted server nodes:
HydrationCapability.renderUpdate(block)renders such a block with hydration suspended and records it.owns()refuses recorded blocks and their descendants, sorenderBlock's existing!ownscheck keeps every later render client-side, including a retry that resumes inside one.renderUpdate.reconcileKeyed's three insert sites pass a newinsertedflag, andmountItemthen skips adoption and builds the row on the client.renderUpdate. It no longer adopts text at the cursor, and it builds a new list on the client.renderBranchSlot's swap already parks the cursor on its own close marker and cannot steal.The server HTML predates the new captures, so nothing is reported (
docs/deferred-hydration.md, "Boundary ownership", gains one sentence on this). A changeset is included.Repro, from the report: server
k='a', rows['x','y']. Hydrate with a pending leaf,render(DynProbe, { k: 'b' })while pending, then resolve. Onmainthe section ends as<s>x</s><s>y</s><i>B</i><em>e</em>, where<i>B</i><s>x</s><s>y</s><u>x</u><em>e</em>is expected. Rows['q','x','y']and['x','q']each lost<s>x</s>.Validation
pnpm format:check(not run repo-wide;pnpm format:files:checkon every touched file passes)pnpm typecheck(not run repo-wide;pnpm typecheck:fileson the runtime, test, and.tsrxfixture passes)pnpm test(not run locally; left to CI)packages/octane/tests/hydration/stale-deferred-retry.test.tswith_fixtures/stale-deferred-retry.tsrx, 58 cases per compile mode. They assert final DOM, server-node identity for survivors (<em>,<u>, adopted rows,<b>), noonRecoverableErrorand noconsole.error, and that later updates own exactly the nodes they show. They pass inoctaneandoctane-prod(116) on the rebased head.main, 44 of 58 fail. Reverting each of the eight pieces of the fix on its own fails its own cases.main, the wholetests/hydration/directory passed in theoctaneproject (128 files, 6,244 tests), plus the top-level*hydrat*suites. It was not re-run after rebasing over fix(hydration): discard the server tail after an @if/@switch arm's last component #1587 and fix(hydration): keep a later sibling's server range when a component without one is built #1589.HydrationCapabilitymethods. The client path gains no per-render work, since every new check is behindhydration !== null.Risk / follow-ups
@if/@switchswaps under stale captures still depend on the separateadopt()single-root stale-values reporting gate, which is not onmain.suspend()-based rebuild paths (branch rebuild, childSlot rebuild,mountItemstructural mismatch) don't record their blocks. If such a rebuild suspends and a retry resumes it, it may hit the same steal. This is unverified.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 reconciliation for deferred boundaries, component slots, keyed lists, and renderable holes; behavior changes when captures drift during a suspended retry, though scoped to active hydration and covered by new tests.
Overview
Fixes deferred
<Hydrate>retries when a parent changes captures while the first activation is still suspended. Previously, reconciling those updates under active hydration could adopt or rebuild over server nodes another block already owned—component swaps stealing siblings, keyed inserts losing rows, renderable-hole changes clobbering neighbours, and false mismatch reports.The hydration pass now tracks client-built update content via
renderUpdate/recordUpdateand abuiltByUpdate/ownsgate so replacements mount beside adopted server DOM instead of walking the hydration cursor. That path covers dynamic component swaps, child slots (lists, holes, text), and new keyed rows (insertedonmountItem), including content that suspends and resumes on a later retry.Docs note that capture-driven additions mount client-side without warnings; a changeset and broad hydration tests (
stale-deferred-retry) lock the behavior.Reviewed by Cursor Bugbot for commit bdc4a38. Bugbot is set up for automated code reviews on this repo. Configure here.