Skip to content

fix(hydration): adopt a descriptor list again from its first server item when a deferred retry refills it - #1624

Merged
trueadm merged 4 commits into
mainfrom
fix/descriptor-hydrate-held-arm
Oct 3, 2026
Merged

trueadm merged 4 commits into
mainfrom
fix/descriptor-hydrate-held-arm

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Hydrating a deferred <Hydrate> boundary whose children are descriptors (a component that uses plain return JSX, not an @{ … } body) rebuilt a list item on the client and duplicated its server nodes when that item suspended. With the reported repro, the section ended up as <!--if--><s>s</s><!--it--><!--if--><s>s</s><i>z</i><!----><b>b</b><!--/if--><!--/it--><em>e</em>, with a recoverable "Hydration mismatch" and the dev warning "the client expected another list item but the server rendered ". The same component written as an @{ … } body hydrated correctly.

Two defects combine:

  1. The descriptor list refilled from the wrong cursor. <section>'s descriptor children hydrate as a list (renderPreparedChildList → mountItemsLinear). When item 0's first render suspends, the list keeps no items. The boundary's retry resumes the suspended block at its saved cursor (<i>, inside the item) and then fills the list again from there. mountItem found no item range at <i>, reported a structural mismatch, discarded the server content up to the list's end and client-built the items. A compiled @for already restarts a first fill from the server's first item (forBlock: "A pending child can replay its adopted slot …"). The descriptor list now does the same: childSlot's existing builtByUpdate check becomes HydrationCapability.buildsList, which also refills a retained list that kept no items (refill).
  2. The abandoned item's held arm left its start comment behind. An item whose first render throws is never returned to its list, so the retry mounts it afresh over the same server range. When a markerless @if/@switch arm suspended inside it, holdMarkerlessBranch had inserted its start comment there. The fresh arm then found that comment instead of its first root ("expected a fragment starting with but the server rendered a comment") and rebuilt. This also affected keyed @for rows. holdMarkerlessBranch now records each held start against the lists whose items enclose it, and HydrationCapability.refill(list), which forBlock's inline cursor reset becomes, removes the ones that the list's discarded items held as it starts the fill at the server's first item. That matches holdMarkerlessBranch's own contract: "An attempt that is discarded instead leaves the server DOM as it was."

With #1622 (merged) keeping the arm's trailing roots, the reported repro now hydrates to <s>s</s><i>z</i><b>b</b><em>e</em> with the server nodes adopted, no recoverable error and no warning.

The defect was wider than the report: no markerless arm or dynamic component identity is needed for part 1. Any descriptor-list item that suspends with no server seed during deferred activation hit it.

Validation

  • pnpm format:check (not run repo-wide; pnpm format:files:check on the changed files passes)
  • pnpm typecheck (not run repo-wide; pnpm typecheck:files on the 4 changed source/test files passes)
  • pnpm test (not run locally; CI covers it)
  • targeted tests, in both --project octane and --project octane-prod:
  • Regressions fail before the fix, on main 3315f74 (dev and prod compiles):
    • TrailingDescriptor, the exact reported component, in markerless-arm-retry (both the "keeps and owns" and the "replaces while pending" tests).
    • TrailingRow, the same frame as a keyed @for row.
    • "resumes a suspended list item in the server nodes of its list", a createElement list item that suspends with no arm, in deferred-hydration-descriptor.
  • Mutation checks: with buildsList's refill disabled, the descriptor-list and TrailingDescriptor tests fail (5). With refill's hold release disabled, the TrailingDescriptor and TrailingRow "keeps and owns" tests fail (4).
  • After the bundle-size redesign (975b0ce) and the merge of main through fix(hydration): keep a hookless component's signal level below its arms and rows #1616: owning files 85/85 per project; the 21 related files 542/542 per project before that merge.

