Skip to content

Commit

Permalink
Don't try to load partytown scripts in the main thread during view tr…
Browse files Browse the repository at this point in the history
…ansitions (#9658)
  • Loading branch information
martrapp committed Jan 11, 2024
1 parent e72efd6 commit a3b5695
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/early-taxis-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes an issue caused by trying to load text/partytown scripts during view transitions
4 changes: 3 additions & 1 deletion packages/astro/src/transitions/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a3b5695

Please sign in to comment.