From 8534fcf6b6c4fa1a82b42f78fe888ef931b58844 Mon Sep 17 00:00:00 2001
From: Dominic Farolino
An HTML element can have specific HTML element insertion steps defined for the - element's local name. Similarly, an HTML element - can have specific HTML element removing steps defined for the element's local name.
+An HTML element can have specific HTML element insertion steps, HTML element + post-insertion steps, and HTML element removing steps, all defined for the + element's local name.
+ +An HTML element can have specific defined for the + element's local name.
+The insertion steps for the HTML Standard, given insertedNode, are defined as the following:
@@ -1796,6 +1799,18 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute node document. +The post-insertion steps for the HTML + Standard, given insertedNode, are defined as the following:
+ +If insertedNode is an element whose namespace is the HTML namespace, and this + standard defines HTML element post-insertion + steps for insertedNode's local + name, then run the corresponding HTML element post-insertion steps given + insertedNode.
The removing steps for the HTML Standard, given removedNode and oldParent, are defined as the following:
@@ -3192,6 +3207,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attributecreateElementNS()
methodgetElementById()
methodgetElementsByClassName()
methodappend()
methodappendChild()
methodcloneNode()
methodimportNode()
methodWhen a script
element el that is not parser-inserted
- experiences one of the events listed in the following list, the user agent must
- immediately prepare the script element el:
The script
HTML element post-insertion steps, given
+ insertedNode, are:
script
element becomes connected.If insertedNode is not connected, then return.
+ +This can happen in the case where an earlier-inserted script removes a later-inserted + script. For example:
-script
element is connected and a node or document fragment is
- inserted into the script
element,
- after any script
elements inserted
- at that time.<script>
+const script1 = document.createElement('script');
+script1.innerText = `
+ document.querySelector('#script2').remove();
+`;
- - The
script
element is connected and has a src
attribute set where previously the element had no such
- attribute.
-
+const script2 = document.createElement('script');
+script2.id = 'script2';
+script2.innerText = `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-insertion 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-insertion steps run, it is no longer connected, and
+ does not get prepared.
If insertedNode is marked as being parser-inserted, then + return.
Prepare the script element given insertedNode.
The script
children changed steps are:
Run the script
HTML element post-insertion steps, given the
+ script
element.
This has an interesting implication on the execution order of a script
element
+ and any newly-inserted child script
elements. Consider the following example:
<script id=outer-script></script>
+
+<script>
+ const outerScript = document.querySelector('#outer-script');
+
+ const start = new Text("console.log(1);");
+ const innerScript = document.createElement('script');
+ innerScript.innerText = `console.log('inner script executing')`;
+ const end = new Text("console.log(2);");
+
+ outerScript.append(start, innerScript, end);
+</script>
+
+ By the time the second script block executes, the outer-script
has
+ already been prepared, but beacuse it is empty,
+ it did not execute and therefore is not marked as already started. The atomic
+ insertion of the Text
nodes and nested script
element have the
+ following effects:
All three child nodes get atomically inserted as children of outer-script
; all of their HTML element insertion steps run,
+ which have no observable consequences in this case.
The outer-script
's children changed steps run, which
+ prepares that script; because its body is now
+ non-empty, this executes the contents of the two Text
nodes, in order.
The script
HTML element post-insertion steps finally run for
+ innerScript
, causing its body to execute.
The src
attribute setter sets are:
If the previous value of the script
's src
content attribute was not empty, then
+ return.
Run the script
HTML element post-insertion steps, given the
+ script
element.
To prepare the script element given a script
element el:
An HTML element can have specific defined for the - element's local name.
- -The insertion steps for the HTML Standard, given insertedNode, are defined as the following:
From 050d07a7a1d87136f48e2ccdf1e2383da5b9ce62 Mon Sep 17 00:00:00 2001 From: Dominic FarolinoBy the time the second script block executes, the All three child nodes get atomically inserted as children of outer-script
has
From d628ddbcb66a101ea71b840ff67799577e190712 Mon Sep 17 00:00:00 2001
From: Dominic Farolino
outer-script
; all of their HTML element insertion steps run,
- which have no observable consequences in this case.
The outer-script
's children changed steps run, which
prepares that script; because its body is now
@@ -62343,7 +62343,7 @@ document.body.append(script1, script2);
-
The src
attribute setter sets are:
The src
attribute setter steps are:
If the previous value of the script
's
Date: Mon, 6 May 2024 22:08:18 -0400
Subject: [PATCH 07/14] More implicit content attribute reaction
---
source | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/source b/source
index c858b70391e..ccea72f1c09 100644
--- a/source
+++ b/source
@@ -62343,7 +62343,8 @@ document.body.append(script1, script2);
The src
attribute setter steps are:
When the src
attribute is set, user agents must run these
+ steps:
If the previous value of the If insertedNode is not connected, then return. This can happen in the case where an earlier-inserted script removes a later-inserted
- script. For example: This can happen in the case where an earlier-inserted Nothing is printed to the console in this example. By the time the HTML element
- post-insertion steps run for the first script that was atomically inserted by script
's
Date: Wed, 8 May 2024 11:30:59 -0400
Subject: [PATCH 08/14] Address annevk@ review
---
source | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/source b/source
index ccea72f1c09..cfe26af0ef9 100644
--- a/source
+++ b/source
@@ -62263,8 +62263,8 @@ o............A....e
script
removes a
+ later-inserted script
. For instance:<script>
const script1 = document.createElement('script');
@@ -62280,11 +62280,12 @@ document.body.append(script1, script2);
</script>
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-insertion steps run, it is no longer connected, and
- does not get prepared.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-insertion
+ steps run, it is no longer connected, and does not get prepared.
This has an interesting implication on the execution order of a script
element
- and any newly-inserted child script
elements. Consider the following example:
script
elements. Consider the following snippet:
<script id=outer-script></script>
From 4f1c9ef1ce9073ccf3677ccf601ba179d75cc73b Mon Sep 17 00:00:00 2001
From: Dominic Farolino
Date: Mon, 13 May 2024 10:39:00 -0400
Subject: [PATCH 09/14] `` -> ``
---
source | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source b/source
index cfe26af0ef9..37a81c29931 100644
--- a/source
+++ b/source
@@ -62283,7 +62283,7 @@ document.body.append(script1, script2);
post-insertion 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-insertion
+ script
, so that by the time its HTML element post-insertion
steps run, it is no longer connected, and does not get prepared.
An HTML element can have specific HTML element insertion steps, HTML element - post-insertion steps, and HTML element removing steps, all defined for the + post-connection steps, and HTML element removing steps, all defined for the element's local name.
The insertion steps for the HTML Standard, given @@ -1795,15 +1795,15 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute node document.
The post-insertion steps for the HTML +
The post-connection steps for the HTML Standard, given insertedNode, are defined as the following:
If insertedNode is an element whose namespace is the HTML namespace, and this - standard defines HTML element post-insertion + standard defines HTML element post-connection steps for insertedNode's local - name, then run the corresponding HTML element post-insertion steps given + name, then run the corresponding HTML element post-connection steps given insertedNode.
The script
HTML element post-insertion steps, given
+
The script
HTML element post-connection steps, given
insertedNode, are:
Nothing is printed to the console in this example. By the time the HTML element
- post-insertion steps run for the first script
that was atomically inserted
+ 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-insertion
+ script
, so that by the time its HTML element post-connection
steps run, it is no longer connected, and does not get prepared.
The script
children changed steps are:
Run the script
HTML element post-insertion steps, given the
+
Run the script
HTML element post-connection steps, given the
script
element.
Text
nodes, in order.
- The script
HTML element post-insertion steps finally run for
+
The script
HTML element post-connection steps finally run for
innerScript
, causing its body to execute.
Run the script
HTML element post-insertion steps, given the
+
Run the script
HTML element post-connection steps, given the
script
element.
If insertedNode is marked as being parser-inserted, then - return.
If insertedNode is parser-inserted, then return.
Prepare the script element given insertedNode.
By the time the second script block executes, the outer-script
has
- already been prepared, but beacuse it is empty,
+ already been prepared, but because it is empty,
it did not execute and therefore is not marked as already started. The atomic
insertion of the Text
nodes and nested script
element have the
following effects:
When the src
attribute is set, user agents must run these
- steps:
The following attribute change
+ steps, given element, localName, oldValue,
+ value, and namespace, are used for all script
elements:
If the previous value of the script
's src
content attribute was not empty, then
- return.
If namespace is not null, then return.
Run the script
HTML element post-connection steps, given the
+
If localName is src
, then run the
+ script
HTML element post-connection steps, given the
script
element.
If namespace is not null, then return.
If localName is src
, then run the
- script
HTML element post-connection steps, given the
- script
element.
script
HTML element post-connection steps, given
+ element.
To prepare the script element given a script