Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(playground/runner): fix external script loading in playground #11017

Merged
13 changes: 10 additions & 3 deletions client/public/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
}

let initialized = false;
function init(state) {
async function init(state) {
if (initialized) {
return;
}
Expand All @@ -117,6 +117,13 @@
document.body.innerHTML = "";
setHTML(document.body, state.html);

for (const script of document.querySelectorAll("script[src]")) {
await new Promise((resolve) => {
script.addEventListener("load", () => resolve());
script.addEventListener("error", () => resolve());
});
}

const script = document.createElement("script");
script.textContent = state.js;
document.body.appendChild(script);
Expand All @@ -129,10 +136,10 @@

initialized = true;
}
window.addEventListener("message", (event) => {
window.addEventListener("message", async (event) => {
const e = event.data;
if (e.typ === "init") {
init(e.state);
await init(e.state);
}
if (e.typ === "reload") {
window.location.reload();
Expand Down