Skip to content

fix(octane): discard server text an only-child hole's element value cannot adopt - #1430

Merged
trueadm merged 3 commits into
mainfrom
claude/lucid-wilson-02a98d
Sep 29, 2026
Merged

trueadm merged 3 commits into
mainfrom
claude/lucid-wilson-02a98d

Conversation

@trueadm

@trueadm trueadm commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Hydrating a renderable {expr} hole that is its host element's only child mishandled server text when the client value is an element, a component, or a list:

function pick(k, v) { return k === 'p' ? createElement('p', null, v) : v; }
export function Hole(props) @{ <section><div>{pick(props.kind, props.v)}</div><b>{props.tail}</b></section> }

Server {kind:'text'}, hydrate {kind:'p'}:

  • Root component: childTextHole pointed the cursor at the bare server text and called childSlot. Its root-return branch read that as a mismatched root and called abandonRoot, so the later only-child hole rendered <b>tt</b>. The dev warning also blamed "a renderable root".
  • Nested component: the value mounted beside the server text (<div>A<!----><p>A</p><!----></div>), and nothing reached onRecoverableError. A list value warned twice but still didn't report.
  • Server rendered nothing and the client value is an object: in the root component this also abandoned the root.

Fix: HydrationCapability.hydrateOnlyChild in packages/octane/src/runtime.ts.

  • If the host starts with the server's <!--[--> range, the slot adopts it, as before.
  • Otherwise the server rendered text or nothing for a primitive, and none of these values can adopt it. The method discards that content and reports once to onRecoverableError (code 51). In dev it warns with the hole's siteLoc. It then builds the value exactly as a client mount would, with hydration suspended for that slot, so the rest of the root keeps hydrating.
  • Textarea: the server text is the textarea's default value, owned by its value props, so it stays. This matches the empty-value sibling fix.
  • Dormant <Hydrate> boundary whose props changed before it activated (staleServerValues): the hole is repaired without a report.
  • Empty server host: the value builds silently, as htext does for missing text.

Both lowerings reach this path: the plain one (childTextHoleUpdate) and the signal one (bindSignalChild with onlyChild). So do .tsrx and .tsx.

Two things a reviewer should know

  1. Suspense retries. If the client value suspends, the boundary's next attempt runs under a new HydrationCapability, and by design it re-adopts the DOM the failed attempt left. Per-capability freshness can't tell that DOM apart from server content. Without handling this, a retry reported a second mismatch and duplicated the element inside a textarea. A lazily created module-level WeakSet records the first node each build produces (in a finally, since a suspension throws out of the build), and a retry drops that node silently.
  2. Bundle reachability. The childSlot call is passed in as a callback. Naming childSlot from the hydration class retained the whole child-slot graph in every hydrating bundle: hydrate-root grew by about 111 KB raw in a first draft.

Validation

  • pnpm format:check (repo-wide): not run. pnpm format:files:check is clean on every changed file.
  • pnpm typecheck (repo-wide): not run. pnpm typecheck:files passes for runtime.ts and the three fixtures. The test file shows only errors that already exist in untouched lines (untyped .map((c) => …) callbacks).
  • pnpm test: the unsharded local run hits a V8 heap out-of-memory in the Vitest main process, a known limitation of this machine. I ran the CI shard config locally instead. Before the merge with main, shard 2/4 passed. Shard 1/4 passed apart from two packages/cli tests that timed out at 5 s under load; both pass on their own (24/24). I stopped shards 3/4 and 4/4 to merge main, so CI is the evidence for them.
  • targeted tests on the merged head: every packages/octane/tests file in the octane and octane-prod projects passes (1,231 files, 25,256 tests).
    • 49 new tests in tests/hydration/mismatch-structural.test.ts; 27 of them fail before the fix. They cover dev and prod compile, root and nested, element, component and list values, a matching value adopting silently, an empty server host, a textarea, .tsx, bindSignalChild, a dormant boundary, and a value that suspends.
    • Deliberately breaking the textarea branch, the dormant-boundary silence, the suspended build, or the retry bookkeeping turns tests red.
  • Bundle size (benchmarks/bundle-size/run-minimal.mjs, against the pre-change runtime): hydrate-root +429 B raw / +118 B gzip / +123 B brotli; deferred-hydration +429 / +100 / +59. The client-only scenarios (cli-spa-starter, root-static-local, hooks-state, suspense-transition) are byte-identical. The CI-enforced --budgets set passes.

