Skip to content

fix(hydration): discard the server tail after a last call adopted in place - #1615

Merged
trueadm merged 2 commits into
mainfrom
claude/fervent-cray-1cd324
Oct 3, 2026
Merged

trueadm merged 2 commits into
mainfrom
claude/fervent-cray-1cd324

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

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 renders ParaEm, 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 endClaim returns undefined and HydrationCapability.settleClaim falls 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, so settleClaim left the tail.

Changes

  • parkInPlace(parent, slot) records which slot adopted server nodes in place and where it parked the cursor (inPlaceSlot / inPlaceTail). renderLiteInPlace passes its lite scope.
  • componentSlotImpl's single-root in-place path now parks through parkInPlace(parentScope, state) instead of parkPast(hydrationCursor, …). The cursor ends in the same place, because renderInPlace already 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.
  • A fragment adopted in place keeps every node it adopted: since fix(hydration): adopt an unframed fragment component and continue after its last root #1597, renderInPlace parks after the fragment's last root. The test's fragment case checks this.
  • The tail is reported through the existing adopted-component-tail contract from fix(hydration): discard the server tail of an adopted component range #1576: recoverable error code 51, plus the dev warning "the client expected the end of the component but the server rendered ".

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check passes on the 4 changed files.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files passes on runtime.ts, the test and the .tsrx fixture.
  • pnpm test: not run in full. See the targeted runs below.
  • targeted tests:
    • New tests/hydration/in-place-tail.test.ts: 60/60 in octane and octane-prod, across dev compile, prod compile, and prod compile with the prod runtime.
    • Before the fix, 26 of 60 failed, each because the server tail stayed. The prod-compile fragment case already passed on main, through renderUnframed.
    • Mutations caught: dropping the slot record on the lite path fails 8 tests; dropping it on the full single-root path fails 18.
    • Whole tests/hydration/ directory in octane on the rebased head: 6800 passed and 6 failed, all 6 in returned-jsx-query-resume.test.ts. That file fails identically with this PR's runtime reverted, and it fails in main's own CI at 6ea582e37c, so it is not caused by this change.
    • Before rebasing (main at ad125250ed), the directory passed in full: 141 files, 6586 tests.
  • Bundle size (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-state unchanged.
    • The new cost is two field writes per in-place adoption and one identity check in settleClaim, all on cold hydration paths, so no runtime benchmark was run.
    • The root-static byte budget already fails on main.

Risk / follow-ups

  • Main CI is currently red on returned-jsx-query-resume.test.ts, so this PR's test shards will fail on that file until main is fixed.
  • Still conservative, and unchanged from main:
    • A last slot that is a template-less wrapper around in-place calls leaves the tail.
    • So does an empty lite call in a dev build.
    • In both cases nothing proves where the last slot's server nodes end.
  • The cursor === inPlaceTail check 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.
  • Composes with the pending rebuilt-root-tail fix (uncommitted in another session): with both runtime diffs applied, both suites pass 186/186. Only settleClaim's doc comment conflicts.
  • Separate pre-existing defects found while probing, worked in another session: in a fragment adopted in place, a trailing text hole duplicates the server text, and a {null} hole is treated as owning the next server node.

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 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.

parkInPlace now records which slot adopted in place and where the cursor parked (inPlaceSlot / inPlaceTail); lite and full single-root paths pass the adopting slot. settleClaim uses 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-tail fixture 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.

…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]>
@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 22:21
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 22:21
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 7 value(s) increased
  • 🔴 bundle-reachability: 18 value(s) increased

