Skip to content

fix(octane): keep adopted raw HTML until __html changes, as React 19.3 - #2228

Merged
trueadm merged 2 commits into
mainfrom
perf/adopted-html-first-write
Oct 23, 2026
Merged

trueadm merged 2 commits into
mainfrom
perf/adopted-html-first-write

Conversation

@trueadm

@trueadm trueadm commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • After hydration, an adopted dangerouslySetInnerHTML now stays until a render passes a different __html string, as in React 19.3. Previously the first render after hydration reparsed and replaced it, even with the same string.
  • Hydration accepts the server's content as the client's __html string (the raw-HTML cache, journaled like any write). Production still compares nothing, and development still warns about a difference at hydration.
  • This also covers a mismatch: the server's HTML stays until __html changes. That reverses fix(octane): preserve unchanged trusted HTML child identity #1278's repair-on-next-render, at the user's request, for React 19.3 parity.

Why

Trusted Types browser coverage (#2224) hydrates a page and then re-renders it. Every adopted raw-HTML host was rewritten on that first re-render, even with an unchanged string. Besides the CPU cost, this replaces the nodes, so iframes and media inside the HTML reload and listeners or state that scripts attached inside it are lost. Octane already skipped same-string writes on the client afterwards, and React 19.3 skips them after hydration too.

React probe

Real React with hydrateRoot, then two same-string re-renders, then a changed string (jsdom, react-dom/server markup, inline {__html} wrapper). "kept" means the server's first child node survived:

react-dom match mismatch (<b>server</b> vs <i>client</i>) other server spelling (<b data-note="&amp;"/>) changed __html afterwards
18.3.1 kept kept, server HTML stays — —
19.0.0 / 19.2.7 rewritten on every render rewritten to the client's on every render rewritten on every render rewritten
19.3.0 kept kept, server HTML stays kept rewritten
  • 19.0 to 19.2: setProp writes innerHTML whenever the {__html} object changes, with no compare.
  • 19.3: compares prevValue.__html !== nextHtml again, which is React 18's behavior.
  • A peer session's independent probe of 19.2.8 and 19.3.0 agrees.

Measurement (headless Chromium, playwright 1.61)

This is what one avoided rewrite costs, for a single raw-HTML host. Each figure is the median of 15 rounds; three runs agreed within about 10%.

raw-HTML subtree rewrite (JS) rewrite + forced layout
1 short <p> (63 B, 3 elements) 3.7 µs 13.5 µs
article section (4.8 KB, 138 elements) 50 µs 262 µs
8 sections (39 KB, 1,104 elements) 377 µs 2.0 ms
40 sections (194 KB, 5,520 elements) 1.9 ms 9.8 ms

The change adds no read or compare. Hydration adds one journaled expando write per raw-HTML host. (The first commit compared el.innerHTML once instead, which cost 0.19 / 8.8 / 71 / 358 µs on the same subtrees. The second commit removes that compare.)

Changes

  • runtime/host-props.ts setHTML: the hydration branch records DANGER_HTML_VALUE = next, journaled, so a dropped hydrating attempt restores it. The write path is unchanged from main.
  • runtime/hydration.ts adoptHTML: comment only.
  • docs/differences-from-react.md: the hydration bullet now states React 19.3 behavior. Raw HTML follows the same "kept until the client changes it" rule as attributes, and the bullet notes 19.0 to 19.2's rewrite.
  • tests/trusted-html.test.ts:
    • "renders, hydrates, updates, and clears HTML": the adopted <b> keeps its identity across the first update.
    • The parser-normalized case is now "…keeps it on the next render".
    • fix(octane): preserve unchanged trusted HTML child identity #1278's case is now "keeps hydration mismatches until __html changes", with and without suppressHydrationWarning. The server's <b> survives a same-string render, then a changed string writes <i>changed</i>.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check on the 5 changed files passes.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files on host-props.ts and hydration.ts passes. The test file reports 22 TS4111 errors on fixture-module client.X accesses, all on lines this change did not add.
  • pnpm test: left to CI (local runs limited to one file in one project).
  • Targeted tests, trusted-html.test.ts in --project octane, 10/10 pass, covering dev and prod compile.
    • Break check: with the adoption seed removed (main's behavior), 6 cases fail across both modes: identity, other spelling, and mismatch kept.
    • First commit: before it, the identity assertion also failed on main.
  • Other raw-HTML hydration suites (conformance/hydration-mismatch, conformance/reconnecting-wave4c, hydration/stale-capture-recovery, hydration/*-value-mismatch) assert only the state right after hydration, which is unchanged. A dormant island whose captures changed still hydrates with the server's value and then writes the new string. Left to CI.
  • pnpm sync: no generated changes.
  • perf-review: node scripts/perf-review-scan.mjs found 0 candidates.
    • Hot path: setHTML is the per-write path, unchanged from main. The hydration branch adds one journalRootProperty call, which returns early outside a root transaction, and one symbol-expando write per adopted raw-HTML host.
    • Shapes: no hot record or Block/Scope field changes, no DOM reads, no scheduling.
    • No must-fix findings.
  • concise-code: src +9 −8 (runtime code +3 −1; the rest is comments). New files: the changeset only. No new exports. Alternatives:
    • (a) Compare el.innerHTML once on the first write (this PR's first commit). About 5 code lines plus a read that costs up to about 18% of a rewrite on a mismatch, and it diverges from 19.3 on mismatches.
    • (b) Compare whenever the cache is undefined. It also reads on fresh client mounts, and it is wrong after a raw-HTML → children → raw-HTML switch.
    • Bytes (CI bench report): +18 raw, +5 to +14 gzip, +15 to +41 brotli on runtime rows such as full_fw and hydrate-frame. The cost is the journaled DANGER_HTML_VALUE write in setHTML's hydration branch. All 64 js-framework work counters are unchanged.

Risk / follow-ups

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.


Note

Medium Risk
Touches hydration and dangerouslySetInnerHTML commit semantics; wrong caching could skip needed DOM updates or leave mismatched HTML longer than before (intentional React 19.3 divergence for mismatches).

Overview
Adopted dangerouslySetInnerHTML no longer reparses server DOM on the first client render when the render’s __html string matches what hydration recorded. setHTML now journals and sets DANGER_HTML_VALUE to that string during hydration adoption, so the existing host[DANGER_HTML_VALUE] === next early return skips innerHTML and preserves server node identity (iframes, listeners, Trusted Types flows).

innerHTML still runs when the string actually changes. Hydration mismatches keep server markup until __html changes—aligned with React 19.3, documented in docs/differences-from-react.md (vs React 19.0–19.2 rewriting on every new {__html} object). trusted-html.test.ts expectations updated accordingly.

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

Hydration marks an adopted dangerouslySetInnerHTML element as holding the
server's content, still without comparing anything in production. The first
write after hydration compares the element's serialization with the render's
__html string once: equal content keeps its nodes, as React 19.3 keeps an
unchanged string; a mismatch or another spelling is rewritten as before.

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 perf PR: performance work labels Oct 23, 2026
@trueadm
trueadm marked this pull request as ready for review October 23, 2026 19:06
Hydration now accepts an adopted dangerouslySetInnerHTML's server content as
the client's __html string, still comparing nothing in production, so only a
render with a different string rewrites it. This matches React 19.3, which
compares the previous __html again (19.0 to 19.2 rewrote on every new
wrapper), including a mismatch, which stays until the string changes.
Replaces the one-time innerHTML compare from the previous commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm trueadm changed the title perf(octane): keep matching adopted raw HTML on the first update fix(octane): keep adopted raw HTML until __html changes, as React 19.3 Oct 23, 2026
@github-actions github-actions Bot added fix PR: bug fix and removed perf PR: performance work labels Oct 23, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website 30864fb Commit Preview URL

Branch Preview URL
Oct 23 2026, 07:13 PM

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 22 value(s) increased
  • 🔴 bundle-reachability: 16 value(s) increased

Compares af767d770, the merge commit's first parent with 6f4d219e8 on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 3.742 3.533 ±0.0% −6.0% … +3.3% ⚪ within noise
octane-tsrx replace 7.867 8.242 +2.0% −4.7% … +11.8% ⚪ within noise
octane-tsrx add 2.825 2.775 ±0.0% −3.7% … +3.8% ⚪ within noise
octane-tsrx update 0.100 0.097 +0.3% −4.1% … +4.5% ⚪ within noise
octane-tsrx select 0.007 0.007 +3.3% −5.1% … +7.6% ⚪ within noise
octane-tsrx swap 0.023 0.022 +1.2% −4.7% … +9.4% ⚪ within noise
octane-tsrx remove 0.017 0.017 +0.8% −2.7% … +3.1% ⚪ within noise
octane-tsrx runlots 25.742 25.883 +4.9% −0.6% … +9.9% ⚪ within noise
octane-tsrx select_lots 0.007 0.007 −0.9% −2.6% … +0.6% ⚪ within noise
octane-tsrx clear 51.483 51.542 −0.9% −2.7% … +2.0% ⚪ within noise
octane-jsx run 3.858 3.608 −1.3% −3.9% … ±0.0% ⚪ within noise
octane-jsx replace 6.333 6.592 +0.8% −3.7% … +4.8% ⚪ within noise
octane-jsx add 3.758 3.725 ±0.0% −2.6% … +2.5% ⚪ within noise
octane-jsx update 0.187 0.184 −0.9% −3.8% … −0.0% ⚪ within noise
octane-jsx select 0.098 0.093 −1.7% −3.6% … −1.1% ⚪ within noise
octane-jsx swap 0.137 0.146 ±0.0% −0.6% … +1.2% ⚪ within noise
octane-jsx remove 0.122 0.123 +0.0% −0.7% … +0.7% ⚪ within noise
octane-jsx runlots 28.900 28.625 +0.8% −2.7% … +4.2% ⚪ within noise
octane-jsx select_lots 1.033 1.039 +1.6% −0.0% … +3.7% ⚪ within noise
octane-jsx clear 52.825 54.658 −1.3% −6.0% … +5.2% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx bindings_js_raw 694,215 694,211 −4 (−0.0%) 🟢
octane-tsrx bindings_js_gzip 229,470 229,467 −3 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 195,415 195,385 −30 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 98,996 99,049 +53 (+0.1%) 🔴
octane-tsrx bindings_fw_raw 333,223 333,219 −4 (−0.0%) 🟢
octane-tsrx bindings_fw_gzip 110,211 110,208 −3 (−0.0%) 🟢
octane-tsrx bindings_fw_brotli 96,419 96,336 −83 (−0.1%) 🟢
octane-tsrx wayfinder_js_raw 449,180 449,198 +18 (+0.0%) 🔴
octane-tsrx wayfinder_js_gzip 148,180 148,192 +12 (+0.0%) 🔴
octane-tsrx wayfinder_js_brotli 129,424 129,428 +4 (+0.0%) 🔴
octane-tsrx pagecraft_oxc_js_raw 547,454 547,450 −4 (−0.0%) 🟢
octane-tsrx pagecraft_oxc_js_gzip 172,222 172,221 −1 (−0.0%) 🟢
octane-tsrx pagecraft_oxc_js_brotli 146,348 146,345 −3 (−0.0%) 🟢
octane-tsrx pagecraft_esbuild_js_raw 580,958 580,975 +17 (+0.0%) 🔴
octane-tsrx pagecraft_esbuild_js_gzip 187,946 187,970 +24 (+0.0%) 🔴
octane-tsrx pagecraft_esbuild_js_brotli 159,940 159,924 −16 (−0.0%) 🟢
octane-tsrx full_fw_raw 543,027 543,045 +18 (+0.0%) 🔴
octane-tsrx full_fw_gzip 169,818 169,825 +7 (+0.0%) 🔴
octane-tsrx full_fw_brotli 144,464 144,490 +26 (+0.0%) 🔴
octane-jsx js_raw 162,513 162,509 −4 (−0.0%) 🟢
octane-jsx js_brotli 46,946 46,923 −23 (−0.0%) 🟢
octane-jsx app_gzip 3,581 3,582 +1 (+0.0%) 🔴
octane-jsx app_brotli 2,921 2,924 +3 (+0.1%) 🔴
octane-jsx fw_raw 151,460 151,456 −4 (−0.0%) 🟢
octane-jsx fw_gzip 49,527 49,526 −1 (−0.0%) 🟢
octane-jsx fw_brotli 44,025 43,999 −26 (−0.1%) 🟢
octane-jsx shell_js_raw 336,401 336,419 +18 (+0.0%) 🔴
octane-jsx shell_js_gzip 109,703 109,717 +14 (+0.0%) 🔴
octane-jsx shell_js_brotli 95,225 95,221 −4 (−0.0%) 🟢
octane-jsx shell_app_gzip 760 765 +5 (+0.7%) 🔴
octane-jsx shell_app_brotli 673 654 −19 (−2.8%) 🟢
octane-jsx shell_fw_raw 335,308 335,326 +18 (+0.0%) 🔴
octane-jsx shell_fw_gzip 108,943 108,952 +9 (+0.0%) 🔴
octane-jsx shell_fw_brotli 94,552 94,567 +15 (+0.0%) 🔴
octane-jsx shell_client_js_raw 281,057 281,053 −4 (−0.0%) 🟢
octane-jsx shell_client_js_gzip 91,061 91,059 −2 (−0.0%) 🟢
octane-jsx shell_client_js_brotli 79,682 79,714 +32 (+0.0%) 🔴
octane-jsx shell_client_app_gzip 770 768 −2 (−0.3%) 🟢
octane-jsx shell_client_app_brotli 669 663 −6 (−0.9%) 🟢
octane-jsx shell_client_fw_raw 279,956 279,952 −4 (−0.0%) 🟢
octane-jsx shell_client_fw_brotli 79,013 79,051 +38 (+0.0%) 🔴
octane-jsx full_fw_raw 543,027 543,045 +18 (+0.0%) 🔴
octane-jsx full_fw_gzip 169,818 169,825 +7 (+0.0%) 🔴
octane-jsx full_fw_brotli 144,464 144,490 +26 (+0.0%) 🔴

67 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-frame raw 349,465 349,483 +18 (+0.0%) 🔴
hydrate-frame gzip 112,266 112,273 +7 (+0.0%) 🔴
hydrate-frame brotli 97,577 97,519 −58 (−0.1%) 🟢
descriptor-children raw 159,528 159,524 −4 (−0.0%) 🟢
descriptor-children gzip 51,838 51,836 −2 (−0.0%) 🟢
descriptor-children brotli 46,117 46,072 −45 (−0.1%) 🟢
split-shell raw 400,415 400,433 +18 (+0.0%) 🔴
split-shell gzip 130,539 130,533 −6 (−0.0%) 🟢
split-shell brotli 113,703 113,729 +26 (+0.0%) 🔴
split-shell-runtime raw 323,712 323,730 +18 (+0.0%) 🔴
split-shell-runtime gzip 104,262 104,267 +5 (+0.0%) 🔴
split-shell-runtime brotli 90,025 90,066 +41 (+0.0%) 🔴
binding-base-ui-vite raw 170,184 170,180 −4 (−0.0%) 🟢
binding-base-ui-vite gzip 55,568 55,567 −1 (−0.0%) 🟢
binding-base-ui-vite brotli 49,319 49,334 +15 (+0.0%) 🔴
binding-base-ui-esbuild raw 198,512 198,530 +18 (+0.0%) 🔴
binding-base-ui-esbuild gzip 66,752 66,763 +11 (+0.0%) 🔴
binding-base-ui-esbuild brotli 59,054 59,076 +22 (+0.0%) 🔴
binding-radix-vite raw 169,516 169,512 −4 (−0.0%) 🟢
binding-radix-vite gzip 55,180 55,181 +1 (+0.0%) 🔴
binding-radix-vite brotli 49,025 48,976 −49 (−0.1%) 🟢
binding-radix-esbuild raw 197,895 197,913 +18 (+0.0%) 🔴
binding-radix-esbuild gzip 66,412 66,434 +22 (+0.0%) 🔴
binding-radix-esbuild brotli 58,816 58,735 −81 (−0.1%) 🟢
binding-apollo-client-vite raw 316,761 316,757 −4 (−0.0%) 🟢
binding-apollo-client-vite gzip 99,044 99,043 −1 (−0.0%) 🟢
binding-apollo-client-vite brotli 87,645 87,690 +45 (+0.1%) 🔴
binding-apollo-client-esbuild raw 352,606 352,624 +18 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 100,974 100,955 −19 (−0.0%) 🟢

94 other measured values are unchanged.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp 30864fb Commit Preview URL

Branch Preview URL
Oct 23 2026, 07:13 PM

@trueadm
trueadm merged commit de689bf into main Oct 23, 2026
34 checks passed
@trueadm
trueadm deleted the perf/adopted-html-first-write branch October 23, 2026 20:37
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