Skip to content

Commit

Permalink
Adds nonce to preinit scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhargava committed Aug 15, 2023
1 parent ec6d2c7 commit a4d96a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,8 @@ export async function renderToHTMLOrFlight(
buildManifest,
assetPrefix,
subresourceIntegrityManifest,
getAssetQueryString(true)
getAssetQueryString(true),
nonce
)
const ServerComponentsRenderer = createServerComponentsRenderer(
tree,
Expand Down Expand Up @@ -1632,7 +1633,8 @@ export async function renderToHTMLOrFlight(
buildManifest,
assetPrefix,
subresourceIntegrityManifest,
getAssetQueryString(false)
getAssetQueryString(false),
nonce
)

const ErrorPage = createServerComponentRenderer(
Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/server/app-render/required-scripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export function getRequiredScripts(
buildManifest: BuildManifest,
assetPrefix: string,
SRIManifest: undefined | Record<string, string>,
qs: string
qs: string,
nonce: string | undefined
): [() => void, string | { src: string; integrity: string }] {
let preinitScripts: () => void
let preinitScriptCommands: string[] = []
Expand All @@ -33,6 +34,7 @@ export function getRequiredScripts(
ReactDOM.preinit(preinitScriptCommands[i], {
as: 'script',
integrity: preinitScriptCommands[i + 1],
nonce,
})
}
}
Expand All @@ -47,6 +49,7 @@ export function getRequiredScripts(
for (let i = 0; i < preinitScriptCommands.length; i++) {
ReactDOM.preinit(preinitScriptCommands[i], {
as: 'script',
nonce,
})
}
}
Expand Down

0 comments on commit a4d96a1

Please sign in to comment.