@@ -8,13 +8,13 @@ import { getScriptToRunAsap } from "../useIsDark/scriptToRunAsap";
88import { fontUrlByFileBasename } from "./zz_internal/fontUrlByFileBasename" ;
99import { getDefaultColorSchemeServerSide } from "./zz_internal/defaultColorScheme" ;
1010import { setLink , type RegisteredLinkProps } from "../link" ;
11+ import { assert } from "tsafe/assert" ;
1112//NOTE: As of now there is no way to enforce ordering in Next Appdir
1213//See: https://github.com/vercel/next.js/issues/16630
1314// @import url(...) doesn't work. Using Sass and @use is our last resort.
1415import "../assets/dsfr_plus_icons.scss" ;
1516// eslint-disable-next-line @typescript-eslint/no-unused-vars -- used in doc
1617import { type startReactDsfr } from "./zz_internal/start" ;
17- import { DEFAULT_TRUSTED_TYPES_POLICY_NAME } from "../tools/trustedTypesPolicy/config" ;
1818
1919export type DsfrHeadProps = {
2020 /** If not provided no fonts are preloaded.
@@ -46,12 +46,9 @@ export type DsfrHeadProps = {
4646const isProduction = process . env . NODE_ENV !== "development" ;
4747
4848export function DsfrHead ( props : DsfrHeadProps ) {
49- const {
50- preloadFonts = [ ] ,
51- Link,
52- nonce,
53- trustedTypesPolicyName = DEFAULT_TRUSTED_TYPES_POLICY_NAME
54- } = props ;
49+ const { preloadFonts = [ ] , Link, nonce, trustedTypesPolicyName = "react-dsfr" } = props ;
50+
51+ assert ( nonce !== "" , "nonce cannot be an empty string" ) ;
5552
5653 const defaultColorScheme = getDefaultColorSchemeServerSide ( ) ;
5754
@@ -90,14 +87,16 @@ export function DsfrHead(props: DsfrHeadProps) {
9087 } )
9188 } }
9289 />
93- < script
94- suppressHydrationWarning
95- key = "nonce-setter"
96- nonce = { nonce }
97- dangerouslySetInnerHTML = { {
98- __html : `window.ssrNonce = "${ nonce } ";`
99- } }
100- />
90+ { nonce !== undefined && (
91+ < script
92+ suppressHydrationWarning
93+ key = "nonce-setter"
94+ nonce = { nonce }
95+ dangerouslySetInnerHTML = { {
96+ __html : `window.ssrNonce = "${ nonce } ";`
97+ } }
98+ />
99+ ) }
101100 </ >
102101 ) ;
103102}
0 commit comments