Skip to content

fix(octane): drop hydration diagnostics from try bodies caught by their catch arm - #1534

Merged
trueadm merged 7 commits into
mainfrom
fix/hydrate-thrown-try-body-diagnostics
Oct 2, 2026
Merged

trueadm merged 7 commits into
mainfrom
fix/hydrate-thrown-try-body-diagnostics

Conversation

@trueadm

@trueadm trueadm commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A hydrating template (@{}) component that clones its root element and then throws inside a @try body reported a false hydration mismatch. The clone is adopted against whatever the server rendered in its place. Often that is the server's own @catch arm, rendered because the server's body threw the same way. The client logged Octane hydration mismatch … the client expected <i> but the server rendered <p> in development and called onRecoverableError in development and production, even though the final DOM and onCaughtError were correct.

function ThrowC(props: { value: unknown }) @{
	<i>{fail(props.value) as string}</i>
}
export function Clone(props: { value: unknown }) @{
	<div>
		<h1>{'before'}</h1>
		@try {
			<ThrowC value={props.value} />
		} @catch (error: unknown) {
			<p class="caught">{String(error) as string}</p>
		}
		<button>{'after'}</button>
	</div>
}

Hydration diagnostics are now held while a hydrating try body renders:

  • Throws to its catch arm: the body's diagnostics are dropped, because the catch arm replaces what it adopted.
  • Completes, suspends, or throws past a boundary without a catch arm: its diagnostics pass to the enclosing hold, and publish when the outermost hold is released.

