Repository navigation
fix(hydration): discard the server tail after a last call adopted in place - #1615
Merged
Merged
Conversation
…place When a component's adopted server range holds raw markup the server rendered for another component, and the client's content there is a sequence of calls without server ranges of their own, each call adopts its server node in place. No template adopts the range's first node, so settleClaim falls back to the last slot's range end, which an in-place slot does not have, and the server markup after the last call's nodes stayed on screen unreported. parkInPlace now records which slot adopted in place and where it parked the cursor. settleClaim treats that position as the last slot's end when the last slot is the one that parked there and the cursor has not moved, then removes and reports the tail once (code 51). The single-root path of componentSlotImpl parks through parkInPlace, since renderInPlace already stepped the cursor past the adopted root. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 22:21
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)
31 other measured values are unchanged. Public-import reachability bundles (bytes)
80 other measured values are unchanged. |
This was referenced Oct 2, 2026
Merged
4 of 5 tasks
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
Hydration now removes the server markup left after a component's last call when that call adopted its server node in place. It reports that markup once.
Repro: the server renders
RawParaEm(<p>,<em>,<s class="tail">) in a component's range, and the client rendersParaEm, which is two calls,<Para />and<Em />, with no server ranges of their own. Each call adopts its server element in place. Before this fix, the section kept<s>on screen and nothing was reported, in both dev and prod compiles. The same happened when the first call's root was rebuilt (server<b>instead of<p>).Cause: no template adopts the range's first node, so
endClaimreturns undefined andHydrationCapability.settleClaimfalls back to its last-slot heuristic. That heuristic needs the last slot's own range end, and a slot that adopted in place has none, sosettleClaimleft the tail.Changes
parkInPlace(parent, slot)records which slot adopted server nodes in place and where it parked the cursor (inPlaceSlot/inPlaceTail).renderLiteInPlacepasses its lite scope.componentSlotImpl's single-root in-place path now parks throughparkInPlace(parentScope, state)instead ofparkPast(hydrationCursor, …). The cursor ends in the same place, becauserenderInPlacealready stepped it past the adopted root.settleClaim: when the owner's last slot is the one that parked in place, and the cursor is still where it parked, that position is the start of the tail. Otherwise the existing range-end check runs unchanged.renderInPlaceparks after the fragment's last root. The test's fragment case checks this.".Validation
pnpm format:check: not run repo-wide.pnpm format:files:checkpasses on the 4 changed files.pnpm typecheck: not run repo-wide.pnpm typecheck:filespasses onruntime.ts, the test and the.tsrxfixture.pnpm test: not run in full. See the targeted runs below.tests/hydration/in-place-tail.test.ts: 60/60 inoctaneandoctane-prod, across dev compile, prod compile, and prod compile with the prod runtime.renderUnframed.tests/hydration/directory inoctaneon the rebased head: 6800 passed and 6 failed, all 6 inreturned-jsx-query-resume.test.ts. That file fails identically with this PR's runtime reverted, and it fails in main's own CI at6ea582e37c, so it is not caused by this change.ad125250ed), the directory passed in full: 141 files, 6586 tests.benchmarks/bundle-size/run-minimal.mjs, production):hydrate-root+149 B raw / +39 B gzip,deferred-hydration+152 B raw / +42 B gzip,root-static+3 B raw / 0 B gzip,hooks-stateunchanged.settleClaim, all on cold hydration paths, so no runtime benchmark was run.root-staticbyte budget already fails on main.Risk / follow-ups
returned-jsx-query-resume.test.ts, so this PR's test shards will fail on that file until main is fixed.cursor === inPlaceTailcheck is defensive. No hydration path found moves the cursor between the last slot's park and the settle, so a mutation that removes it survives.settleClaim's doc comment conflicts.{null}hole is treated as owning the next server node.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 cursor/settlement logic on cold paths; behavior change is narrow (in-place adoption tails) but incorrect settlement could drop or keep wrong DOM.
Overview
Fixes hydration leaving stale server DOM after the last child call when earlier calls adopt server nodes in place (
renderInPlace) and the server had extra markup past those roots.parkInPlacenow records which slot adopted in place and where the cursor parked (inPlaceSlot/inPlaceTail); lite and full single-root paths pass the adopting slot.settleClaimuses that when the owner’s last slot has no range end, so it can strip the tail and fire the existing recoverable mismatch (error #51 / dev “expected end of component”) once, without replacing adopted nodes.Adds
in-place-tailfixture and tests across dev/prod compile and runtime (hooks, fragments, renderable holes, rebuilt-first-root).Reviewed by Cursor Bugbot for commit c5f3043. Bugbot is set up for automated code reviews on this repo. Configure here.