WIP 5944 Fix race condition: Add event listeners to DOM elements before mounting them #5968
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a WIP on #5944 - Trying to fix a race condition where a svelte:head tag containing a script with a src attribute doesn't have it's onload handler attached before after the element is added to the DOM, resulting in a race condition, where if the browser finishes getting the script before the onload listener is attached, the onload event handler will not run, see the Issue for more information about the bug.
So far, it fixes the bug in question by rewriting code generation for the "mount" function of Fragments so that attaching event listeners comes before appending the elements to the DOM.
Help needed! Currently, this breaks the test "deconflict-contextual-action".
As far as I can tell, the test seems to rely on the current order...? I don't know why. Maybe switching this order would break something else. Maybe there are cases where the elements have to be added to the DOM before the event listeners are attached (maybe in order to prevent an event handler to fire at an incorrect time?)... I am lost.
So, bottom line: I don't know why the mount code is being generated in this order. Does it matter, for reasons that I cannot see?