Repository navigation
fix(hydration): adopt a descriptor list again from its first server item when a deferred retry refills it - #1624
Merged
Merged
Conversation
…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]>
trueadm
marked this pull request as ready for review
October 3, 2026 01:07
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)
All 20 timed operations (18 within noise)
Application bundle size (bytes)
9 other measured values are unchanged. Public-import reachability bundles (bytes)
74 other measured values are unchanged. |
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]>
This was referenced Oct 3, 2026
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
Hydrating a deferred
<Hydrate>boundary whose children are descriptors (a component that uses plainreturnJSX, 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:
<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.mountItemfound 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@foralready 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 existingbuiltByUpdatecheck becomesHydrationCapability.buildsList, which also refills a retained list that kept no items (refill).@if/@switcharm suspended inside it,holdMarkerlessBranchhad inserted its start comment there. The fresh arm then found that comment instead of its first root ("expected a fragment starting withbut the server rendered a comment") and rebuilt. This also affected keyed@forrows.holdMarkerlessBranchnow records each held start against the lists whose items enclose it, andHydrationCapability.refill(list), whichforBlock'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 matchesholdMarkerlessBranch'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:checkon the changed files passes)pnpm typecheck(not run repo-wide;pnpm typecheck:fileson the 4 changed source/test files passes)pnpm test(not run locally; CI covers it)--project octaneand--project octane-prod:markerless-arm-retry.test.tsanddeferred-hydration-descriptor.test.ts: 85/85 per project, also on the merge with main at perf(hydration): keep the streamed-boundary validator out of client-only @try apps #1623.TrailingDescriptor, the exact reported component, inmarkerless-arm-retry(both the "keeps and owns" and the "replaces while pending" tests).TrailingRow, the same frame as a keyed@forrow.createElementlist item that suspends with no arm, indeferred-hydration-descriptor.buildsList's refill disabled, the descriptor-list andTrailingDescriptortests fail (5). Withrefill's hold release disabled, theTrailingDescriptorandTrailingRow"keeps and owns" tests fail (4).Risk / follow-ups
renderItemcall inmountItemand a guard inrenderPreparedChildList. 975b0ce removes both:mountItemandrenderPreparedChildListmatch main again.forBlock's inline reset becomes onehydration.refill(state)call, andchildSlot's existingbuiltByUpdatecall becomesbuildsList, so a bundle that does not hydrate should be flat or slightly smaller. Hydrating bundles carryrefill,buildsList, and a parent-chain walk inholdMarkerlessBranch, which runs only when an arm suspends. Per first fill,refilladds one WeakMap lookup, made only after a hold has occurred. The next benchmark report gives the measured delta.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@forand 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.@for). Its slots never render again.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 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@forbehavior.When a suspended item had inserted markerless
@if/@switchhold comments, those start nodes were left behind and confused the retry.holdMarkerlessBranchnow tracks per-list holds andrefillremoves start comments from discarded attempts so the server range stays adoptable.Tests cover JSX-return descriptor list items (
TrailingDescriptor,ListApp) and keyed@forrows (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.