1
1
// XXX: Blocked by https://github.com/vercel/next.js/pull/58129
2
2
// import { headers } from 'next/headers';
3
- import Script , { ScriptProps } from 'next/script' ;
3
+ import Script , { type ScriptProps } from 'next/script' ;
4
4
import { type FC } from 'react' ;
5
5
6
6
import { type NonceConfig } from '../typings/nonce' ;
@@ -10,8 +10,8 @@ import { PUBLIC_ENV_KEY } from './constants';
10
10
type EnvScriptProps = {
11
11
env : ProcessEnv ;
12
12
nonce ?: string | NonceConfig ;
13
- withNextScriptComponent ?: boolean ;
14
- nextScriptComponentProps ?: ScriptProps ;
13
+ disableNextScript ?: boolean ;
14
+ nextScriptProps ?: ScriptProps ;
15
15
} ;
16
16
17
17
/**
@@ -28,8 +28,8 @@ type EnvScriptProps = {
28
28
export const EnvScript : FC < EnvScriptProps > = ( {
29
29
env,
30
30
nonce,
31
- withNextScriptComponent = true ,
32
- nextScriptComponentProps = { strategy : 'beforeInteractive' } ,
31
+ disableNextScript = false ,
32
+ nextScriptProps = { strategy : 'beforeInteractive' } ,
33
33
} ) => {
34
34
let nonceString : string | undefined ;
35
35
@@ -43,23 +43,23 @@ export const EnvScript: FC<EnvScriptProps> = ({
43
43
nonceString = nonce ;
44
44
}
45
45
46
- const html = {
46
+ const innerHTML = {
47
47
__html : `window['${ PUBLIC_ENV_KEY } '] = ${ JSON . stringify ( env ) } ` ,
48
48
} ;
49
49
50
50
// You can opt to use a regular "<script>" tag instead of Next.js' Script Component.
51
51
// Note: When using Sentry, sentry.client.config.ts might run after the Next.js <Script> component, even when the strategy is "beforeInteractive"
52
52
// This results in the runtime environments being undefined and the Sentry client config initialized without the correct configuration.
53
- if ( ! withNextScriptComponent ) {
54
- return < script nonce = { nonceString } dangerouslySetInnerHTML = { html } /> ;
53
+ if ( disableNextScript ) {
54
+ return < script nonce = { nonceString } dangerouslySetInnerHTML = { innerHTML } /> ;
55
55
}
56
56
57
57
// Use Next.js Script Component by default
58
58
return (
59
59
< Script
60
- { ...nextScriptComponentProps }
60
+ { ...nextScriptProps }
61
61
nonce = { nonceString }
62
- dangerouslySetInnerHTML = { html }
62
+ dangerouslySetInnerHTML = { innerHTML }
63
63
/>
64
64
) ;
65
65
} ;
0 commit comments