Risk / follow-ups

  • Hot path / size: the first push's benchmark report showed +22 B raw for tsrx apps and +76 B raw for root-static and JSX bundles, from a renderItem call in mountItem and a guard in renderPreparedChildList. 975b0ce removes both: mountItem and renderPreparedChildList match main again. forBlock's inline reset becomes one hydration.refill(state) call, and childSlot's existing builtByUpdate call becomes buildsList, so a bundle that does not hydrate should be flat or slightly smaller. Hydrating bundles carry refill, buildsList, and a parent-chain walk in holdMarkerlessBranch, which runs only when an arm suspends. Per first fill, refill adds one WeakMap lookup, made only after a hold has occurred. The next benchmark report gives the measured delta.
  • Follow-up (separate defect, flagged as its own task): when a later item of a hydrating list suspends inside a deferred boundary, mountItemsLinear's catch unmounts the completed prefix items with their server DOM. Already-visible server content disappears while pending, and the retry then rebuilds it as a mismatch. This hits compiled @for and descriptor lists alike. It's a different code path (the fill's catch, not the retry's cursor), so it's not in this PR.
  • An abandoned item block from the first attempt still isn't disposed in the hydration path (pre-existing, shared with @for). Its slots never render again.

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 list adoption and DOM cursor recovery on deferred boundaries; wrong behavior could still cause mismatches or stray comment nodes, but scope is narrow and heavily tested.

Overview
Fixes deferred <Hydrate> hydration when descriptor children form a list and the first list item suspends on its initial render. Previously the boundary retry refilled the list from the resumed hydration cursor (inside the item), which triggered structural mismatches, client rebuilds, and duplicated server DOM. The runtime now restarts first-fill adoption from the list’s first server item (refill / buildsList), matching compiled @for behavior.

When a suspended item had inserted markerless @if/@switch hold comments, those start nodes were left behind and confused the retry. holdMarkerlessBranch now tracks per-list holds and refill removes start comments from discarded attempts so the server range stays adoptable.

Tests cover JSX-return descriptor list items (TrailingDescriptor, ListApp) and keyed @for rows (TrailingRow) under the existing markerless-arm retry suite.

Reviewed by Cursor Bugbot for commit fff3f72. Bugbot is set up for automated code reviews on this repo. Configure here.

trueadm and others added 2 commits October 3, 2026 02:05
…tem when a deferred retry refills it

A component that returns JSX passes <Hydrate> its children as descriptors,
so a host's children there hydrate as a list (renderPreparedChildList).
When the first item's first render suspended, mountItemsLinear kept no
items, and the boundary's retry filled the list again from wherever the
resumed render had left the cursor, inside the item. mountItem then found
no item range there, reported a structural list mismatch, discarded the
server content up to the list's end, and rebuilt the item on the client,
duplicating server nodes such as the item's first root. A compiled @for
already restarts its first fill from the server's first item; the
descriptor list now does the same (HydrationCapability.refillList).

The re-adopted item also has to find the server DOM as the server left
it. When a markerless @if or @switch arm suspended inside the item,
holdMarkerlessBranch inserted its start comment there, and the list's
retry, which mounts the item afresh, hit that comment instead of the
arm's first root and rebuilt the arm. That affected compiled @for rows
too. mountItem's hydration path now renders the item through
HydrationCapability.renderItem, which removes the start comments that
the item's attempt held when that render throws, since no slot of the
discarded item renders again.

Hydrating bundles carry the new code in HydrationCapability. A bundle
that does not hydrate keeps one null-guarded call in
renderPreparedChildList.

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 3, 2026
@trueadm
trueadm marked this pull request as ready for review October 3, 2026 01:07
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 2 timed operation(s) possibly slower
  • 🔴 bundle-size: 19 value(s) increased
  • 🔴 bundle-reachability: 17 value(s) increased

Compares 0d91b934a with 809be3d35 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)

