File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 66 normalizeModuleRunnerTransport ,
77} from '../shared/moduleRunnerTransport'
88import { createHMRHandler } from '../shared/hmrHandler'
9- import { ErrorOverlay , overlayId } from './overlay'
9+ import { ErrorOverlay , cspNonce , overlayId } from './overlay'
1010import '@vite/env'
1111
1212// injected by the hmr plugin when served
@@ -506,11 +506,6 @@ if ('document' in globalThis) {
506506 } )
507507}
508508
509- const cspNonce =
510- 'document' in globalThis
511- ? document . querySelector < HTMLMetaElement > ( 'meta[property=csp-nonce]' ) ?. nonce
512- : undefined
513-
514509// all css imports should be inserted at the same position
515510// because after build it will be a single css file
516511let lastInsertedStyle : HTMLStyleElement | undefined
Original file line number Diff line number Diff line change @@ -7,15 +7,22 @@ declare const __HMR_CONFIG_NAME__: string
77const hmrConfigName = __HMR_CONFIG_NAME__
88const base = __BASE__ || '/'
99
10+ export const cspNonce =
11+ 'document' in globalThis
12+ ? document . querySelector < HTMLMetaElement > ( 'meta[property=csp-nonce]' ) ?. nonce
13+ : undefined
14+
1015// Create an element with provided attributes and optional children
1116function h (
1217 e : string ,
13- attrs : Record < string , string > = { } ,
18+ attrs : Record < string , string | undefined > = { } ,
1419 ...children : ( string | Node ) [ ]
1520) {
1621 const elem = document . createElement ( e )
1722 for ( const [ k , v ] of Object . entries ( attrs ) ) {
18- elem . setAttribute ( k , v )
23+ if ( v !== undefined ) {
24+ elem . setAttribute ( k , v )
25+ }
1926 }
2027 elem . append ( ...children )
2128 return elem
@@ -197,7 +204,7 @@ const createTemplate = () =>
197204 '.' ,
198205 ) ,
199206 ) ,
200- h ( 'style' , { } , templateStyle ) ,
207+ h ( 'style' , { nonce : cspNonce } , templateStyle ) ,
201208 )
202209
203210const fileRE = / (?: f i l e : \/ \/ ) ? (?: [ a - z A - Z ] : \\ | \/ ) .* ?: \d + : \d + / g
You can’t perform that action at this time.
0 commit comments