Skip to content

test(octane): cover Trusted Types hydration, streamed table/SVG boundaries and deferred activation - #2224

Merged
trueadm merged 5 commits into
mainfrom
test/trusted-types-coverage
Oct 23, 2026
Merged

trueadm merged 5 commits into
mainfrom
test/trusted-types-coverage

Conversation

@trueadm

@trueadm trueadm commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follows #2221, the re-land of Trusted Types support (#2162) on main. #2221 has merged, and this PR now targets main with only its test changes.

This extends the enforced Trusted Types browser suite to the cases that docs/async-signals-streaming-ssr.md (Trusted Types compatibility) lists and #2162 did not test. Every case runs under require-trusted-types-for 'script'; trusted-types octane octane-stream app, with no default policy, in both development and production bundles:

  • hydrateRoot: hydrates renderToString output.
  • Streamed page: the shell hydrates while a boundary inside <tbody> and one inside <svg> are still pending. Both segments then reveal through the octane-stream JSON carrier and hydrate.
  • Deferred activation: <Hydrate when={interaction({ events: 'click' })}> stays dormant until a click activates it, then replays the click.
  • Report-only: one run per bundle with Content-Security-Policy-Report-Only visits all three pages and asserts zero violations.

After hydration, each page mounts a fresh <tr> in <tbody> and a fresh <rect> in <svg>, so their templates parse in table and SVG context. It also rewrites the adopted dangerouslySetInnerHTML with the application's TrustedHTML.

Each case asserts:

  • no securitypolicyviolation;
  • no page or console errors;
  • no recoverable hydration errors;
  • the server's elements are adopted, not replaced;
  • the new nodes' table and SVG placement and namespace;
  • the kept server HTML.

The tests found no Octane sink writing a string on these paths, so this PR has no source change.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check packages/octane/tests/browser/trusted-types/ passes.

  • pnpm typecheck: not run. Browser tests are outside every typecheck program (packages/octane/tsconfig.json excludes tests). pnpm typecheck:files on the three files reports only the two pre-existing exactOptionalPropertyTypes errors in the untouched tests/_server-fixture.ts, which main's existing browser tests share.

  • pnpm test: not run.

  • targeted tests: vitest run --project octane-events-browser packages/octane/tests/browser/trusted-types/trusted-types.test.ts. 10/10 pass on the merge with main af767d7 (a66718d), and three consecutive runs on an earlier base were clean.

  • Each case fails against a realistic broken sink. Each sink was reverted temporarily, and the reverts were not committed:

    Sink reverted to a string write Cases that fail
    parseTemplate (runtime/templates.ts) all 10
    octane-stream policy in the stream bootstrap the client-render and streamed-page cases, enforced and report-only
    setHTML passing the string to the dev hydration compare the dev hydration, streamed and deferred cases (violation, lost adoption, recoverable error); prod passes, as expected
    setHTML trustedOr all 10
  • perf-review: not applicable. The diff is test-only.

  • concise-code:

    • Size: src +0 −0 (runtime +0 −0). The tests extend the existing trusted-types fixture, client and test file; there are no new files.
    • New exports, all from the test fixture app.tsrx: PAGE_HTML, HydratedPage, StreamedPage and DeferredPage, used by the server routes and the client entry.
    • Alternative rejected: a separate test file per case, which would duplicate the bundle build and the server.
    • Bytes: not applicable.

Risk / follow-ups

  • No browser case reaches two routed sinks under enforcement: the streamed-region receiver's placeFullRegion (hydration/stream-receiver.ts, fetched regions) and binding-view fragments (dom-binding-program.ts createFragment). Reverting either breaks nothing here.
  • Resource scripts in runtime/head.ts (preinit, preinitModule, <script async src>) assign script.src a sanitized string.
    • Under enforcement with no default policy this throws.
    • A TrustedScriptURL passed as a resource script's src is stringified, where React 19.3 likely passes the object through.
    • Not verified in a browser; worth its own case.

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

Low Risk
Test-only changes to the trusted-types browser fixture and Playwright suite; no runtime or production code paths are modified.

Overview
Extends the enforced Trusted Types Playwright suite beyond client-only sinks to SSR hydration, streaming, and deferred <Hydrate>—all under require-trusted-types-for 'script' with octane, octane-stream, and app policies, in development and production bundles.

The fixture gains HydratedPage, StreamedPage, and DeferredPage (plus table/SVG rows that mount after a toggle) so the client can hydrateRoot server HTML where the server used a plain string and the app supplies TrustedHTML. The test HTTP server now serves /hydrate, /stream, and /deferred (with a controllable stream release for pending boundaries inside <tbody> and <svg>), and the client entry routes by pathname between the existing client-render path and hydration.

New assertions cover no CSP violations, no recoverable hydration errors, DOM adoption of server nodes, correct table/SVG placement, and post-update dangerouslySetInnerHTML with TrustedHTML. A report-only CSP block runs the same hydration scenarios and expects zero violations.

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

