Skip to content

Commit

Permalink
fix(playground/runner): fix external script loading in playground (#1…
Browse files Browse the repository at this point in the history
…1017)

* fix(playground/runner): fix external script loading in playground

* refactor mapping

Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>

* add comment to make clear

Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>

* fix code formatting

* update upproach for handling scripts

* code refactoring

Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>

---------

Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>
Co-authored-by: Florian Dieminger <me@fiji-flo.de>
  • Loading branch information
3 people authored May 8, 2024
1 parent 8ee8605 commit 8ba95b2
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit 8ba95b2

Please sign in to comment.