target operation base head Δ noise
octane-tsrx select 0.18 0.39 +116.7% ±60% 🟡 slower
octane-tsrx remove 0.51 0.88 +72.5% ±66% 🟡 slower
All 20 timed operations (18 within noise)
target operation base head Δ noise
octane-tsrx run 4.04 5.64 +39.6% ±48% ⚪ within noise
octane-tsrx replace 11.52 14.69 +27.5% ±80% ⚪ within noise
octane-tsrx add 3.90 4.61 +18.2% ±25% ⚪ within noise
octane-tsrx update 0.75 0.96 +28.0% ±64% ⚪ within noise
octane-tsrx select 0.18 0.39 +116.7% ±60% 🟡 slower
octane-tsrx swap 0.63 0.87 +38.1% ±50% ⚪ within noise
octane-tsrx remove 0.51 0.88 +72.5% ±66% 🟡 slower
octane-tsrx runlots 35.79 44.39 +24.0% ±44% ⚪ within noise
octane-tsrx select_lots 0.36 0.36 +0.0% ±49% ⚪ within noise
octane-tsrx clear 58.42 70.25 +20.2% ±59% ⚪ within noise
octane-jsx run 5.20 5.49 +5.6% ±64% ⚪ within noise
octane-jsx replace 15.53 14.97 −3.6% ±45% ⚪ within noise
octane-jsx add 4.67 4.94 +5.8% ±44% ⚪ within noise
octane-jsx update 1.33 1.12 −15.8% ±59% ⚪ within noise
octane-jsx select 0.88 0.89 +1.1% ±57% ⚪ within noise
octane-jsx swap 1.35 1.28 −5.2% ±53% ⚪ within noise
octane-jsx remove 1.14 1.43 +25.4% ±58% ⚪ within noise
octane-jsx runlots 37.22 40.08 +7.7% ±35% ⚪ within noise
octane-jsx select_lots 4.84 4.32 −10.7% ±80% ⚪ within noise
octane-jsx clear 62.71 67.18 +7.1% ±24% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 126,848 126,840 −8 (−0.0%) 🟢
octane-tsrx js_gzip 41,990 41,997 +7 (+0.0%) 🔴
octane-tsrx js_brotli 37,019 37,035 +16 (+0.0%) 🔴
octane-tsrx app_brotli 2,228 2,230 +2 (+0.1%) 🔴
octane-tsrx fw_raw 119,336 119,328 −8 (−0.0%) 🟢
octane-tsrx fw_gzip 39,426 39,433 +7 (+0.0%) 🔴
octane-tsrx fw_brotli 34,791 34,805 +14 (+0.0%) 🔴
octane-tsrx todo_js_raw 142,235 142,227 −8 (−0.0%) 🟢
octane-tsrx todo_js_gzip 47,001 47,010 +9 (+0.0%) 🔴
octane-tsrx todo_js_brotli 41,211 41,238 +27 (+0.1%) 🔴
octane-tsrx todo_app_gzip 2,476 2,477 +1 (+0.0%) 🔴
octane-tsrx todo_app_brotli 2,120 2,123 +3 (+0.1%) 🔴
octane-tsrx todo_fw_raw 137,125 137,117 −8 (−0.0%) 🟢
octane-tsrx todo_fw_gzip 44,525 44,533 +8 (+0.0%) 🔴
octane-tsrx todo_fw_brotli 39,091 39,115 +24 (+0.1%) 🔴
octane-tsrx chat_js_raw 141,444 141,436 −8 (−0.0%) 🟢
octane-tsrx chat_js_gzip 46,947 46,952 +5 (+0.0%) 🔴
octane-tsrx chat_js_brotli 41,283 41,278 −5 (−0.0%) 🟢
octane-tsrx chat_app_gzip 2,979 2,976 −3 (−0.1%) 🟢
octane-tsrx chat_fw_raw 134,791 134,783 −8 (−0.0%) 🟢
octane-tsrx chat_fw_gzip 43,968 43,976 +8 (+0.0%) 🔴
octane-tsrx chat_fw_brotli 38,644 38,639 −5 (−0.0%) 🟢
octane-tsrx weather_js_raw 178,410 178,402 −8 (−0.0%) 🟢
octane-tsrx weather_js_gzip 58,357 58,367 +10 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,832 50,756 −76 (−0.1%) 🟢
octane-tsrx weather_app_gzip 9,046 9,045 −1 (−0.0%) 🟢
octane-tsrx weather_app_brotli 7,578 7,563 −15 (−0.2%) 🟢
octane-tsrx weather_fw_raw 151,675 151,667 −8 (−0.0%) 🟢
octane-tsrx weather_fw_gzip 49,311 49,322 +11 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 43,254 43,193 −61 (−0.1%) 🟢
octane-jsx js_raw 226,723 226,720 −3 (−0.0%) 🟢
octane-jsx js_gzip 72,373 72,376 +3 (+0.0%) 🔴
octane-jsx js_brotli 62,608 62,693 +85 (+0.1%) 🔴
octane-jsx fw_raw 218,264 218,261 −3 (−0.0%) 🟢
octane-jsx fw_gzip 69,438 69,441 +3 (+0.0%) 🔴
octane-jsx fw_brotli 60,113 60,198 +85 (+0.1%) 🔴

