Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion sandpack-client/src/clients/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,18 @@ export class SandpackRuntime extends SandpackClient {
}
};

this.iframe.onload = () => {
const sendMessage = () => {
const initMsg = {
$channel: CHANNEL_NAME,
$type: "preview/init",
};

iframeContentWindow.postMessage(initMsg, "*", [channel.port2]);

this.iframe.removeEventListener("load", sendMessage);
};

this.iframe.addEventListener("load", sendMessage);
}

private handleWorkerRequest(
Expand Down Expand Up @@ -362,6 +366,10 @@ export class SandpackRuntime extends SandpackClient {
*/
if (message.type === "refresh") {
this.setLocationURLIntoIFrame();

if (this.options.experimental_enableServiceWorker) {
this.serviceWorkerHandshake();
}
}

this.iframeProtocol.dispatch(message);
Expand Down
1 change: 1 addition & 0 deletions sandpack-react/src/presets/CustomSandpack.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const ExperimentalServiceWorker: React.FC = () => {
`,
}}
options={{
bundlerURL: "https://nqfrns-3000.csb.app/",
experimental_enableServiceWorker: true,
}}
template="react"
Expand Down