Skip to content

fix(hydration): build a deferred retry's update content on the client - #1596

Merged
trueadm merged 3 commits into
mainfrom
claude/gifted-wing-15ab75
Oct 2, 2026
Merged

trueadm merged 3 commits into
mainfrom
claude/gifted-wing-15ab75

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  • Component swap (<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.
  • Keyed-list insert: mountItem adopted the list's own range marker as the new row's range, so an adopted row (<s>x</s>) disappeared.
  • Renderable hole ({node}): an identity swap skipped clearChildContent, 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.
  • Swapped-in content that suspends: the next retry resumed it as the activation's source under 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, so renderBlock's existing !owns check keeps every later render client-side, including a retry that resumes inside one.
  • componentSlot: a swap of an existing block goes through renderUpdate.
  • Keyed lists: reconcileKeyed's three insert sites pass a new inserted flag, and mountItem then skips adoption and builds the row on the client.
  • childSlot: a hydrating update to a slot that already rendered clears the old content and renders the new block through renderUpdate. It no longer adopts text at the cursor, and it builds a new list on the client.
  • Branch slots are unchanged. 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. On main the 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:check on every touched file passes)
  • pnpm typecheck (not run repo-wide; pnpm typecheck:files on the runtime, test, and .tsrx fixture passes)
  • pnpm test (not run locally; left to CI)
  • targeted tests:
  • Size: minified prod runtime, whole module, +179 B gzip. Most of it is HydrationCapability methods. The client path gains no per-render work, since every new check is behind hydration !== null.

