Skip to content

feat(ui): support CSP nonce and template placeholder in HtmlServer.document - #11448

Open
MaxFabian25 wants to merge 1 commit into
Effect-TS:mainfrom
MaxFabian25:feat/html-server-document-nonce
Open

MaxFabian25 wants to merge 1 commit into
Effect-TS:mainfrom
MaxFabian25:feat/html-server-document-nonce

Conversation

@MaxFabian25

Copy link
Copy Markdown
Contributor

Summary

  • Add optional DocumentOptions (nonce and noncePlaceholder) to HtmlServer.document so SSR apps using strict Content-Security-Policy headers can attach a per-request nonce to the hydration state <script> tag and replace Vite's CSP nonce placeholder in the static HTML template.
  • Escape the nonce for both single- and double-quoted attribute contexts (&, ", ', <, >) and perform placeholder substitution only on the static template before inserting rendered HTML, head, state, or attributes.
  • Wire Vite's config.html?.cspNonce as the default noncePlaceholder in HtmlServerVite (virtual:effect/ui/document).
  • Preserve byte-identical output when nonce is omitted or empty.

Testing

  • Added unit tests in packages/effect/test/ui/html/HtmlServer.test.ts covering attribute escaping, template-only placeholder substitution, hydration script nonce injection, and omitted/empty nonce parity.
  • Added dev and production Vite build nonce tests in packages/effect/test/ui/html/HtmlServerVite.test.ts.
  • Verified with vitest, pnpm check, oxlint, dprint check, and pnpm jsdocs --check.

@changeset-bot

changeset-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d1132e0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 43 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-amazon-bedrock Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/chat-discord Minor
@effect/chat-slack Minor
@effect/chat-teams Minor
@effect/chat-telegram Minor
@effect/chat-whatsapp Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-cloudflare Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor
@effect/ui-devtools Minor
@effect/ui-native Minor
@effect/ui-opentui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 40.45 KB 40.45 KB 0.00 KB (0.00%)
basic.ts 6.66 KB 6.66 KB 0.00 KB (0.00%)
batching.ts 11.90 KB 11.90 KB 0.00 KB (0.00%)
brand.ts 6.91 KB 6.91 KB 0.00 KB (0.00%)
cache.ts 12.16 KB 12.16 KB 0.00 KB (0.00%)
config.ts 23.89 KB 23.89 KB 0.00 KB (0.00%)
differ.ts 22.75 KB 22.75 KB 0.00 KB (0.00%)
http-client.ts 28.90 KB 28.90 KB 0.00 KB (0.00%)
http-router.ts 39.57 KB 39.57 KB 0.00 KB (0.00%)
logger.ts 12.34 KB 12.34 KB 0.00 KB (0.00%)
metric.ts 10.16 KB 10.16 KB 0.00 KB (0.00%)
optic.ts 7.14 KB 7.14 KB 0.00 KB (0.00%)
pubsub.ts 16.89 KB 16.89 KB 0.00 KB (0.00%)
queue.ts 13.71 KB 13.71 KB 0.00 KB (0.00%)
schedule.ts 12.46 KB 12.46 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.50 KB 14.50 KB 0.00 KB (0.00%)
schema-binary.ts 43.50 KB 43.50 KB 0.00 KB (0.00%)
schema-class.ts 22.50 KB 22.50 KB 0.00 KB (0.00%)
schema-codegen.ts 33.86 KB 33.86 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.95 KB 30.95 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.69 KB 28.69 KB 0.00 KB (0.00%)
schema-string-transformation.ts 16.26 KB 16.26 KB 0.00 KB (0.00%)
schema-string.ts 12.78 KB 12.78 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.86 KB 16.86 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 40.00 KB 40.00 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.64 KB 21.64 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.81 KB 21.81 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.90 KB 21.90 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.94 KB 26.94 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.96 KB 21.96 KB 0.00 KB (0.00%)
schema.ts 21.61 KB 21.61 KB 0.00 KB (0.00%)
stm.ts 14.96 KB 14.96 KB 0.00 KB (0.00%)
stream.ts 10.70 KB 10.70 KB 0.00 KB (0.00%)
supervisor.ts 12.13 KB 12.13 KB 0.00 KB (0.00%)

UI Bundle Size

Vite 8.4.0/Rolldown, production, default Oxc minification, es2023, ES modules, gzip level 9 per chunk. effect 4.2.0, Node v26.12.1. Effect-only client: 27408 B gzip (Δ 0 B vs base).

App Chunks Raw bytes Gzip bytes Added gzip B Δ raw bytes Δ gzip bytes
counter 1 175919 60749 33341 0 0
features 1 185571 64233 36825 0 0
menu 1 290366 98929 71521 0 0

This branch is waiting to be deployed

1 waiting deployment
fork — d1132e03 Waiting Dec 3, 2026 by MaxFabian25 via approval-gate #29430
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant