diff --git a/packages/storefront/src/decap-cms/gen-preview-container.ts b/packages/storefront/src/decap-cms/gen-preview-container.ts index 7f200e303..060015d0e 100644 --- a/packages/storefront/src/decap-cms/gen-preview-container.ts +++ b/packages/storefront/src/decap-cms/gen-preview-container.ts @@ -38,11 +38,11 @@ export const genPreviewContainer = ({ React, cmsConfig, ghToken }: { .getElementById(serverIframeId) as HTMLIFrameElement; initWebcontainer({ repo, ghToken, cliTextarea }) .then(({ webcontainerInstance, startDevServer }) => { - startDevServer(); webcontainerInstance.on('server-ready', (port, url) => { console.log({ port, url }); previewIframe.src = `${url}${previewIframe.dataset.url}`; }); + startDevServer(); }); } }; diff --git a/packages/storefront/src/decap-cms/preview/webcontainer.ts b/packages/storefront/src/decap-cms/preview/webcontainer.ts index 74914b3f0..56eb7f4d1 100644 --- a/packages/storefront/src/decap-cms/preview/webcontainer.ts +++ b/packages/storefront/src/decap-cms/preview/webcontainer.ts @@ -71,15 +71,15 @@ export const initWebcontainer = async ({ repo, ghToken, cliTextarea }: { const cliArgs = args.reduce((acc, opt) => `${acc} ${opt}`, ''); const cli = `$ ${command}${cliArgs}\n`; cliTextarea.value += cli; - const cmd = await webcontainerInstance.spawn(command, args); + const proc = await webcontainerInstance.spawn(command, args); if (import.meta.env.DEV || (window as any).DEBUG) { - cmd.output.pipeTo(new WritableStream({ + proc.output.pipeTo(new WritableStream({ write(stdout) { console.debug?.('webcontainer', { stdout }); }, })); } - if (await cmd.exit !== 0) { + if (await proc.exit !== 0) { throw new Error(`${command} failed`); } }; @@ -93,6 +93,8 @@ export const initWebcontainer = async ({ repo, ghToken, cliTextarea }: { ); const startDevServer = async () => { await exec('npm', ['--prefix', ssrDir, 'run', 'dev']); + // Keep restarting dev server (can crash) + startDevServer(); }; return { webcontainerInstance,