From 974d5117abc8b47f8225e455b9285c88e305272f Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Fri, 22 Sep 2023 18:01:22 +0200 Subject: [PATCH] fix: no deletion of scripts during view transition (#8636) --- .changeset/short-cougars-worry.md | 5 +++++ packages/astro/components/ViewTransitions.astro | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/short-cougars-worry.md 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; } } }