Skip to content

fix(octane): discard stale server text for an empty only-child hole - #1426

Merged
trueadm merged 2 commits into
mainfrom
claude/determined-jemison-da43e1
Sep 29, 2026
Merged

trueadm merged 2 commits into
mainfrom
claude/determined-jemison-da43e1

Conversation

@trueadm

@trueadm trueadm commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A renderable {expr} hole that is its host element's only child renders
markerless: the server writes text as the host's bare text and every empty value
as no children at all. When the server rendered text but the client value was
undefined, false, true, or '', hydration kept the server text and reported
nothing. A later render then produced <div>AB</div>.

function pick(kind, v) { return kind === 'text' ? v : kind === 'undefined' ? undefined : null; }
export function Hole(props) @{ <section><div>{pick(props.kind, props.v)}</div><i>tail</i></section> }

Server-rendered with { kind: 'text', v: 'A' } and hydrated with
{ kind: 'undefined' }: the A stayed, onRecoverableError never fired, and
rendering { kind: 'text', v: 'B' } gave <div>AB</div>.

null only looked correct. It skipped the markerless branch (typeof null === 'object') and reached childSlot. In a root component, childSlot's root-return
check then called abandonRoot, which gave up hydration for the rest of the root:
a later only-child hole rendered <b>tt</b>, and the dev warning said "expected a
renderable root". In a nested component, null left the stale text just like
undefined did.

There were three causes, and the fix needs all three:

  • Runtime, childTextHole: the markerless empty branch returned without
    looking at the host's server children. The new HydrationCapability.hempty is
    htext's counterpart for empty values:
    • It unwraps an empty <!--[--><!--]--> frame silently, since the server frames
      an empty ternary arm.
    • Otherwise it discards the server content and reports it once: error 62 to
      onRecoverableError, plus the dev warning with the hole's location ("the
      client expected nothing but the server rendered text "A"").
    • A dormant <Hydrate> boundary whose captures changed before activation
      repairs without reporting (staleServerValues).
    • A <textarea> is left alone because its value/defaultValue props own its
      text. Six existing textarea hydration tests fail without that guard.
  • Runtime, null routing: null now takes the markerless branch with the
    other empty values, matching ssrChildText, which already writes every empty
    value the same way.
  • Compiler, first render: the compiler seeded the hole's cached previous value
    (_chp) with undefined, so childTextHoleUpdate and the @for inline guard
    skipped the first render whenever the value was undefined. Only-child holes now
    seed the owning scope instead, using the existing never-equal seed that style
    scalars use ('style-unset', renamed to 'unset'). The steady-state update
    helpers are unchanged.

Validation

  • pnpm format:check: only the scoped pnpm format:files:check ran on the changed files, and it passed.
  • pnpm typecheck: only the scoped pnpm typecheck:files ran on runtime.ts, compile.js, and both fixtures, and it was clean. mismatch-structural.test.ts already had 8 implicit-any errors on main, all in lines this PR doesn't touch.
  • pnpm test: not green locally. The single-process run hits the V8 heap limit on this machine, with timeouts before the abort. Shard 1/4 of vitest.ci-sharded.config.js ran before the rebase with 9,063 passed and 2 failed. The two failures were a CLI version timeout and streamdown/highlight-race, which passes 3/3 in isolation. Shards 2–4 were stopped for the rebase and did not run, so CI is the full-suite evidence.
  • targeted tests:
    • After rebasing onto d455cb18c, all of packages/octane/tests/hydration plus the textarea and behavior-root suites pass in octane and octane-prod: 166 files, 3,498 tests.
    • Before the rebase, --project octane --project octane-prod had 4 failures out of 25,059. All were load timeouts or their follow-on errors, and they pass in isolation.
    • New regressions are in mismatch-structural.test.ts ("only-child renderable hole whose client value is empty"), in dev and prod compile. They cover all five empty values in root and nested components, .tsx framed text, a keyed @for row (inline guards), bindSignalChild lowering, matching empty values staying silent, and a dormant <Hydrate> boundary. Each test asserts final DOM, reuse of the adopted server nodes, later renders, onRecoverableError, and the dev warning.
    • Each part of the fix was reverted on its own to confirm that exactly its tests fail:
      • removing the hempty call: 100 failures;
      • routing null through childSlot again: 18;
      • restoring the undefined seed: 16;
      • removing the stale-capture gate: 20;
      • removing the empty-frame unwrap: 16.
  • Codegen-size corpus (16 files, production compile, same method as benchmarks/codegen-size): raw 218,173 → 218,192 bytes (+19), minified +5, gzip +1. The benchmark script's rspack CSS-modules step fails the same way on the baseline, so these totals come from its corpus loop.

Risk / follow-ups

  • Mount cost: in the plain and @for lowerings, an only-child hole whose first
    value is undefined now calls childTextHole once at mount. A null hole no
    longer allocates childSlot state, and steady-state updates are untouched. No
    wall-clock measurement was taken because the difference would sit inside noise.
  • suppressHydrationWarning does not keep the server text here. The discard is
    structural, like htext's extra-children removal, and matches React's
    tail-node check for null/undefined/boolean children. React would keep the
    server text for a literal '' under suppression; Octane renders '' as
    nothing, like the other empty values.
  • Sibling (non-only-child) holes still seed _chp with undefined, so their
    first render skips textHole for undefined in the plain lowering. That
    matters for the sibling-position element→text work in progress, which relies on
    childSlot running.
  • Separately, server text → client element in an only-child hole still hits the
    same abandonRoot misfire in a root component and leaks in a nested one. It is
    a different path and is being handled in its own task.

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
Changes core hydration reconciliation for markerless text holes; behavior is narrow but affects first-paint DOM and error reporting, with extensive targeted tests.

