diff --git a/source b/source index f42733c9bb6..015ab1b24d8 100644 --- a/source +++ b/source @@ -64358,17 +64358,20 @@ o............A....e insertedNode, are:

    -
  1. -

    If insertedNode is not connected, then return.

    +
  2. If insertedNode is parser-inserted, then return.

  3. -
    -

    This can happen in the case where an earlier-inserted script removes a - later-inserted script. For instance:

    +
  4. Prepare the script element given insertedNode.

  5. +
-
<script>
+  
+

The HTML element post-connection steps only run when the inserted element is + still connected, which protects against cases where an earlier-inserted + script removes a later-inserted script. For instance:

+ +
<script>
 const script1 = document.createElement('script');
 script1.innerText = `
-  document.querySelector('#script2').remove();
+document.querySelector('#script2').remove();
 `;
 
 const script2 = document.createElement('script');
@@ -64378,24 +64381,20 @@ script2.textContent = `console.log('script#2 running')`;
 document.body.append(script1, script2);
 </script>
-

Nothing is printed to the console in this example. By the time the HTML element - post-connection steps run for the first script that was atomically inserted - by append(), it can observe that the second - script is already connected to the DOM. It removes the second - script, so that by the time its HTML element post-connection - steps run, it is no longer connected, and does not get prepared.

-
- - -
  • If insertedNode is parser-inserted, then return.

  • - -
  • Prepare the script element given insertedNode.

  • - +

    Nothing is printed to the console in this example. By the time the HTML element + post-connection steps run for the first script that was atomically inserted + by append(), it can observe that the second + script is already connected to the DOM, and it removes it from the DOM. + Because the second script is no longer connected, its HTML + element post-connection steps do not run, and it does not get prepared.

    +

    The script children changed steps are:

      +
    1. If the script element is not connected, then return.

    2. +
    3. Run the script HTML element post-connection steps, given the script element.

    @@ -64449,9 +64448,9 @@ document.body.append(script1, script2);
    1. If namespace is not null, then return.

    2. -
    3. If localName is src, then run the - script HTML element post-connection steps, given - element.

    4. +
    5. If localName is src and + element is connected, then run the script HTML element + post-connection steps, given element.

    To prepare the script element given a script