Changes

  • packages/octane/src/runtime.ts
    • The four publication points (noteRecoverableHydrationError, warnHydrationStructuralMismatch, warnHydrationValueMismatch, warnHydrationKeptServerValue) push a thunk while a hold is active.
    • The hold is a module-level counter. Its array is allocated only when a diagnostic is actually held.
    • HydrationCapability.holdDiagnostics / releaseDiagnostics / renderTryBody are methods, so client-only bundles shed them.
    • Covered try render paths: mountTry, the initial Suspense hydration renderer, passthrough tries, the compiled <ErrorBoundary> (errorBlock) mount and re-render paths, and renderVisibleTry. Render-phase updates drained during hydration re-render a try body that is still hydrating, so the last one can report the same false mismatch.
    • Class writes flush after the render, outside any hold. The class mismatch warning now skips an element that a caught body left detached, as flushTextWarnings already does for text.
  • docs/differences-from-react.md: one sentence in the hydration section stating the contract.
  • Changeset: octane patch.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check passes on every changed file and on the default staged/unstaged selection.

  • pnpm typecheck: not run repo-wide. pnpm typecheck:files (tsrx-tsc, with the .tsrx fixture) passes on the changed files.

  • pnpm test: not run as a whole. Before the rebase onto current main, the full octane (19,536/19,537) and octane-prod (16,093/16,096) projects ran. The four failures were in behavior-root.test.ts and independent-parent.test.ts at load ~60. Both files pass 478/478 in isolation on this change, and independent-parent also flaked on base.

  • targeted tests:

    • New file: packages/octane/tests/hydration/try-clone-thrower.test.ts, 26 cases in octane and octane-prod.
      • Drop cases assert no console.error, no onRecoverableError, the correct final DOM, adopted <div>/<h1>/<button> hosts around the boundary, and a live click handler. They cover: @try (server catch arm and server divergence), a template-less callee, @pending (initial Suspense renderer), compiled and component <ErrorBoundary>, nested boundaries (inner catches; inner completes and outer catches; catch-less inner), a drained re-render (@try and <ErrorBoundary>), passthrough, and a class binding adopted from the catch arm.
      • Controls show real mismatches still report: a body that completes (template, template-less, @pending, <ErrorBoundary>, nested, drained re-render, passthrough), a body that suspends (with and without @pending), and a class mismatch on a live element.
    • Seen failing first: on the base runtime, 15 tests fail in each project and the 11 controls pass. Removing the hold from any single call site turns that path's test red. So do three wrong policies: always drop, drop on suspension, and publish on inner release instead of forwarding.
    • Current head (merged with main, including fix(octane): adopt the server catch arm when a template-less use() reader rejected #1523 and fix(hydration): report a rebuilt clone's mismatch once #1533): packages/octane/tests/hydration/ plus root-error-callbacks.test.ts pass in both projects (214 files, 11,316 tests). With the hold disabled, the template-less cases still fail on top of fix(octane): adopt the server catch arm when a template-less use() reader rejected #1523's renderUnframed, which reports the missing range when the body throws an application error.
  • Bundle bytes (benchmarks/bundle-size/run-minimal.mjs, against main at f647ceff6):

    Fixture raw gzip
    hydrate-root +622 +263
    deferred-hydration +669 +256
    suspense-transition +192 +43
    context, root-static, binding-base-ui-vite +39 +18 to +20
    cli-spa-starter, hooks-state, behavior-root-vite 0 0

    The second commit moves the hold check behind a HydrationCapability method, so bundles that never hydrate no longer retain the hold's state. That cut their cost from +90 to +39 raw bytes (the first benchmark report on this PR shows the earlier numbers).

  • Runtime: the added work is one counter increment and an array-length read per hydrating try body, plus a null check on client-only try renders. Wall-clock benchmarks were not trustworthy on the shared machine (load 40–70), so none were run.

Risk / follow-ups

  • A component inside a hydrating try body that a drained render-phase update re-renders, and that then throws, reaches the catch arm through handleRenderError without a hold, so it can still report. That path already warns in development about the cross-component render-phase update.
  • A server-rejected use() inside a cloned template no longer reports the clone mismatch, but its catch arm is still adopted incorrectly after the clone's recovery. That is pre-existing, and separate work on server catch-arm hydration addresses it.

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 and error reporting across many try/boundary render paths; behavior change is intentional but could hide real mismatches if hold/release logic is wrong on an edge path.

Overview
Fixes false hydration diagnostics when a hydrating @try / <ErrorBoundary> body throws into its catch arm after adopting server markup (often the server’s own catch output).

While a try body hydrates, dev mismatch logs and onRecoverableError are held and discarded if an application error is caught locally; they still publish when the body completes, suspends, or propagates past the boundary. Hydrating try renders go through renderTryBody on the main boundary paths (including Suspense retry and drained render-phase updates). Class mismatch warnings skip nodes a caught body already detached.

Docs and an octane patch changeset document the contract. try-clone-thrower fixture + tests cover drop vs. still-report cases.

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

…ir catch arm

A hydrating template that clones its root and then throws inside a @Try
body compared that clone against whatever the server rendered there,
often the server's own @catch arm, and reported a false mismatch through
console.error (dev) and onRecoverableError (dev and prod). Hold hydration
diagnostics while a hydrating try body renders: drop them when it throws
to its catch arm, pass them to the enclosing hold otherwise, and publish
when the outermost hold releases. Class mismatch warnings, which flush
after the render, skip elements a caught body left detached.

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 1, 2026
@trueadm
trueadm marked this pull request as ready for review October 1, 2026 23:53
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 10 value(s) increased
  • 🔴 bundle-reachability: 25 value(s) increased

Compares 3ffd8cc3c with 80822b47a 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 moving the same way. 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.83 3.56 −7.0% ±18% ⚪ within noise
octane-tsrx replace 9.34 8.60 −7.9% ±31% ⚪ within noise
octane-tsrx add 4.05 3.53 −12.8% ±19% ⚪ within noise
octane-tsrx update 0.55 0.41 −25.5% ±47% ⚪ within noise
octane-tsrx select 0.25 0.17 −32.0% ±71% ⚪ within noise
octane-tsrx swap 0.54 0.42 −22.2% ±36% ⚪ within noise
octane-tsrx remove 0.55 0.45 −18.2% ±52% ⚪ within noise
octane-tsrx runlots 33.94 32.71 −3.6% ±31% ⚪ within noise
octane-tsrx select_lots 0.29 0.23 −20.7% ±68% ⚪ within noise
octane-tsrx clear 51.52 44.25 −14.1% ±30% ⚪ within noise
octane-jsx run 4.42 3.93 −11.1% ±22% ⚪ within noise
octane-jsx replace 10.08 8.24 −18.3% ±23% ⚪ within noise
octane-jsx add 3.92 3.38 −13.8% ±23% ⚪ within noise
octane-jsx update 0.86 0.64 −25.6% ±47% ⚪ within noise
octane-jsx select 0.57 0.48 −15.8% ±59% ⚪ within noise
octane-jsx swap 0.95 0.76 −20.0% ±72% ⚪ within noise
octane-jsx remove 1.03 0.75 −27.2% ±73% ⚪ within noise
octane-jsx runlots 32.23 31.94 −0.9% ±24% ⚪ within noise
octane-jsx select_lots 2.84 2.67 −6.0% ±26% ⚪ within noise
octane-jsx clear 54.57 47.31 −13.3% ±40% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx weather_js_raw 175,162 175,224 +62 (+0.0%) 🔴
octane-tsrx weather_js_gzip 57,141 57,163 +22 (+0.0%) 🔴
octane-tsrx weather_js_brotli 49,636 49,684 +48 (+0.1%) 🔴
octane-tsrx weather_app_gzip 9,044 9,043 −1 (−0.0%) 🟢
octane-tsrx weather_app_brotli 7,607 7,564 −43 (−0.6%) 🟢
octane-tsrx weather_fw_raw 148,427 148,489 +62 (+0.0%) 🔴
octane-tsrx weather_fw_gzip 48,097 48,120 +23 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 42,029 42,120 +91 (+0.2%) 🔴
octane-jsx js_raw 224,299 224,338 +39 (+0.0%) 🔴
octane-jsx js_gzip 71,415 71,436 +21 (+0.0%) 🔴
octane-jsx js_brotli 61,830 61,806 −24 (−0.0%) 🟢
octane-jsx app_gzip 2,944 2,942 −2 (−0.1%) 🟢
octane-jsx app_brotli 2,504 2,492 −12 (−0.5%) 🟢
octane-jsx fw_raw 215,832 215,871 +39 (+0.0%) 🔴
octane-jsx fw_gzip 68,471 68,494 +23 (+0.0%) 🔴
octane-jsx fw_brotli 59,326 59,314 −12 (−0.0%) 🟢

29 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
root-static raw 200,622 200,661 +39 (+0.0%) 🔴
root-static gzip 63,598 63,612 +14 (+0.0%) 🔴
root-static brotli 55,178 55,162 −16 (−0.0%) 🟢
hydrate-root raw 156,011 156,633 +622 (+0.4%) 🔴
hydrate-root gzip 49,972 50,218 +246 (+0.5%) 🔴
hydrate-root brotli 43,581 43,771 +190 (+0.4%) 🔴
deferred-hydration raw 218,124 218,793 +669 (+0.3%) 🔴
deferred-hydration gzip 69,372 69,637 +265 (+0.4%) 🔴
deferred-hydration brotli 59,951 60,197 +246 (+0.4%) 🔴
suspense-transition raw 165,252 165,405 +153 (+0.1%) 🔴
suspense-transition gzip 53,013 53,049 +36 (+0.1%) 🔴
suspense-transition brotli 46,281 46,264 −17 (−0.0%) 🟢
binding-base-ui-vite raw 210,816 210,855 +39 (+0.0%) 🔴
binding-base-ui-vite gzip 67,142 67,171 +29 (+0.0%) 🔴
binding-base-ui-esbuild raw 208,801 208,838 +37 (+0.0%) 🔴
binding-base-ui-esbuild gzip 67,124 67,160 +36 (+0.1%) 🔴
binding-base-ui-esbuild brotli 58,306 58,272 −34 (−0.1%) 🟢
binding-radix-vite raw 212,745 212,784 +39 (+0.0%) 🔴
binding-radix-vite gzip 67,723 67,746 +23 (+0.0%) 🔴
binding-radix-vite brotli 58,789 58,763 −26 (−0.0%) 🟢
binding-radix-esbuild raw 210,689 210,726 +37 (+0.0%) 🔴
binding-radix-esbuild gzip 67,703 67,728 +25 (+0.0%) 🔴
binding-radix-esbuild brotli 58,843 58,830 −13 (−0.0%) 🟢
binding-mantine-hooks-esbuild gzip 32,553 32,554 +1 (+0.0%) 🔴
binding-mantine-hooks-esbuild brotli 28,888 28,903 +15 (+0.1%) 🔴
binding-apollo-client-vite raw 355,865 355,904 +39 (+0.0%) 🔴
binding-apollo-client-vite gzip 111,262 111,277 +15 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,065 97,132 +67 (+0.1%) 🔴
binding-apollo-client-esbuild raw 358,854 358,891 +37 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 113,488 113,517 +29 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 98,974 98,962 −12 (−0.0%) 🟢

74 other measured values are unchanged.

CI job durations

  • 🟢 3 job(s) faster than every recent main run: typecheck checks, heavy integration (browser - chromium), test shard (Node 24, 3/4)

Compares the CI run for 54c9d60da (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 main median main range this PR Δ
wall clock (first job start to last job end) 15m 07s 13m 32s–18m 13s 13m 46s −1m 21s (−9%) ⚪ within noise
total job time 157m 32s 150m 35s–201m 42s 149m 25s −8m 07s (−5%) ⚪ within noise
typecheck checks 9m 14s 8m 23s–11m 07s 7m 48s −1m 26s (−16%) 🟢 faster
heavy integration (browser - chromium) 12m 57s 12m 15s–17m 24s 11m 17s −1m 40s (−13%) 🟢 faster
test shard (Node 24, 3/4) 10m 54s 10m 05s–13m 34s 8m 57s −1m 57s (−18%) 🟢 faster
All 26 timed jobs
job main median main range this PR Δ
React parity shard (4/4) 12m 09s 10m 46s–15m 11s 12m 41s +32s (+4%) ⚪ within noise
example apps (3/3) 3m 44s 3m 22s–6m 06s 3m 49s +5s (+2%) ⚪ within noise
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 47s 5m 30s–9m 13s 5m 50s +3s (+1%) ⚪ within noise
examples 4s 4s–4s 4s ±0s (±0%) ⚪ within noise
typecheck 4s 3s–5s 4s ±0s (±0%) ⚪ within noise
lint 4s 4s–4s 4s ±0s (±0%) ⚪ within noise
test (24) 4s 4s–5s 4s ±0s (±0%) ⚪ within noise
classify changeset release 16s 15s–17s 15s −1s (−6%) ⚪ within noise
React parity checks 16s 14s–18s 15s −1s (−6%) ⚪ within noise
CI provenance 4s 3s–5s 3s −1s (−25%) ⚪ within noise
example apps (2/3) 3m 52s 3m 41s–6m 33s 3m 50s −2s (−1%) ⚪ within noise
example apps (1/3) 3m 22s 3m 12s–6m 30s 3m 20s −2s (−1%) ⚪ within noise
React parity shard (2/4) 11m 21s 10m 32s–16m 59s 11m 05s −16s (−2%) ⚪ within noise
test shard (Node 24, 4/4) 11m 22s 11m 03s–14m 15s 11m 02s −20s (−3%) ⚪ within noise
test shard (Node 24, 2/4) 13m 18s 10m 41s–15m 15s 12m 58s −20s (−3%) ⚪ within noise
Lynx compatibility 2m 07s 1m 35s–2m 19s 1m 39s −28s (−22%) ⚪ within noise
validate publishable packages 4m 47s 3m 58s–5m 22s 4m 17s −30s (−10%) ⚪ within noise
website integration suite 6m 24s 5m 49s–6m 31s 5m 48s −36s (−9%) ⚪ within noise
Three compatibility 3m 42s 2m 41s–3m 51s 2m 56s −46s (−21%) ⚪ within noise
React parity shard (3/4) 12m 05s 10m 11s–13m 05s 11m 06s −59s (−8%) ⚪ within noise
React parity shard (1/4) 12m 04s 10m 54s–13m 55s 11m 05s −59s (−8%) ⚪ within noise
typecheck checks 9m 14s 8m 23s–11m 07s 7m 48s −1m 26s (−16%) 🟢 faster
heavy integration (browser - chromium) 12m 57s 12m 15s–17m 24s 11m 17s −1m 40s (−13%) 🟢 faster
test shard (Node 24, 1/4) 12m 57s 10m 39s–16m 33s 11m 13s −1m 44s (−13%) ⚪ within noise
lint checks 9m 40s 7m 55s–11m 33s 7m 55s −1m 45s (−18%) ⚪ within noise
test shard (Node 24, 3/4) 10m 54s 10m 05s–13m 34s 8m 57s −1m 57s (−18%) 🟢 faster

trueadm and others added 6 commits October 2, 2026 01:09
… bundles

The recoverable-error publication point checked the hold's module state
directly, so every bundle that retains noteRecoverableHydrationError kept
the hold's counter, array and push helper (+90 raw bytes in client-only
bundles such as root-static, context and the binding fixtures). Ask the
current HydrationCapability to hold the diagnostic instead: the method
ships only with hydration, which cuts the client-only cost to +39 raw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-body-diagnostics

# Conflicts:
#	packages/octane/src/runtime.ts
@trueadm
trueadm merged commit 1fa3853 into main Oct 2, 2026
30 checks passed
@trueadm
trueadm deleted the fix/hydrate-thrown-try-body-diagnostics branch October 2, 2026 07:25
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