Skip to content

Commit 11f1272

Browse files
noxannevk
authored andcommitted
Use the new definition of the insertion steps
whatwg/dom#732 We defer preparing scripts and updating style blocks during insertion to make sure all DOM mutations are finished before executing scripts. This is what Chrome and Firefox seem to already do anyway.
1 parent 928f862 commit 11f1272

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

source

+48-30
Original file line numberDiff line numberDiff line change
@@ -2071,24 +2071,24 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
20712071

20722072
<p>A <dfn data-x="nodes are inserted">node <var>A</var> is inserted</dfn> into a node <var>B</var>
20732073
when the <span data-x="concept-node-insert-ext">insertion steps</span> are invoked with
2074-
<var>A</var> as the argument and <var>A</var>'s new parent is <var>B</var>. Similarly, a <dfn
2075-
data-x="nodes are removed">node <var>A</var> is removed</dfn> from a node <var>B</var> when the
2076-
<span data-x="concept-node-remove-ext">removing steps</span> are invoked with <var>A</var> as the
2077-
<var>removedNode</var> argument and <var>B</var> as the <var>oldParent</var> argument.</p>
2074+
<var>A</var> as the first argument and <var>A</var>'s new parent is <var>B</var>. Similarly, a
2075+
<dfn data-x="nodes are removed">node <var>A</var> is removed</dfn> from a node <var>B</var> when
2076+
the <span data-x="concept-node-remove-ext">removing steps</span> are invoked with <var>A</var> as
2077+
the <var>removedNode</var> argument and <var>B</var> as the <var>oldParent</var> argument.</p>
20782078

20792079
<p>A <dfn id="insert-an-element-into-a-document" data-x="node is inserted into a document"
20802080
data-lt="inserted into a document|node is inserted into a document" data-export="">node is
20812081
inserted into a document</dfn> when the <span data-x="concept-node-insert-ext">insertion
2082-
steps</span> are invoked with it as the argument and it is now <span>in a document tree</span>.
2083-
Analogously, a <dfn id="remove-an-element-from-a-document" data-x="node is removed from a
2084-
document" data-lt="removed from a document|node is removed from a document" data-export="">node is
2085-
removed from a document</dfn> when the <span data-x="concept-node-remove-ext">removing
2086-
steps</span> are invoked with it as the argument and it is now no longer <span>in a document
2087-
tree</span>.</p>
2082+
steps</span> are invoked with it as the first argument and it is now <span>in a document
2083+
tree</span>. Analogously, a <dfn id="remove-an-element-from-a-document" data-x="node is removed
2084+
from a document" data-lt="removed from a document|node is removed from a document"
2085+
data-export="">node is removed from a document</dfn> when the <span
2086+
data-x="concept-node-remove-ext">removing steps</span> are invoked with it as the argument and it
2087+
is now no longer <span>in a document tree</span>.</p>
20882088

