@@ -721,7 +721,12 @@ export function startServe(
721721 // every positional claim after it.
722722 lines . push (
723723 `` ,
724- `function createHtmlChunkTransform(clientEntry, extraHead) {` ,
724+ `function escapeAttribute(value) {` ,
725+ ` return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');` ,
726+ `}` ,
727+ `` ,
728+ `function createHtmlChunkTransform(clientEntry, extraHead, nonce) {` ,
729+ ` const nonceAttr = nonce ? ' nonce="' + escapeAttribute(nonce) + '"' : '';` ,
725730 ` let first = true;` ,
726731 ` let injected = false;` ,
727732 ` return (chunk) => {` ,
@@ -767,7 +772,7 @@ export function startServe(
767772 // fresh render-into-body mount (hydration, by contrast, wants to
768773 // start as early as possible).
769774 headParts . push (
770- `(clientEntry ? '<script type="module" src="' + clientEntry + '"${ clientMode ? '' : ' async' } ></' + 'script>' : '')` ,
775+ `(clientEntry ? '<script type="module"' + nonceAttr + ' src="' + clientEntry + '"${ clientMode ? '' : ' async' } ></' + 'script>' : '')` ,
771776 ) ;
772777 }
773778 if ( headParts . length ) {
@@ -851,7 +856,7 @@ export function startServe(
851856 ` return createSSRResponse(result, event, {` ,
852857 ` responseInit: options.responseInit,` ,
853858 ` nonce: options.nonce,` ,
854- ` transformChunk: createHtmlChunkTransform(clientEntry, options.devHead),` ,
859+ ` transformChunk: createHtmlChunkTransform(clientEntry, options.devHead, options.nonce ),` ,
855860 ` });` ,
856861 `}` ,
857862 `` ,
0 commit comments