0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

Don't try to load partytown scripts in the main thread during view transitions (#9658)

This commit is contained in:
Martin Trapp 2024-01-11 06:12:45 +01:00 committed by GitHub
parent e72efd6a9a
commit a3b5695176
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Fixes an issue caused by trying to load text/partytown scripts during view transitions

View file

@ -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);
}