Skip to content

Commit 7c26d49

Browse files
authored
Fix passing the correct nonce for iframely script and preload it (#2360)
1 parent 97035a0 commit 7c26d49

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/components/DocumentView/Embed.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as gitbookAPI from '@gitbook/api';
2+
import { headers } from 'next/headers';
23
import Script from 'next/script';
34
import ReactDOM from 'react-dom';
45

@@ -12,8 +13,9 @@ import { IntegrationBlock } from './Integration';
1213

1314
export async function Embed(props: BlockProps<gitbookAPI.DocumentBlockEmbed>) {
1415
const { block, context, ...otherProps } = props;
16+
const nonce = headers().get('x-nonce') || undefined;
1517

16-
ReactDOM.preconnect('https://cdn.iframe.ly');
18+
ReactDOM.preload('https://cdn.iframe.ly/embed.js', { as: 'script', nonce });
1719

1820
const { data: embed } = await (context.content
1921
? api().spaces.getEmbedByUrlInSpace(context.content.spaceId, { url: block.data.url })
@@ -28,8 +30,7 @@ export async function Embed(props: BlockProps<gitbookAPI.DocumentBlockEmbed>) {
2830
__html: embed.html,
2931
}}
3032
/>
31-
{/* We load the iframely script to resize the embed iframes dynamically */}
32-
<Script src="https://cdn.iframe.ly/embed.js" defer async />
33+
<Script src="https://cdn.iframe.ly/embed.js" nonce={nonce} />
3334
</>
3435
) : embed.type === 'integration' ? (
3536
<IntegrationBlock

0 commit comments

Comments
 (0)