Skip to content

Commit 9773472

Browse files
committed
fix embed preview url setting
1 parent 7509467 commit 9773472

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

website/src/components/Stackblitz/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ function getStackblitzEl(projectId: string, exampleId?: string) {
5050
const embedPromise = embedFn(el, projectId, opts);
5151

5252
embedPromise.then(async (p) => {
53-
try {
54-
await p.preview.getUrl();
55-
if (exampleId) p.preview.setUrl(`/${exampleId || ''}`);
56-
} catch (e) {}
53+
// Set URL fails, probably because the preview is not loaded yet
54+
// so we need to poll until it is loaded
55+
const interval = setInterval(async () => {
56+
try {
57+
await p.preview.setUrl(`/${exampleId || ''}`);
58+
clearInterval(interval);
59+
} catch (e) {}
60+
}, 300);
5761
});
5862

5963
cache[projectId] = elParent;

0 commit comments

Comments
 (0)