Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nonce-local-projection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solidjs/vite-plugin': patch
---

The generated start-mode server handler no longer imports `scriptNonce`/`styleNonce` from `@solidjs/web`. It projects each destination of a `{ script, style }` nonce with a local helper instead. Those helpers are internal to `@solidjs/web` (solidjs/solid#4016), and its single-script surfaces now take the full `CSPNonce` themselves. The handler works with `@solidjs/web` versions both before and after that change.
16 changes: 12 additions & 4 deletions src/ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ export function startServe(
const composeServerFunctions = internal.serverFunctions;

const lines = [
`import { createRequestEvent, createSSRResponse, commitEventResponse, scriptNonce, styleNonce, isResponseEnvelope } from '@solidjs/web';`,
`import { createRequestEvent, createSSRResponse, commitEventResponse, isResponseEnvelope } from '@solidjs/web';`,
...(isBuild ? [`import { reportServerError } from 'solid-js/internal';`] : []),
`import { provideRequestEvent } from ${JSON.stringify(STORAGE_SOURCE)};`,
`import * as entry from ${JSON.stringify(entryServerSpec())};`,
Expand Down Expand Up @@ -1326,12 +1326,20 @@ export function startServe(
` return value ? ' nonce="' + escapeAttribute(value) + '"' : '';`,
`}`,
``,
// One destination of a `CSPNonce` (a string, or a `{ script, style }`
// pair with `false` for an un-nonced destination). Kept local: the
// matching @solidjs/web helpers are internal.
`function destinationNonce(nonce, destination) {`,
` const value = typeof nonce === 'string' ? nonce : nonce && nonce[destination];`,
` return typeof value === 'string' && value ? value : undefined;`,
`}`,
``,
// The client entry and the dev scripts take the script destination of
// a `{ script, style }` pair; the dev styles and the csp-nonce meta the
// style destination.
`function createHtmlChunkTransform(clientEntry, extraHead, nonce) {`,
` const nonceAttr = nonceAttribute(scriptNonce(nonce));`,
` const styleAttr = nonceAttribute(styleNonce(nonce));`,
` const nonceAttr = nonceAttribute(destinationNonce(nonce, 'script'));`,
` const styleAttr = nonceAttribute(destinationNonce(nonce, 'style'));`,
` let first = true;`,
` let injected = false;`,
` return (chunk) => {`,
Expand Down Expand Up @@ -1527,7 +1535,7 @@ export function startServe(
// single-script surfaces.
` return createSSRResponse(result, event, {`,
` responseInit: options.responseInit,`,
` nonce: scriptNonce(nonce) || null,`,
` nonce: destinationNonce(nonce, 'script') || null,`,
` transformChunk: createHtmlChunkTransform(clientEntry, options.devHead, nonce),`,
` });`,
`}`,
Expand Down
Loading