20892089
<p>A node <dfn data-export="">becomes connected</dfn> when the <span
2090-
data-x="concept-node-insert-ext">insertion steps</span> are invoked with it as the argument and it
2091-
is now <span>connected</span>. Analogously, a node <dfn data-lt="become disconnected"
2090+
data-x="concept-node-insert-ext">insertion steps</span> are invoked with it as the first argument
2091+
and it is now <span>connected</span>. Analogously, a node <dfn data-lt="become disconnected"
20922092
data-export="">becomes disconnected</dfn> when the <span data-x="concept-node-remove-ext">removing
20932093
steps</span> are invoked with it as the argument and it is now no longer
20942094
<span>connected</span>.</p>
@@ -2098,7 +2098,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
20982098
<span data-x="concept-document-bc">browsing context</span> is non-null. A node <dfn
20992099
data-lt="become browsing-context connected" data-export="">becomes browsing-context
21002100
connected</dfn> when the <span data-x="concept-node-insert-ext">insertion steps</span> are invoked
2101-
with it as the argument and it is now <span>browsing-context connected</span>. A node <dfn
2101+
with it as the first argument and it is now <span>browsing-context connected</span>. A node <dfn
21022102
data-lt="become browsing-context disconnected" data-export="">becomes browsing-context
21032103
disconnected</dfn> either when the <span data-x="concept-node-remove-ext">removing steps</span>
21042104
are invoked with it as the argument and it is now no longer <span>browsing-context
@@ -15193,8 +15193,21 @@ interface <dfn>HTMLStyleElement</dfn> : <span>HTMLElement</span> {
1519315193

1519415194
<div w-nodev>
1519515195

15196-
<p>The user agent must run the <span>update a <code>style</code> block</span> algorithm whenever
15197-
one of the following conditions occur:</p>
15196+
<p>To run the <span data-x="concept-node-insert-ext">insertion steps</span> for a
15197+
<code>style</code> element with <var>style</var> and <var>deferredStepsQueue</var>, the user
15198+
agent must act as follows:</p>
15199+
15200+
<ol>
15201+
<li><p>If <var>style</var> is on the <span>stack of open elements</span>, then return.<p></li>
15202+
15203+
<li><p>If <var>style</var> is not <span>connected</span>, then return.</p></li>
15204+
15205+
<li><p><span>Enqueue</span> the steps to <span data-x="update a style block">update</span>
15206+
<var>style</var> to <var>deferredStepsQueue</var>.</p></li>
15207+
</ol>
15208+
15209+
<p>Additionally, the user agent must run the <span>update a <code>style</code> block</span>
15210+
algorithm whenever one of the following conditions occur:</p>
1519815211
<!-- note that a browsing context isn't needed:
1519915212
https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2739 -->
1520015213

@@ -15203,8 +15216,7 @@ interface <dfn>HTMLStyleElement</dfn> : <span>HTMLElement</span> {
1520315216
parser</span> or <span>XML parser</span>.</p></li>
1520415217

1520515218
<li><p>The element is not on the <span>stack of open elements</span> of an <span>HTML
15206-
parser</span> or <span>XML parser</span>, and it <span>becomes connected</span> or <span
15207-
data-x="becomes disconnected">disconnected</span>.</p></li>
15219+
parser</span> or <span>XML parser</span>, and it <span>becomes disconnected</span>.</p></li>
1520815220

1520915221
<li><p>The element's <span>children changed steps</span> run.</p></li>
1521015222
</ul>
@@ -58529,24 +58541,30 @@ o............A....e
5852958541

5853058542
<hr>
5853158543

58532-
<p>When a <code>script</code> element that is not marked as being <span>"parser-inserted"</span>
58533-
experiences one of the events listed in the following list, the user agent must
58534-
<span>immediately</span> <span data-x="prepare a script">prepare</span> the <code>script</code>
58535-
element:</p>
58544+
<p>To run the <span data-x="concept-node-insert-ext">insertion steps</span> for a
58545+
<code>script</code> element with <var>script</var> and <var>deferredStepsQueue</var>, the user
58546+
agent must act as follows:</p>
5853658547

58537-
<ul>
58548+
<ol>
58549+
<li><p>If <var>script</var> is marked as being <span>"parser-inserted"</span>, then
58550+
return.<p></li>
5853858551

58539-
<li>The <code>script</code> element <span>becomes connected</span>.</li>
58552+
<li><p>If <var>script</var> is not <span>connected</span>, then return.</p></li>
5854058553

58541-
<li>The <code>script</code> element is <span>connected</span> and a node or document fragment is
58542-
<span data-x="nodes are inserted">inserted</span> into the <code>script</code> element, after any
58543-
<code>script</code> elements <span data-x="nodes are inserted">inserted</span> at that time.</li>
58554+
<li><p><span>Enqueue</span> the steps to <span data-x="prepare a script">prepare</span>
58555+
<var>script</var> to <var>deferredStepsQueue</var>.</p></li>
58556+
</ol>
5854458557

58545-
<li>The <code>script</code> element is <span>connected</span> and has a <code
58546-
data-x="attr-script-src">src</code> attribute set where previously the element had no such
58547-
attribute.</li>
58558+
<p>To run the <span>children changed steps</span> for a <code>script</code> element with
58559+
<var>script</var> and <var>deferredStepsQueue</var>, the user agent must run the <span
58560+
data-x="concept-node-insert-ext">insertion steps</span> with <var>script</var> and
58561+
<var>deferredStepsQueue</var>.</p>
5854858562

58549-
</ul>
58563+
<p>Additionally, when a <code>script</code> element that is not marked as being
58564+
<span>"parser-inserted"</span> is <span>connected</span> and has a <code
58565+
data-x="attr-script-src">src</code> attribute set where previously the element had no such
58566+
attribute, the user agent must <span>immediately</span> <span
58567+
data-x="prepare a script">prepare</span> the <code>script</code> element.</p>
5855058568

5855158569
<p>To <dfn data-x="prepare a script" data-export="">prepare a script</dfn>, the user agent must
5855258570
act as follows:</p>

0 commit comments

Comments
 (0)