fix(transitions): snapshot script collection before iterating in runScripts - #17563
fix(transitions): snapshot script collection before iterating in runScripts#17563okxint wants to merge 1 commit into
Conversation
…cripts 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.
|
sirrryasir
left a comment
There was a problem hiding this comment.
Converting document.getElementsByTagName('script') to static arrays via Array.from() across runScripts() and the initialization pass is correct.
getElementsByTagName returns a live HTMLCollection. When runScripts() appends the sentinel module script (data:application/javascript,) at line 142, the live collection updates mid-loop, causing index displacement and skipping subsequent script tags. Static array snapshots ensure every element present at invocation is visited exactly once.
LGTM.
getElementsByTagNamereturns a liveHTMLCollection. When new scripts areappended to the DOM inside the loop body — specifically the sentinel
data:application/javascriptmodule injected at line 142 — the collectiongrows mid-iteration and subsequently added scripts are skipped (the iterator
index advances past them before they are visited).
Convert to a static snapshot with
Array.from()before each loop so everyscript is visited exactly once.
Affected loops (
runScripts()is called on every page transition):