diff --git a/.changeset/short-cougars-worry.md b/.changeset/short-cougars-worry.md new file mode 100644 index 000000000000..05c1c20b57f5 --- /dev/null +++ b/.changeset/short-cougars-worry.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +fix: no deletion of scripts during view transition diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index aa266af1347f..230b2f3024aa 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -219,13 +219,13 @@ const { fallback = 'animate' } = Astro.props as Props; for (const s2 of newDocument.scripts) { if ( // Inline - (s1.textContent && s1.textContent === s2.textContent) || + (!s1.src && s1.textContent === s2.textContent) || // External - (s1.type === s2.type && s1.src === s2.src) + (s1.src && s1.type === s2.type && s1.src === s2.src) ) { - s2.remove(); - } else { - s1.remove(); + // the old script is in the new document: we mark it as executed to prevent re-execution + s2.dataset.astroExec = ''; + break; } } }