Risk / follow-ups

  • The hot path is unchanged. Client renders take the same childSlot call, and the new branch runs only on a hydrating first render of an object-valued only-child hole.
  • An empty server host with an object client value is recovered silently, consistent with htext. React would report it. Worth a follow-up decision if the policy should tighten.
  • The text→empty sibling fix (fix(octane): discard stale server text for an empty only-child hole #1426, hempty) has landed and is merged in here. Its method sits next to hydrateOnlyChild, and both suites pass together. The framed element→text work (discardUnadoptedText) is still in flight and touches the same area.
  • Found while probing; not fixed here:

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 first-render hydration for a narrow but user-visible DOM mismatch path; behavior is well-tested but incorrect recovery previously corrupted roots or duplicated text.

Overview
Fixes hydration when a markerless only-child {expr} hole was server-rendered as bare text but the client first renders an element, component, or list.

HydrationCapability.hydrateOnlyChild (wired from childTextHole on the hydrating object-value path) either adopts the server <!--[--> range as before, or strips stale server text, fires onRecoverableError once (dev warns at the hole’s siteLoc), and mounts the client value without abandoning the rest of the root. HYDRATION_BUILT_CONTENT avoids double-report/duplicate DOM on suspense retries; textarea keeps server text as default value; dormant <Hydrate> with staleServerValues repairs silently.

Adds fixtures and a large mismatch-structural.test.ts suite (dev/prod, root/nested, suspense, signals, TSX).

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

trueadm and others added 2 commits September 29, 2026 22:07
…annot adopt

A renderable `{expr}` hole that is its host's only child serializes a
primitive as the host's bare text and frames an element, a component, or a
list in a `<!--[-->…<!--]-->` range. When the server rendered text but the
client value is one of those, childTextHole pointed the cursor at that text
and called childSlot. In the root component, childSlot's root-return branch
abandoned hydration for the rest of the root, so a later only-child hole
rendered its text twice and the dev warning blamed "a renderable root". In
a nested component the value mounted beside the server text unreported.

HydrationCapability.hydrateOnlyChild now adopts the server's range when
there is one. Otherwise it discards the host's server content, reports the
recovery once with the hole's source location, and builds the value as a
client mount would under suspended hydration, so the rest of the root keeps
hydrating. A textarea keeps its server text as its default value, and a
dormant boundary whose captures changed repairs the hole silently. The
first node the hole builds is remembered across Suspense retry attempts,
which run under a new capability, so a value that suspends is reported and
built once. The childSlot call is passed in as a callback: naming it from
the hydration class would retain the whole child-slot graph in every
hydrating bundle.

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 Sep 29, 2026
@github-actions
github-actions Bot marked this pull request as draft September 29, 2026 21:12
@trueadm
trueadm marked this pull request as ready for review September 29, 2026 21:41
…2a98d

# Conflicts:
#	packages/octane/src/runtime.ts
#	packages/octane/tests/hydration/mismatch-structural.test.ts
@trueadm
trueadm merged commit 25cc659 into main Sep 29, 2026
30 checks passed
@trueadm
trueadm deleted the claude/lucid-wilson-02a98d branch September 29, 2026 23:00
trueadm added a commit that referenced this pull request Sep 29, 2026
HTML tag names are ASCII case-insensitive, and ssrHostElement folds a
descriptor textarea's children on the lowercased tag. The client compared
the authored type exactly, so `createElement('TEXTAREA', null, 'a', list)`
still reconciled its children as a keyed list and left range comments
inside the textarea. Both de-opt paths now share a case-insensitive check
that compares the string before any DOM read.

With main merged, the only-child hole tests from #1430 expected an element
value inside a textarea to render beside the server text. A textarea's
children are text on both sides now, so that case asserts the error on the
server and through onUncaughtError on the client, and the suspending-hole
fixture no longer puts an element in a textarea.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Sep 29, 2026
…ides (#1435)

* fix(octane): render a textarea's children as one text value on both sides

Textarea content is RCDATA: the HTML parser keeps markup and comments inside
it as literal text. A textarea with more than one child compiled to a client
template with `<!>` placeholders inside the textarea (a client-only mount
threw reading `parentNode` of null) and a server frame such as
`hello <!-- -->A`, so the pre-hydration value held the markers and hydration
reported a mismatch or rebuilt the root.

A textarea's children now fold into one text value. The compiler binds it as
the host's only Text node through `textareaText` and the server serializes it
markerless through `ssrTextareaText`. Descriptor textareas (createElement,
stored JSX) and a children prop from a spread follow the same rule. Strings and
numbers render, empty values render nothing, arrays and iterables join, and any
other value throws error 336 on both sides. Markup or a template directive
written inside a textarea is a compile error. Signal handles in a compiled
textarea's holes stay live through one derived handle over the parts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(octane): update mixed children of a spread textarea after hydration

The spread textarea default reset is fixed on main (#1432), so the spread
cases now join the shared mount, hydrate and update matrix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(octane): fold a de-opt textarea's children whatever its tag's case

HTML tag names are ASCII case-insensitive, and ssrHostElement folds a
descriptor textarea's children on the lowercased tag. The client compared
the authored type exactly, so `createElement('TEXTAREA', null, 'a', list)`
still reconciled its children as a keyed list and left range comments
inside the textarea. Both de-opt paths now share a case-insensitive check
that compares the string before any DOM read.

With main merged, the only-child hole tests from #1430 expected an element
value inside a textarea to render beside the server text. A textarea's
children are text on both sides now, so that case asserts the error on the
server and through onUncaughtError on the client, and the suspending-hole
fixture no longer puts an element in a textarea.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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