Skip to content

fix(hydration): adopt the server's node at a renderable hole in a fragment adopted in place - #1613

Merged
trueadm merged 4 commits into
mainfrom
claude/agitated-euclid-d38c1e
Oct 3, 2026
Merged

trueadm merged 4 commits into
mainfrom
claude/agitated-euclid-d38c1e

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A component call with no server range of its own adopts its fragment template in place of the raw markup the server rendered for another @if arm or component (renderInPlace → adopt()'s in-place fragment branch → fragmentRemainder; prod goes through renderUnframed(…, unframed = true)). The server frames every renderable hole's value as <!--[-->…<!--]-->, but that raw markup frames none. A {value} hole's compiled walk therefore found a bare server node where its own placeholder belongs. childSlot took that node as the slot's end marker:

  • A text hole duplicated the server's text. Server <p>p</p><em>e</em>x, client <Para/> + <EmText text="x"/>. EmText is @{ <><em>{'e'}</em>{props.text}</> }. The section read …<em>e</em>xx, in both the dev and prod compiles.
  • A {null} hole counted as owning a server node. Server <p>p</p><em>e</em><s class="tail">s</s>, client <Para/> + <EmNull/>. fragmentRemainder stepped one server node for the hole, so <s> was treated as fragment content. It stayed unreported in dev, and prod's renderUnframed framed it inside the call's <!--comp-->…<!--/comp-->.
  • The same duplication hit a text hole followed by another root (<em/>{text}<i/>). An element value at the fragment's last root built a fresh element.

Changes

  • New HydrationCapability.holeOpen. It replaces childSlot's existing hydration isOpen(anchor) test and returns the open marker the hole adopts. That is the server's own marker when it framed the hole. Only inside a template adopted in place (inPlaceEnd !== undefined), it instead wraps what the server rendered for the hole in fresh [/] markers, as the server would have. The hole then adopts that range through the ordinary path: claimRange, discardUnadoptedText, text adoption. Non-hydrating bundles keep their raw size, because the call replaces the old isOpen test rather than adding a new one.
    • A hole before another root holds the one node the compiled walk counts for it. Each root after it was already matched against the next node.
    • The fragment's last root holds its node only when that node is the kind the value renders: text for a primitive, an element for an object. Otherwise the server rendered nothing for the hole. The fragment's server nodes then end before that node, and the enclosing claim removes and reports the node as the stale tail.
  • fragmentRemainder (bounded, in-place only) records the server node at a last-root hole as inPlaceHole. renderInPlace saves and restores it with the other in-place state.

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 passes on runtime.ts, the test, and the .tsrx fixture.
  • pnpm test: not run in full; CI covers it.
  • targeted tests:
    • New tests/hydration/in-place-fragment-holes.test.ts. It covers dev compile, prod compile, and prod compile with prod runtime, in the octane and octane-prod projects.
      • On main, 30 of 60 fail: every non-control case. The controls pass.
      • With this change, 56 of 60 pass. See the dependency below.
    • Each part of the fix was mutated in turn, and each mutation fails the suite: the childSlot call, the trailing end correction, the trailing-hole record, and the text and element rules.
    • The in-place, unframed, fragment, arm, tail, hole, sibling, range, lite, mismatch, rebuilt and split hydration suites pass in both projects on the pre-rebase base. After rebasing onto fix(hydration): replace exactly the server node at a component hole in another arm's adopted nodes #1603, 33 of them pass again in octane. The rest of tests/hydration (94 files) passes in octane.
    • Size, measured with benchmarks/bundle-size/run-minimal.mjs:
      • hydrate-root and deferred-hydration: +549 B raw / about +157 B gzip.
      • root-static: +0 B raw, +8 B gzip, −28 B brotli. The gzip and brotli changes come from the reshaped childSlot condition. context, hooks-state, root-chained-jsx and suspense-transition: 0.
      • The first push added 13 B raw to every bundle with a child slot. The second commit removes it by folding the call into the existing isOpen test.
      • Main already exceeds the committed budgets for these bundles.
    • Timing benchmarks were not run locally. In normal hydration the change adds one early-returning method call per hole's first render.

Risk / follow-ups

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/range adoption in runtime.ts; wrong framing could cause mismatches or DOM loss, but behavior is covered by new hydration tests.

Overview
Fixes hydration when a fragment is adopted in place (renderInPlace) and the server left renderable holes unframed (raw text/elements instead of <!--[-->…<!--]-->).

The runtime adds holeOpen, used from childSlot instead of only checking isOpen(anchor). Inside an in-place template it can wrap the server’s bare node in hydration markers so {value} holes reuse that text or element (no duplicate text) and update in place. inPlaceHole plus fragmentRemainder track the server node at a last-root hole so {null} does not treat the following sibling as fragment content—stale tail nodes are removed and reported once.

Adds in-place-fragment-holes fixture/tests (dev/prod compile and runtime) and an octane patch changeset.

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

…gment adopted in place

A component call with no server range of its own adopts its fragment
template in place of the raw markup the server rendered for another arm or
component. The server frames every renderable hole's value in a range, but
that markup frames none, so a {value} hole's walk found the server's bare
text, or the node after the fragment, where its own placeholder belongs.
childSlot took that server node as the slot's end marker: a text hole
inserted a second copy of the server's text before it, and a {null} hole
that is the fragment's last root made the next server node its end, while
fragmentRemainder counted that node as the fragment's content, so it stayed
on screen without a report.

HydrationCapability.frameHole frames what the server rendered for such a
hole, as the server would have, and the hole adopts that range through the
ordinary path. A hole before another root holds the one node the compiled
walk counts for it. The fragment's last root (recorded by fragmentRemainder
as inPlaceHole) holds its node only when the value renders that kind of
node; otherwise the fragment's server nodes end before it, and what follows
is the stale tail the enclosing claim removes and reports once.

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:19
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 5 value(s) increased
  • 🔴 bundle-reachability: 19 value(s) increased