9 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 116,540 116,532 −8 (−0.0%) 🟢
cli-spa-starter gzip 39,367 39,374 +7 (+0.0%) 🔴
cli-spa-starter brotli 34,355 34,417 +62 (+0.2%) 🔴
root-static raw 203,051 203,048 −3 (−0.0%) 🟢
root-static gzip 64,566 64,568 +2 (+0.0%) 🔴
root-static brotli 55,912 55,972 +60 (+0.1%) 🔴
hydrate-root raw 172,212 172,763 +551 (+0.3%) 🔴
hydrate-root gzip 54,603 54,756 +153 (+0.3%) 🔴
hydrate-root brotli 47,653 47,724 +71 (+0.1%) 🔴
deferred-hydration raw 235,621 236,172 +551 (+0.2%) 🔴
deferred-hydration gzip 74,502 74,659 +157 (+0.2%) 🔴
deferred-hydration brotli 64,283 64,380 +97 (+0.2%) 🔴
binding-base-ui-vite raw 213,242 213,239 −3 (−0.0%) 🟢
binding-base-ui-vite gzip 68,135 68,137 +2 (+0.0%) 🔴
binding-base-ui-vite brotli 59,058 59,057 −1 (−0.0%) 🟢
binding-base-ui-esbuild raw 211,199 211,196 −3 (−0.0%) 🟢
binding-base-ui-esbuild gzip 68,117 68,119 +2 (+0.0%) 🔴
binding-base-ui-esbuild brotli 59,088 59,070 −18 (−0.0%) 🟢
binding-aria-esbuild brotli 3,012 3,014 +2 (+0.1%) 🔴
binding-radix-vite raw 215,172 215,169 −3 (−0.0%) 🟢
binding-radix-vite gzip 68,707 68,709 +2 (+0.0%) 🔴
binding-radix-vite brotli 59,620 59,589 −31 (−0.1%) 🟢
binding-radix-esbuild raw 213,089 213,086 −3 (−0.0%) 🟢
binding-radix-esbuild gzip 68,699 68,701 +2 (+0.0%) 🔴
binding-radix-esbuild brotli 59,594 59,575 −19 (−0.0%) 🟢
binding-apollo-client-vite raw 358,297 358,294 −3 (−0.0%) 🟢
binding-apollo-client-vite gzip 112,261 112,264 +3 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,937 97,914 −23 (−0.0%) 🟢
binding-apollo-client-esbuild raw 361,246 361,243 −3 (−0.0%) 🟢
binding-apollo-client-esbuild gzip 114,470 114,472 +2 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,711 99,638 −73 (−0.1%) 🟢

74 other measured values are unchanged.

trueadm and others added 2 commits October 3, 2026 02:24
The benchmark report showed the fix adding bytes to every bundle that
renders lists (+22 B raw for tsrx apps, +76 B raw for root-static and
JSX bundles): mountItem called hydration.renderItem instead of
renderBlock, and renderPreparedChildList gained a guard for refillList.

Move both parts behind call sites that already exist:
- holdMarkerlessBranch records each held start against the lists whose
  items enclose it (rare: only when an arm suspends), and
  HydrationCapability.refill(list) removes the ones the list's discarded
  items held as it starts a first fill at the server's first item.
  forBlock's inline cursor reset becomes that call.
- childSlot's existing builtByUpdate check becomes buildsList, which
  also refills a descriptor list that kept no items.

mountItem and renderPreparedChildList are unchanged from main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 11a9da9 into main Oct 3, 2026
31 checks passed
@trueadm
trueadm deleted the fix/descriptor-hydrate-held-arm branch October 3, 2026 07:25
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