Skip to content

fix(hydration): report a rebuilt clone's mismatch once - #1533

Merged
trueadm merged 1 commit into
mainfrom
fix/rebuilt-clone-text-diagnostic
Oct 2, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/rebuilt-clone-text-diagnostic

Conversation

@trueadm

@trueadm trueadm commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • When hydration rebuilds a template clone because its root mismatches the server node, dev now logs only the structural diagnostic. Previously it also logged a false "server rendered text …" mismatch for the same recovery.
  • recordTextMismatch skips text whose host was built fresh by mismatch recovery. The fresh clone holds the client template's own placeholder (" " for an only-child hole, <!----> swapped to "" for a sibling hole), not server text.
  • A genuine text mismatch inside an adopted server element still reports, in dev and prod.

Repro (pre-existing on main):

function Leaf(props: { value: unknown }) @{
	<i>{read(props.value) as string}</i>
}
export function Branch(props: { server?: boolean }) @{
	<div>
		@if (props.server) {
			<b class="server">{'server'}</b>
		} @else {
			<Leaf value={undefined} />
		}
	</div>
}

The server renders { server: true } and the client hydrates {}. Before this fix, dev logged:

  1. …the client expected <i> but the server rendered <b>. The mismatched subtree was rebuilt on the client. (correct)
  2. …server rendered text " " but the client rendered "ok"… (false)

The same duplicate appeared for sibling text holes, inside @try bodies, against a server @pending arm, and after a render-phase update during hydration. onRecoverableError already fired once because reports coalesce, and the final DOM was already correct.

Changes

  • packages/octane/src/runtime.ts: a guard in HydrationCapability.recordTextMismatch checks freshNodes.has(parentNode). It checks the parent rather than the node because the sibling-hole path replaces the clone's <!----> with a new, unmarked Text node.
  • packages/octane/tests/hydration/rebuilt-clone-text.test.ts plus its fixture: dev and prod compile regressions. Each case asserts exactly one structural diagnostic, no text diagnostic, one structural onRecoverableError, and the correct final DOM. A same-tag control asserts a genuine server text mismatch still reports.
  • Patch changeset for octane.

Performance

  • Hot path unchanged. The guard runs only after server and client text already differ, which only happens on mismatch. It also sits after the existing production early return for roots without an error handler.
  • Production bundle (node benchmarks/bundle-size/run-minimal.mjs hydrate-root deferred-hydration suspense-transition, baseline = HEAD runtime, same machine):
    • hydrate-root: 155342 → 155380 raw (+38), 49745 → 49758 gzip (+13), 43374 → 43429 brotli (+55)
    • deferred-hydration: +38 raw / +12 gzip / +36 brotli
    • suspense-transition (no hydration): unchanged

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 the changed runtime, test, and .tsrx fixture passes)
  • pnpm test (not run in full; see the targeted Vitest runs below)
  • targeted tests:
    • Before the fix, the 5 dev-compile cases failed, each only on the extra text diagnostic.
    • Making recordTextMismatch always skip fails the genuine-text control in dev and prod, in both projects.
    • vitest run --project octane --project octane-prod (all files) on the pre-rebase head: 1291 files / 35729 tests passed.
    • After rebasing onto main: --project octane --project octane-prod packages/octane/tests/hydration/ packages/octane/tests/map-destructured-param-write.test.ts: 210 files / 11158 tests passed.
    • pnpm sync left no generated changes.

Risk / follow-ups

  • Correctness risk is low. Every markFresh target is a client-created element or comment, and client-built hosts render their children with hydration suspended. A fresh parent therefore never holds server text, so the guard cannot hide a real mismatch.
  • Related defects found while probing, not fixed here:
    • Dynamic title/class/style on the same rebuilt clone log false value diagnostics through allowAttribute/allowClass/the style check. suppressHydrationWarning there may also keep the template's missing attribute instead of the client value.
    • A @try body that suspends after its clone was rebuilt reports the structural mismatch twice and fires onRecoverableError twice. The server content is also removed while the body is pending.

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