trueadm and others added 4 commits October 23, 2026 18:36
Re-lands #2162. It merged into `next` on 2026-10-20, after #2103 had
already integrated `next` into `main`, and `next` was then deleted, so
the change never reached `main`. This is the #2162 squash commit
(424e5cc) cherry-picked onto `main` without changes.

A TrustedHTML, TrustedScript, or TrustedScriptURL passed to
dangerouslySetInnerHTML or an attribute now reaches its DOM sink as the
object, as in React 19.3, so it works under an enforced
require-trusted-types-for 'script' CSP.

Markup Octane parses itself (compiled templates, binding fragments,
streamed regions) goes through a module-private `octane` policy, created
at module load with the native `String` as its rule, and the streaming
bootstrap's JSON carrier through `octane-stream`. Application strings
never go through either.

Refs #2053.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
main's test config rejects reading a server fixture's export through its
index signature, so name the fixture module type, as other tests do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
setScriptText updated an existing Text node in place, so after the first
write a TrustedScript never reached the script's textContent sink, and
under enforcement a string update was not rejected. An unchanged body
still writes nothing; a changed one now always assigns textContent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aries and deferred activation

Run the enforced `require-trusted-types-for 'script'` browser suite, which
has no default policy, over the cases the streaming design doc lists:
hydrateRoot of renderToString output, a streamed page whose <tbody> and
<svg> boundaries reveal after the shell hydrates, and a deferred
<Hydrate> boundary that a click activates. Each page then mounts fresh
table and SVG content and rewrites its adopted dangerouslySetInnerHTML.
A report-only run checks that the same pages raise no violations.

Each case passes in dev and prod bundles and fails when the template,
stream-bootstrap, setHTML or dev hydration-compare sink writes a string.

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 test PR: tests only labels Oct 23, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 23, 2026 •

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 a66718d Commit Preview URL

Branch Preview URL
Oct 23 2026, 06:42 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 23, 2026 •

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 a66718d Commit Preview URL

Branch Preview URL
Oct 23 2026, 06:41 PM

Base automatically changed from feat/trusted-types-main to main October 23, 2026 18:37
…verage

# Conflicts:
#	packages/octane/tests/browser/trusted-types/app.tsrx
#	packages/octane/tests/browser/trusted-types/client.ts
#	packages/octane/tests/browser/trusted-types/trusted-types.test.ts
@trueadm
trueadm marked this pull request as ready for review October 23, 2026 18:39
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares af767d770, the merge commit's first parent with 95cef13a4 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.533 3.583 −0.0% −6.9% … +3.2% ⚪ within noise
octane-tsrx replace 8.100 8.492 −1.3% −9.4% … +14.5% ⚪ within noise
octane-tsrx add 3.983 4.650 +8.1% −10.7% … +22.0% ⚪ within noise
octane-tsrx update 0.104 0.102 −3.0% −6.3% … +1.3% ⚪ within noise
octane-tsrx select 0.008 0.008 −3.1% −12.8% … +2.2% ⚪ within noise
octane-tsrx swap 0.022 0.022 −3.7% −7.4% … +1.9% ⚪ within noise
octane-tsrx remove 0.024 0.026 +1.7% −12.7% … +14.7% ⚪ within noise
octane-tsrx runlots 31.958 30.917 −1.7% −8.9% … +6.0% ⚪ within noise
octane-tsrx select_lots 0.009 0.010 −2.9% −5.5% … +8.0% ⚪ within noise
octane-tsrx clear 68.033 73.800 −0.4% −8.7% … +8.8% ⚪ within noise
octane-jsx run 7.000 6.283 −10.4% −16.7% … +13.5% ⚪ within noise
octane-jsx replace 10.092 11.075 −0.5% −4.4% … +4.0% ⚪ within noise
octane-jsx add 6.558 6.708 +2.1% −6.0% … +13.0% ⚪ within noise
octane-jsx update 0.290 0.284 −4.1% −12.5% … +12.6% ⚪ within noise
octane-jsx select 0.148 0.144 −9.8% −13.6% … −1.4% ⚪ within noise
octane-jsx swap 0.549 0.515 −5.8% −31.3% … +10.2% ⚪ within noise
octane-jsx remove 0.252 0.260 −3.1% −13.8% … +12.1% ⚪ within noise
octane-jsx runlots 38.650 37.108 −5.9% −10.5% … +5.4% ⚪ within noise
octane-jsx select_lots 1.416 1.401 +3.4% −1.3% … +7.7% ⚪ within noise
octane-jsx clear 67.700 65.158 +4.0% −1.0% … +9.3% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 111 measured values.

Public-import reachability bundles (bytes)

No changes across 123 measured values.

@trueadm
trueadm merged commit 8e60520 into main Oct 23, 2026
52 checks passed
@trueadm
trueadm deleted the test/trusted-types-coverage branch October 23, 2026 20:36
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 test PR: tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant