Skip to content

fix(hydration): keep server values in a suspended @try arm and report once at commit - #1544

Merged
trueadm merged 4 commits into
mainfrom
fix/suspended-arm-value-repair
Oct 2, 2026
Merged

trueadm merged 4 commits into
mainfrom
fix/suspended-arm-value-repair

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A resolved @try arm (server emitted oct-suspense:N, hydrated by renderInitialSuspenseHydration) whose first hydrating attempt repairs a text or attribute value and then suspends now keeps the server's value while pending, and reports the mismatch once when an attempt commits.

Why

The arm hydrates speculatively: a suspended attempt is discarded and a later one adopts the same server nodes. Before this change:

  • htext/htextSwap wrote the client value immediately, so the server's text showed the client value while the arm was still pending.
  • The text warning sat in the capability's textWarnings, which only publish on success. The suspension dropped the capability, and the retry saw matching text. As a result, neither the dev "server rendered text … but the client rendered …" warning nor onRecoverableError fired.
  • Attributes and style had the same rewrite-while-pending problem, and they warned from the attempt that was thrown away.
  • Kept dangerouslySetInnerHTML content warned on every attempt.

Without suspension, the same arm reports one warning and one onRecoverableError. The fix makes the suspended case match.

Changes

  • HydrationCapability.speculative is set only by renderInitialSuspenseHydration.
  • Before overwriting a server text value, attribute, class (in flushClassWrites) or style, a speculative attempt records the server value. Recording happens only on the mismatch path, never on the happy path.
  • rollback() restores the recorded values newest first, on suspension or error. Nodes cloned fresh by structural recovery are skipped: they hold client template values, and restoring them made the retry report false mismatches.
  • Value warnings are held on the capability until it settles: attribute, class, style, and the kept-dangerouslySetInnerHTML warning. The hold goes through warnHeldHydrationMismatch, whose call sites are all dev-gated, so production bundles drop it.
  • settle(outer) replaces flushTextWarnings() on success. An arm that commits inside an enclosing speculative attempt hands its records and pending warnings to that attempt. Otherwise they publish through fix(octane): drop hydration diagnostics from try bodies caught by their catch arm #1534's diagnostic hold, as before.
  • On the error path, after rollback(), the capability stops being speculative. An adopted server catch arm keeps reporting immediately.
  • Added a changeset (octane patch) and one sentence in the hydration section of docs/differences-from-react.md.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check on every changed file passes.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files on runtime.ts, the new test and the .tsrx fixture passes.
  • pnpm test: not run. The octane and octane-prod vitest projects were run instead (below).
  • targeted tests:
    • New packages/octane/tests/hydration/suspended-arm-value-mismatch.test.ts: 36 cases, dev and prod compile.
      • Covers text, sibling text, attribute, style, class, nested text, nested class, raw HTML, a namespaced xlink:href removal, and a clone rebuilt before the arm suspended.
      • Asserts the server markup is unchanged while pending, exactly one warning (dev) and the right onRecoverableError count at commit, and the final DOM.
      • Against main's runtime at 4ab33b6b1, 15 of the 36 fail. The class cases pass on both, because class writes already wait until commit outside nested arms. The rebuilt-clone case passes on main itself since fix(hydration): apply a rebuilt clone's attributes without a value report #1536.
      • Each part of the fix was deliberately broken in turn, and each break fails at least one test: the restore, the warning hold, the nested hand-off, the class record, the fresh-clone skip, and the namespaced restore.
    • On the current head (e9a3a8af3, which merges main through 4ab33b6b1, including fix(hydration): apply a rebuilt clone's attributes without a value report #1536 and fix(hydration): keep a suspended root's server values and report value mismatches once #1556): packages/octane/tests/hydration/ passes in both octane and octane-prod (230 files, 11,893 tests).
    • On the previous head (c0c3e8b35): the full octane-prod project passed (614 files, 16,411 tests). The full octane project passed 19,775 tests; its 3 failures were timeouts against the tests' own 15 s limits (compiler/volar ×2, one behavior-root case) at a load average of about 100, and both files passed when rerun alone (207/207 and 33/33).
    • Earlier runs before the merge hit only load-sensitive timeouts, and each of those files passed when rerun alone (hydration-ssr-diagnostics, vite-integration, ssr-suspense, compiler-vite-options, strong-html).
  • Bundle (benchmarks/bundle-size/run-minimal.mjs, production):
    • hydrate-root and deferred-hydration: +922 raw / +258–279 gzip after the follow-up trim in c9b255d28 (the first push measured +1,009 raw).
    • cli-spa-starter, hooks-state, context and suspense-transition: +0.
    • In the PR bench report, client-only and binding bundles drop 15 raw / 3–7 gzip bytes, because the kept-dangerouslySetInnerHTML warning call is now dev-guarded. Their brotli deltas move both ways by compressor noise.
    • No scenario that CI checks against its size budgets is affected.
    • Timing was not A/B'd because the machine's load made it untrustworthy. The happy path adds no per-node work.

Risk / follow-ups

  • Main's fix(hydration): keep a suspended root's server values and report value mismatches once #1556 added the root-level twin of this fix: journalRepair() journals values in a root's hydrating attempt, and save()/remember() journal structure. It doesn't cover a resolved @try arm, because when the arm suspends the root still commits around it. The merge shares the value sites: journalRepair() calls this PR's repaired() first. allowAttribute calls repaired() directly, because attribute setters already journal for the root.
  • The structural rollback for suspended @try arms (the double structural report) is being stacked on this PR. It plans to fold repaired/journalRepair and this PR's repairs/heldWarnings into one undo mechanism.
  • Not covered: a suspended <Hydrate> island activation keeps its capability and resumes at the cursor. It reports once, but may still show client values while pending; this was not verified. Binding-view bindingText repairs silently, so it never had a report to lose.
  • Separate pre-existing defect found while probing, tracked separately: a use() read inside a text hole of a reader whose server read rejected reports false structural and attribute mismatches.

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 rollback/settle logic in runtime.ts for speculative @try arms; incorrect repair or warning timing could affect dev diagnostics and recoverable-error reporting without altering production mismatch recovery semantics for non-suspense paths.

Overview
Fixes hydration mismatch reporting when a resolved @try arm repairs server/client text or attributes, then suspends before the attempt commits.

Speculative suspense hydration now records server values before overwriting them and rolls them back if the attempt is discarded, so pending markup still shows server output instead of prematurely applied client values. Dev warnings for attributes, class, style, and kept dangerouslySetInnerHTML are deferred via warnHeldHydrationMismatch until the attempt settles, matching text behavior and ensuring onRecoverableError and console diagnostics fire once on the committing retry.

Nested speculative attempts merge repairs and held warnings into an outer capability through settle/rollback. Documentation and a patch changeset describe the React-parity behavior; new hydration tests cover text, attributes, style, class, nested arms, HTML, xlink, and rebuilt clones.

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

… once at commit

A resolved @Try arm (server emitted oct-suspense:N) hydrates speculatively:
when its first attempt suspends, the attempt is discarded and a later one
adopts the same server nodes. An attempt that repaired a text or attribute
value before suspending wrote the client value into the server's markup while
the arm was still pending, and queued the text warning on a capability that
the suspension dropped. The committing attempt then found the value already
matching, so the mismatch never reached onRecoverableError or the dev warning.

The arm's HydrationCapability is now speculative. Before it overwrites a
server text value, attribute, class or style, it records the server value, and
rollback() restores them when the attempt suspends or throws. Nodes cloned
fresh by structural recovery hold client template values and are skipped.
Value warnings (attribute, class, style, kept dangerouslySetInnerHTML) are held
until the attempt settles. A nested arm that commits inside an enclosing
speculative attempt hands its records and pending warnings to that attempt.

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
…ue-repair

# Conflicts:
#	packages/octane/src/runtime.ts
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 08:55
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 1 value(s) increased
  • 🔴 bundle-reachability: 9 value(s) increased

Compares 4ab33b6b1 with f261ebeb9 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.84 3.53 −8.1% ±26% ⚪ within noise
octane-tsrx replace 8.31 7.70 −7.3% ±48% ⚪ within noise
octane-tsrx add 3.50 3.57 +2.0% ±22% ⚪ within noise
octane-tsrx update 0.55 0.38 −30.9% ±53% ⚪ within noise
octane-tsrx select 0.23 0.21 −8.7% ±75% ⚪ within noise
octane-tsrx swap 0.46 0.32 −30.4% ±54% ⚪ within noise
octane-tsrx remove 0.45 0.35 −22.2% ±59% ⚪ within noise
octane-tsrx runlots 33.19 31.88 −3.9% ±40% ⚪ within noise
octane-tsrx select_lots 0.24 0.24 ±0.0% ±68% ⚪ within noise
octane-tsrx clear 43.32 43.90 +1.3% ±30% ⚪ within noise
octane-jsx run 3.67 3.87 +5.4% ±21% ⚪ within noise
octane-jsx replace 8.13 7.22 −11.2% ±31% ⚪ within noise
octane-jsx add 3.30 3.24 −1.8% ±18% ⚪ within noise
octane-jsx update 0.60 0.51 −15.0% ±55% ⚪ within noise
octane-jsx select 0.44 0.34 −22.7% ±63% ⚪ within noise
octane-jsx swap 0.71 0.61 −14.1% ±47% ⚪ within noise
octane-jsx remove 0.74 0.61 −17.6% ±61% ⚪ within noise
octane-jsx runlots 30.86 30.55 −1.0% ±19% ⚪ within noise
octane-jsx select_lots 2.49 2.19 −12.0% ±31% ⚪ within noise
octane-jsx clear 47.22 41.15 −12.9% ±21% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-jsx js_raw 224,353 224,338 −15 (−0.0%) 🟢
octane-jsx js_gzip 71,483 71,476 −7 (−0.0%) 🟢
octane-jsx js_brotli 61,880 61,858 −22 (−0.0%) 🟢
octane-jsx app_brotli 2,500 2,501 +1 (+0.0%) 🔴
octane-jsx fw_raw 215,886 215,871 −15 (−0.0%) 🟢
octane-jsx fw_gzip 68,540 68,533 −7 (−0.0%) 🟢
octane-jsx fw_brotli 59,380 59,357 −23 (−0.0%) 🟢

38 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
root-static raw 200,676 200,661 −15 (−0.0%) 🟢
root-static gzip 63,652 63,645 −7 (−0.0%) 🟢
root-static brotli 55,219 55,276 +57 (+0.1%) 🔴
hydrate-root raw 159,641 160,519 +878 (+0.5%) 🔴
hydrate-root gzip 51,135 51,407 +272 (+0.5%) 🔴
hydrate-root brotli 44,604 44,818 +214 (+0.5%) 🔴
deferred-hydration raw 221,896 222,774 +878 (+0.4%) 🔴
deferred-hydration gzip 70,561 70,862 +301 (+0.4%) 🔴
deferred-hydration brotli 60,979 61,181 +202 (+0.3%) 🔴
binding-base-ui-vite raw 210,870 210,855 −15 (−0.0%) 🟢
binding-base-ui-vite gzip 67,207 67,201 −6 (−0.0%) 🟢
binding-base-ui-vite brotli 58,335 58,282 −53 (−0.1%) 🟢
binding-base-ui-esbuild raw 208,853 208,838 −15 (−0.0%) 🟢
binding-base-ui-esbuild gzip 67,199 67,193 −6 (−0.0%) 🟢
binding-base-ui-esbuild brotli 58,366 58,330 −36 (−0.1%) 🟢
binding-radix-vite raw 212,799 212,784 −15 (−0.0%) 🟢
binding-radix-vite gzip 67,778 67,771 −7 (−0.0%) 🟢
binding-radix-vite brotli 58,781 58,830 +49 (+0.1%) 🔴
binding-radix-esbuild raw 210,741 210,726 −15 (−0.0%) 🟢
binding-radix-esbuild gzip 67,778 67,767 −11 (−0.0%) 🟢
binding-radix-esbuild brotli 58,874 58,871 −3 (−0.0%) 🟢
binding-apollo-client-vite raw 355,919 355,904 −15 (−0.0%) 🟢
binding-apollo-client-vite gzip 111,326 111,322 −4 (−0.0%) 🟢
binding-apollo-client-vite brotli 97,200 97,188 −12 (−0.0%) 🟢
binding-apollo-client-esbuild raw 358,906 358,891 −15 (−0.0%) 🟢
binding-apollo-client-esbuild gzip 113,560 113,553 −7 (−0.0%) 🟢
binding-apollo-client-esbuild brotli 98,923 99,050 +127 (+0.1%) 🔴

78 other measured values are unchanged.

CI job durations

⚪ No job outside the range of recent main runs.

Compares the CI run for e9a3a8af3 (run) with the last 5 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s. Job time excludes runner setup.

job main median main range this PR Δ
wall clock (first job start to last job end) 13m 32s 11m 55s–15m 07s 12m 34s −58s (−7%) ⚪ within noise
total job time 149m 29s 134m 18s–156m 28s 138m 01s −11m 28s (−8%) ⚪ within noise
All 26 timed jobs
job main median main range this PR Δ
example apps (1/3) 3m 12s 3m 06s–3m 19s 3m 27s +15s (+8%) ⚪ within noise
lint checks 8m 01s 7m 46s–9m 37s 8m 15s +14s (+3%) ⚪ within noise
validate publishable packages 4m 16s 3m 51s–5m 00s 4m 22s +6s (+2%) ⚪ within noise
test shard (Node 24, 3/4) 10m 02s 9m 24s–10m 50s 10m 07s +5s (+1%) ⚪ within noise
React parity shard (1/4) 10m 55s 10m 45s–12m 00s 10m 59s +4s (+1%) ⚪ within noise
classify changeset release 13s 13s–15s 14s +1s (+8%) ⚪ within noise
Three compatibility 2m 44s 2m 38s–3m 48s 2m 45s +1s (+1%) ⚪ within noise
Lynx compatibility 1m 32s 1m 29s–2m 04s 1m 32s ±0s (±0%) ⚪ within noise
typecheck 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
lint 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
React parity checks 11s 10s–12s 11s ±0s (±0%) ⚪ within noise
test (24) 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
CI provenance 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 43s 5m 27s–5m 45s 5m 42s −1s (−0%) ⚪ within noise
examples 3s 3s–4s 2s −1s (−33%) ⚪ within noise
example apps (2/3) 3m 43s 3m 38s–3m 49s 3m 37s −6s (−3%) ⚪ within noise
example apps (3/3) 3m 38s 3m 19s–3m 41s 3m 28s −10s (−5%) ⚪ within noise
heavy integration (browser - chromium) 12m 12s 10m 58s–12m 54s 11m 58s −14s (−2%) ⚪ within noise
React parity shard (2/4) 10m 30s 9m 52s–11m 18s 10m 14s −16s (−3%) ⚪ within noise
website integration suite 5m 56s 5m 44s–7m 00s 5m 39s −17s (−5%) ⚪ within noise
React parity shard (4/4) 11m 19s 10m 08s–12m 06s 10m 55s −24s (−4%) ⚪ within noise
React parity shard (3/4) 10m 36s 10m 08s–12m 02s 10m 08s −28s (−4%) ⚪ within noise
test shard (Node 24, 1/4) 11m 23s 10m 36s–13m 13s 10m 54s −29s (−4%) ⚪ within noise
test shard (Node 24, 4/4) 11m 06s 10m 21s–13m 56s 10m 30s −36s (−5%) ⚪ within noise
test shard (Node 24, 2/4) 12m 09s 10m 38s–14m 29s 10m 47s −1m 22s (−11%) ⚪ within noise
typecheck checks 8m 20s 1m 56s–9m 11s 2m 03s −6m 17s (−75%) ⚪ within noise

trueadm and others added 2 commits October 2, 2026 10:09
… attempt

Move the speculative check and the server-value read into
HydrationCapability.repaired(), so each repair site is one call. A
non-speculative hydration no longer reads the class or style attribute at
all on the mismatch path, and hydrate-root / deferred-hydration shrink by
87 raw bytes.

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

# Conflicts:
#	docs/differences-from-react.md
#	packages/octane/src/runtime.ts
@trueadm
trueadm merged commit 25017f3 into main Oct 2, 2026
31 checks passed
@trueadm
trueadm deleted the fix/suspended-arm-value-repair branch October 2, 2026 12:07
trueadm added a commit that referenced this pull request Oct 2, 2026
…ition

Keep both sides in renderInitialSuspenseHydration: the attempt's capability
is speculative (#1544) and shares the set of client-built nodes across
attempts. Adapt the rebuilt-tail sweep to main's root hydration journal:
save() the parent before removing the tail, and sweep only while the
rebuilt root still stands right before it, so a rolled-back attempt's
stale tail is never swept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 2, 2026
…ttempt rebuilt a mismatch (#1560)

* fix(hydration): keep server values in a suspended @Try arm and report once at commit

A resolved @Try arm (server emitted oct-suspense:N) hydrates speculatively:
when its first attempt suspends, the attempt is discarded and a later one
adopts the same server nodes. An attempt that repaired a text or attribute
value before suspending wrote the client value into the server's markup while
the arm was still pending, and queued the text warning on a capability that
the suspension dropped. The committing attempt then found the value already
matching, so the mismatch never reached onRecoverableError or the dev warning.

The arm's HydrationCapability is now speculative. Before it overwrites a
server text value, attribute, class or style, it records the server value, and
rollback() restores them when the attempt suspends or throws. Nodes cloned
fresh by structural recovery hold client template values and are skipped.
Value warnings (attribute, class, style, kept dangerouslySetInnerHTML) are held
until the attempt settles. A nested arm that commits inside an enclosing
speculative attempt hands its records and pending warnings to that attempt.

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

* perf(hydration): read the repaired server value only in a speculative attempt

Move the speculative check and the server-value read into
HydrationCapability.repaired(), so each repair site is one call. A
non-speculative hydration no longer reads the class or style attribute at
all on the mismatch path, and hydrate-root / deferred-hydration shrink by
87 raw bytes.

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

* fix(hydration): keep a suspended @Try arm's server content when its attempt rebuilt a mismatch

A resolved @Try arm (oct-suspense:N) whose first hydrating attempt rebuilt a
mismatched template clone and then suspended removed the server node while
the attempt was discarded, left the arm blank while pending, and reported the
structural mismatch twice (dev warning and onRecoverableError, dev and prod):
the retry found only the range's close marker and reported again.

A speculative attempt now keeps one undo list. save(parent) snapshots a
parent's children once before structural recovery changes them (the same
sites #1556 journals for roots, plus the de-opt reconcile); remember() makes
HYDRATION_REBUILT marks undoable; #1544's value repairs push restore steps
onto the same list. settle() hands the list to an enclosing speculative
attempt and rollback() replays it newest first. Any failed attempt rolls back
and drops its held diagnostics, so the attempt that commits reports each
mismatch once. #1544's heldWarnings/repairs log fold into this list and
#1534's hold. collectRootRange/restoreRootRange are shared with
journalRootRange, and a dormant island's staleServerValues now carries to
retries.

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

* fix(hydration): undo de-opt children a suspended @Try arm inserted or moved

reconcileDeoptChildren recorded a speculative snapshot of a server host only
when it removed a child. Filling an empty server host, or inserting and moving
children in its ordering pass, journaled only for the root, so a resolved @Try
arm that hit those paths and then suspended left client-built children in the
server markup while pending. Record the host before both, through a cold
helper that does nothing outside a hydrating attempt or for a fresh host.

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

* fix(hydration): skip restoring a range whose bounds left their parent

The speculative arm's undo called restoreRootRange without the check that
journalRootRange makes first: when either bound is no longer in the parent,
the snapshot owns no range there, and walking to a bound that is gone sweeps
the parent's later siblings and then inserts before a detached anchor. Move
the check into restoreRootRange so both callers share it. Recovery cannot
detach an arm's own bounds in balanced markup; the regression simulates an
outside mutation during the suspended attempt.

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