Low Risk
Narrow change to dev/prod hydration mismatch reporting on an already-mismatched path; genuine adopted-server text mismatches remain reported.

Overview
Fixes duplicate hydration diagnostics when mismatch recovery rebuilds a template clone whose root does not match server markup. Development builds previously logged the correct structural rebuild warning and a second, false server-rendered text warning because text holes in the fresh clone were compared against the client template’s placeholder, not real server text.

HydrationCapability.recordTextMismatch now returns early when the text node’s parent is in freshNodes (client-built during recovery), including sibling-hole cases where the text node itself is replaced. Genuine text mismatches inside adopted server elements are unchanged.

Adds a hydration fixture and Vitest coverage (dev and prod compile) for @if, @try, @pending, render-phase updates, sibling text holes, plus a control that still expects a real text mismatch. Includes an octane patch changeset.

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

When a template's root does not match the server node, hydration reports
the structural mismatch and clones the template fresh on the client. That
clone's text holes still bound through the hydrating text path and
compared the template's own placeholder as server text, so development
builds logged a second, false text mismatch for the same recovery.

recordTextMismatch now skips text whose host was built fresh by mismatch
recovery. The check runs only on the cold mismatch path. A genuine text
mismatch inside an adopted server element still reports.

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:51
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-reachability: 6 value(s) increased

Compares f647ceff6 with c3bcbf099 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 4.13 3.89 −5.8% ±19% ⚪ within noise
octane-tsrx replace 10.14 9.28 −8.5% ±17% ⚪ within noise
octane-tsrx add 4.01 4.10 +2.2% ±30% ⚪ within noise
octane-tsrx update 0.77 0.61 −20.8% ±65% ⚪ within noise
octane-tsrx select 0.30 0.24 −20.0% ±48% ⚪ within noise
octane-tsrx swap 0.70 0.43 −38.6% ±45% ⚪ within noise
octane-tsrx remove 0.64 0.51 −20.3% ±42% ⚪ within noise
octane-tsrx runlots 35.15 34.22 −2.6% ±18% ⚪ within noise
octane-tsrx select_lots 0.35 0.33 −5.7% ±46% ⚪ within noise
octane-tsrx clear 49.28 50.26 +2.0% ±10% ⚪ within noise
octane-jsx run 4.29 4.17 −2.8% ±32% ⚪ within noise
octane-jsx replace 9.92 9.84 −0.8% ±16% ⚪ within noise
octane-jsx add 3.81 3.90 +2.4% ±29% ⚪ within noise
octane-jsx update 0.74 0.80 +8.1% ±38% ⚪ within noise
octane-jsx select 0.58 0.51 −12.1% ±47% ⚪ within noise
octane-jsx swap 0.98 0.93 −5.1% ±40% ⚪ within noise
octane-jsx remove 0.91 0.91 −0.0% ±62% ⚪ within noise
octane-jsx runlots 35.33 33.60 −4.9% ±21% ⚪ within noise
octane-jsx select_lots 2.87 2.83 −1.4% ±31% ⚪ within noise
octane-jsx clear 52.87 52.40 −0.9% ±25% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 155,342 155,380 +38 (+0.0%) 🔴
hydrate-root gzip 49,745 49,758 +13 (+0.0%) 🔴
hydrate-root brotli 43,374 43,429 +55 (+0.1%) 🔴
deferred-hydration raw 217,607 217,645 +38 (+0.0%) 🔴
deferred-hydration gzip 69,239 69,251 +12 (+0.0%) 🔴
deferred-hydration brotli 59,791 59,827 +36 (+0.1%) 🔴

99 other measured values are unchanged.

CI job durations

  • 🟢 4 job(s) faster than every recent main run: example apps (3/3), typecheck checks, lint checks, React parity shard (4/4)

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

@trueadm
trueadm merged commit ad203e9 into main Oct 2, 2026
52 checks passed
@trueadm
trueadm deleted the fix/rebuilt-clone-text-diagnostic branch October 2, 2026 00:11
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