From a3b5695176cd0280438938c1d6caef478a571415 Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Thu, 11 Jan 2024 06:12:45 +0100 Subject: [PATCH] Don't try to load partytown scripts in the main thread during view transitions (#9658) --- .changeset/early-taxis-love.md | 5 +++++ packages/astro/src/transitions/router.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/early-taxis-love.md diff --git a/.changeset/early-taxis-love.md b/.changeset/early-taxis-love.md new file mode 100644 index 0000000000..2e092dfe1f --- /dev/null +++ b/.changeset/early-taxis-love.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue caused by trying to load text/partytown scripts during view transitions diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index 41b9acf874..4e4f562a3c 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -151,12 +151,14 @@ function runScripts() { let wait = Promise.resolve(); for (const script of Array.from(document.scripts)) { if (script.dataset.astroExec === '') continue; + const type = script.getAttribute('type'); + if (type && type !== 'module' && type !== 'text/javascript') continue; const newScript = document.createElement('script'); newScript.innerHTML = script.innerHTML; for (const attr of script.attributes) { if (attr.name === 'src') { const p = new Promise((r) => { - newScript.onload = r; + newScript.onload = newScript.onerror = r; }); wait = wait.then(() => p as any); }