File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ export function Asset({
1212 tag,
1313 attrs,
1414 children,
15- } : RouterManagedTag ) : React . ReactElement | null {
15+ nonce,
16+ } : RouterManagedTag & { nonce ?: string } ) : React . ReactElement | null {
1617 switch ( tag ) {
1718 case 'title' :
1819 return (
@@ -23,16 +24,21 @@ export function Asset({
2324 case 'meta' :
2425 return < meta { ...attrs } suppressHydrationWarning />
2526 case 'link' :
26- return < link { ...attrs } suppressHydrationWarning />
27+ return < link { ...attrs } nonce = { nonce } suppressHydrationWarning />
2728 case 'style' :
2829 return (
2930 < style
3031 { ...attrs }
3132 dangerouslySetInnerHTML = { { __html : children as string } }
33+ nonce = { nonce }
3234 />
3335 )
3436 case 'script' :
35- return < Script attrs = { attrs } > { children } </ Script >
37+ return (
38+ < Script attrs = { attrs } nonce = { nonce } >
39+ { children }
40+ </ Script >
41+ )
3642 default :
3743 return null
3844 }
@@ -41,9 +47,11 @@ export function Asset({
4147function Script ( {
4248 attrs,
4349 children,
50+ nonce,
4451} : {
4552 attrs ?: ScriptAttrs
4653 children ?: string
54+ nonce ?: string
4755} ) {
4856 const router = useRouter ( )
4957
@@ -146,7 +154,7 @@ function Script({
146154 }
147155
148156 if ( attrs ?. src && typeof attrs . src === 'string' ) {
149- return < script { ...attrs } suppressHydrationWarning />
157+ return < script { ...attrs } suppressHydrationWarning nonce = { nonce } />
150158 }
151159
152160 if ( typeof children === 'string' ) {
@@ -155,6 +163,7 @@ function Script({
155163 { ...attrs }
156164 dangerouslySetInnerHTML = { { __html : children } }
157165 suppressHydrationWarning
166+ nonce = { nonce }
158167 />
159168 )
160169 }
Original file line number Diff line number Diff line change @@ -174,8 +174,10 @@ export const useTags = () => {
174174 */
175175export function HeadContent ( ) {
176176 const tags = useTags ( )
177+ const router = useRouter ( )
178+ const nonce = router . options . ssr ?. nonce
177179 return tags . map ( ( tag ) => (
178- < Asset { ...tag } key = { `tsr-meta-${ JSON . stringify ( tag ) } ` } />
180+ < Asset { ...tag } key = { `tsr-meta-${ JSON . stringify ( tag ) } ` } nonce = { nonce } />
179181 ) )
180182}
181183
Original file line number Diff line number Diff line change @@ -58,7 +58,11 @@ export const Scripts = () => {
5858 return (
5959 < >
6060 { allScripts . map ( ( asset , i ) => (
61- < Asset { ...asset } key = { `tsr-scripts-${ asset . tag } -${ i } ` } />
61+ < Asset
62+ { ...asset }
63+ key = { `tsr-scripts-${ asset . tag } -${ i } ` }
64+ nonce = { router . options . ssr ?. nonce }
65+ />
6266 ) ) }
6367 </ >
6468 )
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export const renderRouterToStream = async ({
2323 if ( typeof ReactDOMServer . renderToReadableStream === 'function' ) {
2424 const stream = await ReactDOMServer . renderToReadableStream ( children , {
2525 signal : request . signal ,
26+ nonce : router . options . ssr ?. nonce ,
2627 } )
2728
2829 if ( isbot ( request . headers . get ( 'User-Agent' ) ) ) {
@@ -44,6 +45,7 @@ export const renderRouterToStream = async ({
4445
4546 try {
4647 const pipeable = ReactDOMServer . renderToPipeableStream ( children , {
48+ nonce : router . options . ssr ?. nonce ,
4749 ...( isbot ( request . headers . get ( 'User-Agent' ) )
4850 ? {
4951 onAllReady ( ) {
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ export const renderRouterToStream = async ({
1818} ) => {
1919 const { writable, readable } = new TransformStream ( )
2020
21- const stream = Solid . renderToStream ( children )
21+ const stream = Solid . renderToStream ( children , {
22+ nonce : router . options . ssr ?. nonce ,
23+ } )
2224
2325 if ( isbot ( request . headers . get ( 'User-Agent' ) ) ) {
2426 await stream
Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ export const renderRouterToString = async ({
1212 children : ( ) => JSXElement
1313} ) => {
1414 try {
15- let html = Solid . renderToString ( children )
15+ let html = Solid . renderToString ( children , {
16+ nonce : router . options . ssr ?. nonce ,
17+ } )
1618 router . serverSsr ! . setRenderFinished ( )
1719 const injectedHtml = await Promise . all ( router . serverSsr ! . injectedHtml ) . then (
1820 ( htmls ) => htmls . join ( '' ) ,
You can’t perform that action at this time.
0 commit comments