Risk / follow-ups

  • These paths also apply when a render-phase update re-renders an adopted parent during root hydration. A component swap there now builds on the client without a report, which matches React deferring such an update. Existing hydration suites pass.
  • @if/@switch swaps under stale captures still depend on the separate adopt() single-root stale-values reporting gate, which is not on main.
  • The existing suspend()-based rebuild paths (branch rebuild, childSlot rebuild, mountItem structural 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

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with 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 / recordUpdate and a builtByUpdate/owns gate 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 (inserted on mountItem), 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.

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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 2, 2026
@github-actions
github-actions Bot marked this pull request as draft October 2, 2026 18:59

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

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 when inserted is true, so that owns() correctly returns false for inserted keyed-list rows on a later retry, preventing them from adopting a sibling's server nodes.

Create PR

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.

Comment thread packages/octane/src/runtime.ts Resolved
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 29 value(s) increased
  • 🔴 bundle-reachability: 36 value(s) increased

Compares 70ee6a381 with c299439af on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 4.98 4.37 −12.2% ±52% ⚪ within noise
octane-tsrx replace 11.96 10.79 −9.8% ±37% ⚪ within noise
octane-tsrx add 4.56 4.31 −5.5% ±36% ⚪ within noise
octane-tsrx update 0.74 0.68 −8.1% ±56% ⚪ within noise
octane-tsrx select 0.35 0.27 −22.9% ±53% ⚪ within noise
octane-tsrx swap 0.72 0.76 +5.6% ±84% ⚪ within noise
octane-tsrx remove 0.71 0.63 −11.3% ±64% ⚪ within noise
octane-tsrx runlots 42.34 39.87 −5.8% ±37% ⚪ within noise
octane-tsrx select_lots 0.36 0.36 ±0.0% ±39% ⚪ within noise
octane-tsrx clear 58.48 60.82 +4.0% ±34% ⚪ within noise
octane-jsx run 4.81 4.85 +0.8% ±40% ⚪ within noise
octane-jsx replace 11.69 15.06 +28.8% ±41% ⚪ within noise
octane-jsx add 4.10 4.57 +11.5% ±34% ⚪ within noise
octane-jsx update 1.71 1.41 −17.5% ±74% ⚪ within noise
octane-jsx select 0.90 1.02 +13.3% ±40% ⚪ within noise
octane-jsx swap 1.41 1.83 +29.8% ±97% ⚪ within noise
octane-jsx remove 1.36 1.70 +25.0% ±56% ⚪ within noise
octane-jsx runlots 34.38 37.51 +9.1% ±32% ⚪ within noise
octane-jsx select_lots 3.83 3.33 −13.1% ±48% ⚪ within noise
octane-jsx clear 62.63 70.41 +12.4% ±36% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 126,782 126,849 +67 (+0.1%) 🔴
octane-tsrx js_gzip 41,957 41,980 +23 (+0.1%) 🔴
octane-tsrx js_brotli 36,941 37,057 +116 (+0.3%) 🔴
octane-tsrx app_brotli 2,224 2,226 +2 (+0.1%) 🔴
octane-tsrx fw_raw 119,270 119,337 +67 (+0.1%) 🔴
octane-tsrx fw_gzip 39,395 39,418 +23 (+0.1%) 🔴
octane-tsrx fw_brotli 34,717 34,831 +114 (+0.3%) 🔴
octane-tsrx todo_js_raw 141,725 141,792 +67 (+0.0%) 🔴
octane-tsrx todo_js_gzip 46,805 46,823 +18 (+0.0%) 🔴
octane-tsrx todo_js_brotli 41,053 40,999 −54 (−0.1%) 🟢
octane-tsrx todo_app_brotli 2,124 2,120 −4 (−0.2%) 🟢
octane-tsrx todo_fw_raw 136,615 136,682 +67 (+0.0%) 🔴
octane-tsrx todo_fw_gzip 44,328 44,346 +18 (+0.0%) 🔴
octane-tsrx todo_fw_brotli 38,929 38,879 −50 (−0.1%) 🟢
octane-tsrx chat_js_raw 140,970 141,037 +67 (+0.0%) 🔴
octane-tsrx chat_js_gzip 46,780 46,798 +18 (+0.0%) 🔴
octane-tsrx chat_js_brotli 41,111 41,075 −36 (−0.1%) 🟢
octane-tsrx chat_app_gzip 2,978 2,979 +1 (+0.0%) 🔴
octane-tsrx chat_app_brotli 2,638 2,636 −2 (−0.1%) 🟢
octane-tsrx chat_fw_raw 134,317 134,384 +67 (+0.0%) 🔴
octane-tsrx chat_fw_gzip 43,802 43,819 +17 (+0.0%) 🔴
octane-tsrx chat_fw_brotli 38,473 38,439 −34 (−0.1%) 🟢
octane-tsrx weather_js_raw 177,579 177,733 +154 (+0.1%) 🔴
octane-tsrx weather_js_gzip 58,074 58,107 +33 (+0.1%) 🔴
octane-tsrx weather_js_brotli 50,441 50,546 +105 (+0.2%) 🔴
octane-tsrx weather_app_brotli 7,578 7,574 −4 (−0.1%) 🟢
octane-tsrx weather_fw_raw 150,844 150,998 +154 (+0.1%) 🔴
octane-tsrx weather_fw_gzip 49,029 49,062 +33 (+0.1%) 🔴
octane-tsrx weather_fw_brotli 42,863 42,972 +109 (+0.3%) 🔴
octane-jsx js_raw 225,675 225,959 +284 (+0.1%) 🔴
octane-jsx js_gzip 72,082 72,144 +62 (+0.1%) 🔴
octane-jsx js_brotli 62,374 62,482 +108 (+0.2%) 🔴
octane-jsx app_gzip 2,943 2,944 +1 (+0.0%) 🔴
octane-jsx app_brotli 2,506 2,503 −3 (−0.1%) 🟢
octane-jsx fw_raw 217,208 217,492 +284 (+0.1%) 🔴
octane-jsx fw_gzip 69,139 69,200 +61 (+0.1%) 🔴
octane-jsx fw_brotli 59,868 59,979 +111 (+0.2%) 🔴

8 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 116,474 116,541 +67 (+0.1%) 🔴
cli-spa-starter gzip 39,331 39,349 +18 (+0.0%) 🔴
cli-spa-starter brotli 34,341 34,385 +44 (+0.1%) 🔴
root-static raw 201,994 202,277 +283 (+0.1%) 🔴
root-static gzip 64,234 64,341 +107 (+0.2%) 🔴
root-static brotli 55,669 55,778 +109 (+0.2%) 🔴
context raw 110,371 110,455 +84 (+0.1%) 🔴
context gzip 36,552 36,596 +44 (+0.1%) 🔴
context brotli 32,359 32,366 +7 (+0.0%) 🔴
hydrate-root raw 165,499 165,727 +228 (+0.1%) 🔴
hydrate-root gzip 52,825 52,891 +66 (+0.1%) 🔴
hydrate-root brotli 45,991 46,094 +103 (+0.2%) 🔴
deferred-hydration raw 228,305 228,634 +329 (+0.1%) 🔴
deferred-hydration gzip 72,449 72,550 +101 (+0.1%) 🔴
deferred-hydration brotli 62,531 62,583 +52 (+0.1%) 🔴
suspense-transition raw 166,879 166,964 +85 (+0.1%) 🔴
suspense-transition gzip 53,661 53,704 +43 (+0.1%) 🔴
suspense-transition brotli 46,834 46,899 +65 (+0.1%) 🔴
binding-base-ui-vite raw 212,184 212,468 +284 (+0.1%) 🔴
binding-base-ui-vite gzip 67,842 67,882 +40 (+0.1%) 🔴
binding-base-ui-vite brotli 58,749 58,839 +90 (+0.2%) 🔴
binding-base-ui-esbuild raw 210,153 210,433 +280 (+0.1%) 🔴
binding-base-ui-esbuild gzip 67,772 67,837 +65 (+0.1%) 🔴
binding-base-ui-esbuild brotli 58,752 58,858 +106 (+0.2%) 🔴
binding-radix-vite raw 214,114 214,400 +286 (+0.1%) 🔴
binding-radix-vite gzip 68,360 68,468 +108 (+0.2%) 🔴
binding-radix-vite brotli 59,319 59,336 +17 (+0.0%) 🔴
binding-radix-esbuild raw 212,042 212,325 +283 (+0.1%) 🔴
binding-radix-esbuild gzip 68,373 68,424 +51 (+0.1%) 🔴
binding-radix-esbuild brotli 59,272 59,298 +26 (+0.0%) 🔴
binding-apollo-client-vite raw 357,236 357,523 +287 (+0.1%) 🔴
binding-apollo-client-vite gzip 111,930 112,047 +117 (+0.1%) 🔴
binding-apollo-client-vite brotli 97,593 97,667 +74 (+0.1%) 🔴
binding-apollo-client-esbuild raw 360,192 360,480 +288 (+0.1%) 🔴
binding-apollo-client-esbuild gzip 114,127 114,217 +90 (+0.1%) 🔴
binding-apollo-client-esbuild brotli 99,395 99,495 +100 (+0.1%) 🔴

69 other measured values are unchanged.

trueadm and others added 2 commits October 2, 2026 20:14
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
trueadm marked this pull request as ready for review October 2, 2026 19:16
@trueadm
trueadm merged commit 2b4b3fc into main Oct 2, 2026
50 checks passed
@trueadm
trueadm deleted the claude/gifted-wing-15ab75 branch October 2, 2026 19:38
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant