Skip to content

Commit 5c40f84

Browse files
committed
fix: fix vite dev style nonce
1 parent 72a3224 commit 5c40f84

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/plugin-rsc/examples/basic/src/server.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import './styles.css'
44
export default async function handler(request: Request): Promise<Response> {
55
const url = new URL(request.url)
66
const { Root } = await import('./routes/root.tsx')
7+
const nonce = !process.env.NO_CSP ? crypto.randomUUID() : undefined
8+
// https://vite.dev/guide/features.html#content-security-policy-csp
9+
// this isn't needed if `style-src: 'unsafe-inline'` (dev) and `script-src: 'self'`
10+
const nonceMeta = nonce && <meta property="csp-nonce" nonce={nonce} />
711
const root = (
812
<>
913
{import.meta.viteRsc.loadCss()}
14+
{nonceMeta}
1015
<Root url={url} />
1116
</>
1217
)
13-
const nonce = !process.env.NO_CSP ? crypto.randomUUID() : undefined
1418
const response = await handleRequest({
1519
request,
1620
getRoot: () => root,

0 commit comments

Comments
 (0)