Skip to content

fix(hydration): repair stale dormant Hydrate captures without side renders - #1282

Merged
domgan-oai merged 1 commit into
mainfrom
fix/dormant-hydrate-capture-diagnostics
Sep 23, 2026
Merged

domgan-oai merged 1 commit into
mainfrom
fix/dormant-hydrate-capture-diagnostics

Conversation

@trueadm

@trueadm trueadm commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1181 (review items D2, D3, D4).

  • D2: no more extra dev render. When a mounted parent changed a dormant Hydrate boundary's captures before activation, development rendered the whole child subtree an extra time, with the old props, in a detached document. That ran component bodies, useState initializers, useMemo factories and getSnapshot, which production never did ([render:a, init:a, snap:a, snap:a, render:b, …] vs [render:b, …]). Octane documents no StrictMode double-invoke, so this probe is removed along with the native-signal support fix(hydration): isolate native signal attribute diagnostics #1238 added on top of it: the ~20 saved-and-restored runtime globals, the hydrateAttributeProbe guards, the useSignal$ diagnostic initializer and the staged-DOM allowlist entries.
  • D3: no false text mismatch. The same scenario reported a legitimately changed text hole as a hydration mismatch: onRecoverableError (error And again #61) in production and console.error in development. fix: distinguish dormant capture updates from hydration mismatches #1181 fixed this for attributes only.

How it works now

Each dormant, server-preserved boundary keeps the captures and provided context values it was first claimed with, until it activates. Activation compares them with the current ones:

  • Split boundaries compare the __data capture array.
  • Unsplit boundaries use the compiler's per-body capture list. It is now emitted in production as well, so dev and prod reach the same decision.
  • Context is compared only when the global context epoch has moved.

When anything changed, the server HTML predates the client's state. Activation then repairs attributes, class, style and text without a warning or onRecoverableError. A boundary claimed inside such a boundary inherits this. When the captures are unchanged, for example after a parent re-render with equal values, real mismatches are still reported. No child render happens either way.

Contract change: #1181 also promised that a genuine initial mismatch would still be diagnosed after a later capture change corrected it. That requires rendering the stale captures, so it is dropped. Such a mismatch is now repaired silently. docs/deferred-hydration.md is updated to match.

D4

The SUSPENSE_RESOLVED_COMMENT branch of takeInitialSuspenseHydration does build idState without signalState, but the fallback it feeds is never reached, so this PR leaves it unchanged:

  • In plain roots the ID prefix and the signal prefix are equal.
  • In independent islands, the adapter's framed scope always supplies an ancestor key first.

While checking this I found that island client keys carry an extra ["legacy",[],""] segment the server keys don't have. I have not yet shown a user-visible effect; it is being investigated separately.

Cost

Production, measured on the Hydrate test fixtures with esbuild minify and gzip:

  • about +1.6 KB minified / +440 B gzip, only for apps that use Hydrate;
  • about +120 B of compiled output per unsplit Hydrate site.

Development loses the whole probe path.

Validation

  • Formatting check on the changed files (pnpm format:files:check)
  • Typecheck of the changed files (pnpm typecheck:files, tsrx-tsc)
  • pnpm test, run as CI runs it: 4 shards with vitest.ci-sharded.config.js, 29,980 tests passing. The single-process pnpm test runs out of heap on this machine.
  • Targeted tests:
    • packages/octane/tests/hydration (octane and octane-prod projects): 2,040 tests passing after rebasing onto current main.
    • scripts/check-staged-dom and its tests pass.
    • The new regression tests fail before the fix: production reports a recoverable text error, and development logs render:first, init:first….
    • The identical-capture, context-only and nested-inheritance tests each fail when their mechanism is disabled on purpose.
  • Repo-wide pnpm format:check and pnpm typecheck were not run; only the scoped versions above.

Risk / follow-ups

  • Coarse unsplit comparison: unsplit children without a compiler capture list (non-compiled children, a Hydrate not imported from octane) are treated as changed whenever the function identity differs. Diagnostics are skipped there rather than reported falsely.
  • Structural mismatches not covered: a legitimate capture change that flips an @if arm is still reported as a recoverable structural mismatch. This PR only covers value-level diagnostics.
  • Not changed under stale captures: suppressHydrationWarning and dangerouslySetInnerHTML still keep the server value, as before.

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 deferred-hydration activation and mismatch reporting in dev and prod; behavior is broad but covered by extensive hydration tests and narrows false positives rather than skipping checks when captures are unchanged.

Overview
Dormant Hydrate boundaries no longer get an extra development-only render against old closure captures. That detached probe (and the related hydrateAttributeProbe, native-read pauses, and useSignal$ diagnostic initializer) is removed so dev and prod follow the same activation path.

Instead, server-preserved boundaries record initial captures and context at claim time. On activation, Octane compares them to the current props/context (compiler CHILDREN_CAPTURES in production for unsplit children). If anything changed, staleServerValues is set and attributes, class, style, and text are repaired silently—no console.error or onRecoverableError. Nested boundaries inherit stale server HTML from an activating parent. Unchanged captures still surface real server/client mismatches as before.

Contract change: an initial mismatch that a later capture update would have “fixed” before activation is now repaired without a diagnostic (docs updated).

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

…nders

When a mounted parent changes a dormant Hydrate boundary's captures or
provided context before activation, the server HTML predates the client's
state. Decide that by comparing the initial and current captures instead
of rendering the child with its historical props, and repair attributes,
class, style and text without mismatch diagnostics in dev and prod.

Removes the development-only historical attribute probe (#1181) and the
native-signal isolation built on it (#1238), which re-ran component
bodies, state initializers, memo factories and getSnapshot with stale
props.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review September 23, 2026 11:22
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 23, 2026
@domgan-oai
domgan-oai merged commit 08d9a82 into main Sep 23, 2026
47 of 50 checks passed
@domgan-oai
domgan-oai deleted the fix/dormant-hydrate-capture-diagnostics branch September 23, 2026 11:47
trueadm added a commit that referenced this pull request Sep 23, 2026
… fast path

#1282 removed `hydrateAttributeProbe` along with the side-render capture it
served, deleting this exact guard from `nativePresentationBinding`. #1270,
branched earlier, copied that guard into its new scalar-literal fast path in
`nativeStyleBinding`. Both merged, leaving main referencing an undefined
name: `tsc` fails (TS2304), the octane build and every package pack fail,
and in dev the fast path throws `ReferenceError: hydrateAttributeProbe is not
defined` (#1270's own style-transaction and signal-binding tests fail).

Drop the guard to match #1282's removal in the general path.

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

#1282 removed `hydrateAttributeProbe` along with the side-render capture it
served, deleting this exact guard from `nativePresentationBinding`. #1270,
branched earlier, copied that guard into its new scalar-literal fast path in
`nativeStyleBinding`. Both merged, leaving main referencing an undefined
name: `tsc` fails (TS2304), the octane build and every package pack fail,
and in dev the fast path throws `ReferenceError: hydrateAttributeProbe is not
defined` (#1270's own style-transaction and signal-binding tests fail).

Drop the guard to match #1282's removal in the general path.

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.

2 participants