From c15e0a21802336159649d1ef92e751fad2f6db65 Mon Sep 17 00:00:00 2001 From: okxint Date: Fri, 31 Jul 2026 12:17:40 +0530 Subject: [PATCH] fix(transitions): snapshot script collection before iterating in runScripts getElementsByTagName returns a live HTMLCollection. When new scripts are appended to the DOM inside the loop body (e.g. the sentinel data:application/javascript module), the collection grows mid-iteration and some scripts get skipped. Convert to a static Array snapshot with Array.from() before each loop so every script is visited exactly once. --- packages/astro/src/transitions/router.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index dfa77325908d..aa1f04aa2701 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -131,7 +131,7 @@ function runScripts() { // inline module scripts cannot be awaited for with onload. // Thus to be able to wait for the execution of all scripts, we make sure that the last inline module script // is always followed by an external module script - for (const script of document.getElementsByTagName('script')) { + for (const script of Array.from(document.getElementsByTagName('script'))) { script.dataset.astroExec === undefined && script.getAttribute('type') === 'module' && (needsWaitForInlineModuleScript = script.getAttribute('src') === null); @@ -142,7 +142,7 @@ function runScripts() { `