Overview
Fixes hydration when a renderable {expr} is the only child of its host and the server sent text but the client value is empty (null, undefined, booleans, or ''). Stale text was left in the DOM (e.g. <div>AB</div> on the next update) with no recoverable error; null at the root could abandon hydration for sibling holes.

The runtime adds hempty, called from the markerless empty path in childTextHole: it strips server text (or an empty comment frame), fires onRecoverableError once, and in dev warns with source location. null now follows the same markerless path as other empty values instead of childSlot/abandonRoot. Dormant <Hydrate> boundaries with legitimately stale captures still repair silently; <textarea> hosts are skipped.

The compiler seeds only-child holes’ cached previous value with unset (renamed from style-unset) so the first hydrating render always runs the hole logic even when the value is undefined. Broad regression tests cover root/nested components, .tsx, @for, signal bindings, and dormant boundaries (dev and prod compile).

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

A renderable `{expr}` hole that is its host's only child renders
markerless: the server serializes text as the host's bare text and every
empty value as no children. When the server rendered text but the client
value was `undefined`, a boolean, or `''`, hydration kept the server text
and reported nothing, so a later value rendered beside it (`<div>AB</div>`).

Three causes:
- childTextHole's markerless empty branch returned without looking at the
  host's server children. The new HydrationCapability.hempty, htext's
  empty counterpart, unwraps an empty `<!--[--><!--]-->` frame silently,
  otherwise discards the server content and reports it once (recoverable
  error plus the located dev warning). Dormant boundaries whose captures
  changed repair without reporting, and a textarea is left alone because
  its value props own its text.
- `null` bypassed that branch (`typeof null === 'object'`) and reached
  childSlot. In a root component that took the root-return path and
  abandoned hydration for the rest of the root, so a later only-child hole
  duplicated its text; in a nested component the stale text stayed. `null`
  now takes the markerless branch like the other empty values.
- The compiler seeded the hole's cached previous value with `undefined`,
  so its first render skipped the hole entirely for an `undefined` value.
  Only-child holes now seed the owning scope (the existing never-equal
  `unset` seed, renamed from `style-unset`), so hydration always reaches
  the hole. The steady-state update helpers are unchanged.

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 20:39
@trueadm
trueadm marked this pull request as ready for review September 29, 2026 21:05
@trueadm
trueadm merged commit 898820a into main Sep 29, 2026
51 of 55 checks passed
@trueadm
trueadm deleted the claude/determined-jemison-da43e1 branch September 29, 2026 22:14
trueadm added a commit that referenced this pull request Oct 5, 2026
…t signals (#1762)

* perf(octane): stop shipping the signal binding runtime in apps without signals

Since async signals (#1069) the compiler treated every opaque text,
attribute, control and textarea hole, such as `{row.label as string}`, as a
potential signal handle in every module. Every app therefore retained
bindSignalText and the direct-binding engine and stamped signal identities
on every component, even when it never created a handle.

Opaque holes now bind handles only in modules that import from
`octane/signals` (a type-only `SignalHandle` import is enough and does not
enable native reads), in modules using DOM bindings, or everywhere with the
new `opaqueSignalHandles` compiler option. `$`-named expressions still bind
in every module. A dev-only error reports a handle that reaches a plain text
hole.

Gating exposed two plain-path hydration gaps that the signal path had been
masking: a sibling or whole-output hole whose first client value is
`undefined` kept the server content (the #1426 sentinel now seeds every
hole), and an `undefined` first attribute value kept the server attribute
(the IfChanged writers now apply the direct-signal path's hydration rule).

Runtime gzip: rows 38,991 -> 37,307, TodoMVC 44,217 -> 41,076,
chat 43,638 -> 40,347, weather 48,986 -> 47,270. Budgets lowered.

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

* ci(bench): re-lower byte budgets after merging main

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

* ci(bench): re-lower minimal budgets after merging main

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

* test(bench): opt scoped-signals harnesses that pass opaque handles into opaqueSignalHandles

These workflow tests render real handles through ordinary props in modules
without a signals import (late model-engine imports, opaque rows and
attributes), which now binds only with the opaqueSignalHandles option.

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

* fix(octane): look through satisfies and instantiation wrappers for nested $ handles

The syntactic-only capability check unwrapped as/!/parentheses but not
`satisfies` or instantiation expressions, so `(a ?? b$) satisfies T`
stopped binding `b$` in a module without a signals import.

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

* test: update signal-capable mapping and writer tests for the opaque-handle gate

signals-dom-bindings passes handles through ordinary props in an untyped
module, so it opts into opaqueSignalHandles. The playground mapping rows for
signal-free modules now map to the plain writers, and a signals-importing
variant keeps the named writer-record targets covered.

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