Compares 62e76bfff with 5605327b3 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 3.70 3.49 −5.7% ±15% ⚪ within noise
octane-tsrx replace 8.72 7.84 −10.1% ±41% ⚪ within noise
octane-tsrx add 3.78 3.43 −9.3% ±31% ⚪ within noise
octane-tsrx update 0.45 0.48 +6.7% ±48% ⚪ within noise
octane-tsrx select 0.20 0.18 −10.0% ±90% ⚪ within noise
octane-tsrx swap 0.39 0.35 −10.3% ±32% ⚪ within noise
octane-tsrx remove 0.35 0.36 +2.9% ±50% ⚪ within noise
octane-tsrx runlots 30.63 31.81 +3.9% ±25% ⚪ within noise
octane-tsrx select_lots 0.25 0.24 −4.0% ±38% ⚪ within noise
octane-tsrx clear 42.49 41.19 −3.1% ±15% ⚪ within noise
octane-jsx run 3.66 3.65 −0.3% ±12% ⚪ within noise
octane-jsx replace 7.04 7.40 +5.1% ±28% ⚪ within noise
octane-jsx add 3.27 3.20 −2.1% ±7% ⚪ within noise
octane-jsx update 0.56 0.59 +5.4% ±47% ⚪ within noise
octane-jsx select 0.38 0.38 −0.0% ±37% ⚪ within noise
octane-jsx swap 0.72 0.69 −4.2% ±35% ⚪ within noise
octane-jsx remove 0.67 0.61 −9.0% ±65% ⚪ within noise
octane-jsx runlots 28.72 29.43 +2.5% ±10% ⚪ within noise
octane-jsx select_lots 2.35 2.66 +13.2% ±20% ⚪ within noise
octane-jsx clear 41.62 43.09 +3.5% ±11% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx weather_js_raw 178,401 178,404 +3 (+0.0%) 🔴
octane-tsrx weather_js_gzip 58,321 58,320 −1 (−0.0%) 🟢
octane-tsrx weather_js_brotli 50,754 50,823 +69 (+0.1%) 🔴
octane-tsrx weather_app_gzip 9,045 9,044 −1 (−0.0%) 🟢
octane-tsrx weather_app_brotli 7,590 7,580 −10 (−0.1%) 🟢
octane-tsrx weather_fw_raw 151,666 151,669 +3 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 43,164 43,243 +79 (+0.2%) 🔴
octane-jsx js_raw 226,720 226,723 +3 (+0.0%) 🔴
octane-jsx js_gzip 72,349 72,348 −1 (−0.0%) 🟢
octane-jsx js_brotli 62,708 62,648 −60 (−0.1%) 🟢
octane-jsx app_gzip 2,936 2,935 −1 (−0.0%) 🟢
octane-jsx app_brotli 2,499 2,504 +5 (+0.2%) 🔴
octane-jsx fw_raw 218,261 218,264 +3 (+0.0%) 🔴
octane-jsx fw_brotli 60,209 60,144 −65 (−0.1%) 🟢

31 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
root-static raw 203,048 203,051 +3 (+0.0%) 🔴
root-static brotli 55,970 55,931 −39 (−0.1%) 🟢
context raw 110,856 110,859 +3 (+0.0%) 🔴
context brotli 32,499 32,483 −16 (−0.0%) 🟢
hydrate-root raw 169,643 169,792 +149 (+0.1%) 🔴
hydrate-root gzip 53,945 53,980 +35 (+0.1%) 🔴
hydrate-root brotli 47,135 47,098 −37 (−0.1%) 🟢
deferred-hydration raw 233,041 233,193 +152 (+0.1%) 🔴
deferred-hydration gzip 73,828 73,863 +35 (+0.0%) 🔴
deferred-hydration brotli 63,686 63,775 +89 (+0.1%) 🔴
suspense-transition raw 167,387 167,390 +3 (+0.0%) 🔴
suspense-transition brotli 47,008 47,025 +17 (+0.0%) 🔴
binding-base-ui-vite raw 213,239 213,242 +3 (+0.0%) 🔴
binding-base-ui-vite gzip 68,114 68,115 +1 (+0.0%) 🔴
binding-base-ui-vite brotli 59,009 58,987 −22 (−0.0%) 🟢
binding-base-ui-esbuild raw 211,196 211,199 +3 (+0.0%) 🔴
binding-base-ui-esbuild brotli 59,109 59,050 −59 (−0.1%) 🟢
binding-radix-vite raw 215,169 215,172 +3 (+0.0%) 🔴
binding-radix-vite brotli 59,582 59,445 −137 (−0.2%) 🟢
binding-radix-esbuild raw 213,086 213,089 +3 (+0.0%) 🔴
binding-radix-esbuild brotli 59,505 59,604 +99 (+0.2%) 🔴
binding-apollo-client-vite raw 358,294 358,297 +3 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,935 97,903 −32 (−0.0%) 🟢
binding-apollo-client-esbuild raw 361,243 361,246 +3 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,681 99,691 +10 (+0.0%) 🔴

80 other measured values are unchanged.

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