Skip to content

Commit 440f88f

Browse files
committed
fix(web): keep scriptNonce/styleNonce exported as an internal plugin seam
The published @solidjs/vite-plugin's generated handler still imports both, so removing the exports breaks every start-mode build. They stay exported, marked @internal, until the plugin stops importing them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_018LY7F9czoRqdMEvk2QwPr1
1 parent 4a33bd7 commit 440f88f

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

‎.changeset/single-script-nonce.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@solidjs/web": patch
33
---
44

5-
`HydrationScript`, `generateHydrationScript` and `createSSRResponse` now take the same `CSPNonce` as `renderToString`/`renderToStream` (a string or a `{ script, style }` pair) and use its script half, so `event.nonce` can be passed to all of them as is. `scriptNonce` and `styleNonce`, which only existed to do that projection, are no longer exported.
5+
`HydrationScript`, `generateHydrationScript` and `createSSRResponse` now take the same `CSPNonce` as `renderToString`/`renderToStream` (a string or a `{ script, style }` pair) and use its script half, so `event.nonce` can be passed to all of them as is. `scriptNonce` and `styleNonce`, which only existed to do that projection, are now internal: they are no longer documented, and stay exported only for `@solidjs/vite-plugin`'s generated handler until it stops importing them.

‎packages/web/src/server.ts‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,13 +1426,35 @@ function normalizeNonce(nonce) {
14261426
};
14271427
}
14281428

1429-
// The script half of a `CSPNonce`, for the surfaces that emit one script.
1430-
function scriptNonce(nonce) {
1429+
function destinationNonce(nonce, destination) {
14311430
if (nonce == null) return undefined;
1432-
const value = typeof nonce === "string" ? nonce : nonce.script;
1431+
const value = typeof nonce === "string" ? nonce : nonce[destination];
14331432
return typeof value === "string" && value ? value : undefined;
14341433
}
14351434

1435+
/**
1436+
* The script half of a `CSPNonce`. The surfaces that emit one script take a
1437+
* `CSPNonce` and project it themselves; this stays exported only for
1438+
* `@solidjs/vite-plugin`'s generated handler, which still imports it.
1439+
* @internal
1440+
*/
1441+
export function scriptNonce(nonce?: CSPNonce): string | undefined;
1442+
1443+
export function scriptNonce(nonce) {
1444+
return destinationNonce(nonce, "script");
1445+
}
1446+
1447+
/**
1448+
* The style half of a `CSPNonce`. Exported only for
1449+
* `@solidjs/vite-plugin`'s generated handler, which still imports it.
1450+
* @internal
1451+
*/
1452+
export function styleNonce(nonce?: CSPNonce): string | undefined;
1453+
1454+
export function styleNonce(nonce) {
1455+
return destinationNonce(nonce, "style");
1456+
}
1457+
14361458
// Attribute names are ASCII case-insensitive, so a caller-supplied `Nonce`
14371459
// counts as one too.
14381460
function hasNonceProp(props) {

‎packages/web/test/server/single-script-nonce.spec.tsx‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// script half, so an app passes `event.nonce` everywhere without projecting it.
77
import { describe, expect, test } from "vitest";
88
import { generateHydrationScript, HydrationScript, renderToString } from "@solidjs/web";
9-
import * as web from "@solidjs/web";
109

1110
const split = { script: "s-1", style: "t-1" };
1211

@@ -34,9 +33,4 @@ describe("single-script surfaces take a CSPNonce", () => {
3433
const html = renderToString(() => <HydrationScript />, { nonce: split });
3534
expect(html).toContain(`<script nonce="s-1">window._$HY`);
3635
});
37-
38-
test("the projection helpers are not public exports", () => {
39-
expect("scriptNonce" in web).toBe(false);
40-
expect("styleNonce" in web).toBe(false);
41-
});
4236
});

0 commit comments

Comments
 (0)