Compares bc30a18ac with c9d064868 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.91 4.34 +11.0% ±85% ⚪ within noise
octane-tsrx replace 8.27 7.50 −9.3% ±19% ⚪ within noise
octane-tsrx add 3.79 3.52 −7.1% ±14% ⚪ within noise
octane-tsrx update 0.48 0.42 −12.5% ±46% ⚪ within noise
octane-tsrx select 0.20 0.17 −15.0% ±75% ⚪ within noise
octane-tsrx swap 0.36 0.37 +2.8% ±33% ⚪ within noise
octane-tsrx remove 0.40 0.33 −17.5% ±52% ⚪ within noise
octane-tsrx runlots 34.23 33.13 −3.2% ±17% ⚪ within noise
octane-tsrx select_lots 0.16 0.16 −0.0% ±81% ⚪ within noise
octane-tsrx clear 33.95 33.91 −0.1% ±29% ⚪ within noise
octane-jsx run 4.07 4.06 −0.2% ±46% ⚪ within noise
octane-jsx replace 7.44 7.12 −4.3% ±9% ⚪ within noise
octane-jsx add 3.34 3.37 +0.9% ±9% ⚪ within noise
octane-jsx update 0.49 0.50 +2.0% ±29% ⚪ within noise
octane-jsx select 0.38 0.37 −2.6% ±31% ⚪ within noise
octane-jsx swap 0.64 0.59 −7.8% ±54% ⚪ within noise
octane-jsx remove 0.48 0.50 +4.2% ±20% ⚪ within noise
octane-jsx runlots 31.13 32.85 +5.5% ±17% ⚪ within noise
octane-jsx select_lots 2.51 2.81 +12.0% ±28% ⚪ within noise
octane-jsx clear 35.29 38.55 +9.2% ±13% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-jsx js_gzip 72,348 72,360 +12 (+0.0%) 🔴
octane-jsx js_brotli 62,648 62,690 +42 (+0.1%) 🔴
octane-jsx app_gzip 2,935 2,937 +2 (+0.1%) 🔴
octane-jsx app_brotli 2,504 2,500 −4 (−0.2%) 🟢
octane-jsx fw_gzip 69,413 69,423 +10 (+0.0%) 🔴
octane-jsx fw_brotli 60,144 60,190 +46 (+0.1%) 🔴

39 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
root-static gzip 64,546 64,554 +8 (+0.0%) 🔴
root-static brotli 55,931 55,950 +19 (+0.0%) 🔴
hydrate-root raw 169,792 170,341 +549 (+0.3%) 🔴
hydrate-root gzip 53,980 54,142 +162 (+0.3%) 🔴
hydrate-root brotli 47,098 47,205 +107 (+0.2%) 🔴
deferred-hydration raw 233,193 233,742 +549 (+0.2%) 🔴
deferred-hydration gzip 73,863 74,028 +165 (+0.2%) 🔴
deferred-hydration brotli 63,775 63,914 +139 (+0.2%) 🔴
binding-base-ui-vite gzip 68,115 68,122 +7 (+0.0%) 🔴
binding-base-ui-vite brotli 58,987 59,025 +38 (+0.1%) 🔴
binding-base-ui-esbuild gzip 68,099 68,106 +7 (+0.0%) 🔴
binding-base-ui-esbuild brotli 59,050 59,103 +53 (+0.1%) 🔴
binding-radix-vite gzip 68,687 68,695 +8 (+0.0%) 🔴
binding-radix-vite brotli 59,445 59,532 +87 (+0.1%) 🔴
binding-radix-esbuild gzip 68,683 68,687 +4 (+0.0%) 🔴
binding-radix-esbuild brotli 59,604 59,539 −65 (−0.1%) 🟢
binding-apollo-client-vite gzip 112,241 112,249 +8 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,903 98,041 +138 (+0.1%) 🔴
binding-apollo-client-esbuild gzip 114,448 114,459 +11 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,691 99,704 +13 (+0.0%) 🔴

85 other measured values are unchanged.

…ts for an open marker

The benchmark report showed +13 raw bytes in every bundle with a child slot,
including ones that never hydrate (root-static, octane-jsx), from the extra
arguments at frameHole's call site. HydrationCapability.holeOpen now replaces
the existing isOpen(anchor) test there: it returns the server's open marker,
the frame it gives a hole in a template adopted in place, or null, so the
branch no longer reassigns the anchor and non-hydrating bundles keep their
size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 22:36
@trueadm
trueadm merged commit 0b833bb into main Oct 3, 2026
30 checks passed
@trueadm
trueadm deleted the claude/agitated-euclid-d38c1e branch October 3, 2026 00:20
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