Skip to content

Commit 143485b

Browse files
committed
fix docs build
1 parent 05307f6 commit 143485b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

website/src/components/Stackblitz/index.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BrowserOnly from '@docusaurus/BrowserOnly';
12
import StackBlitzSDK, { EmbedOptions } from '@stackblitz/sdk';
23
import { useCallback } from 'react';
34
import React from 'react';
@@ -8,19 +9,26 @@ interface Props {
89

910
const cache: Record<string, HTMLDivElement> = {};
1011

11-
const elRoot = document.createElement('div');
12-
elRoot.style.visibility = 'hidden';
13-
elRoot.style.pointerEvents = 'none';
14-
elRoot.style.width = '0px';
15-
elRoot.style.height = '0px';
16-
elRoot.style.position = 'absolute';
12+
let elRoot: HTMLDivElement | null = null;
1713

18-
document.body.appendChild(elRoot);
14+
function getRootElement() {
15+
const elRoot = document.createElement('div');
16+
elRoot.style.visibility = 'hidden';
17+
elRoot.style.pointerEvents = 'none';
18+
elRoot.style.width = '0px';
19+
elRoot.style.height = '0px';
20+
elRoot.style.position = 'absolute';
21+
22+
document.body.appendChild(elRoot);
23+
return elRoot;
24+
}
1925

2026
function getStackblitzEl(projectId: string) {
2127
const existing = cache[projectId];
2228
if (existing) return existing;
2329

30+
elRoot = elRoot || getRootElement();
31+
2432
const elParent = document.createElement('div');
2533
elParent.style.display = 'contents';
2634
elRoot.appendChild(elParent);
@@ -50,7 +58,11 @@ function getStackblitzEl(projectId: string) {
5058
return elParent;
5159
}
5260

53-
export function Stackblitz({ embedId }: Props) {
61+
export function Stackblitz(props: Props) {
62+
return <BrowserOnly>{() => <StackblitzCore {...props} />}</BrowserOnly>;
63+
}
64+
65+
function StackblitzCore({ embedId }: Props) {
5466
const el = getStackblitzEl(embedId);
5567

5668
const ref = useCallback(

0 commit comments

Comments
 (0)