Skip to content

Commit 0b507c1

Browse files
committed
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 775cfc2 commit 0b507c1

File tree

1 file changed

+56
-36
lines changed

1 file changed

+56
-36
lines changed

source

+56-36
Original file line numberDiff line numberDiff line change
@@ -2072,24 +2072,24 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
20722072

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

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

20902090
<p>A node <dfn data-export="">becomes connected</dfn> when the <span
2091-
data-x="concept-node-insert-ext">insertion steps</span> are invoked with it as the argument and it
2092-
is now <span>connected</span>. Analogously, a node <dfn data-lt="become disconnected"
2091+
data-x="concept-node-insert-ext">insertion steps</span> are invoked with it as the first argument
2092+
and it is now <span>connected</span>. Analogously, a node <dfn data-lt="become disconnected"
20932093
data-export="">becomes disconnected</dfn> when the <span data-x="concept-node-remove-ext">removing
20942094
steps</span> are invoked with it as the argument and it is now no longer
20952095
<span>connected</span>.</p>
@@ -2098,12 +2098,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
20982098
<span>connected</span> and its <span data-x="shadow-including root">shadow-including root</span>
20992099
has a <span data-x="concept-document-bc">browsing context</span>. A node <dfn data-lt="become
21002100
browsing-context connected" data-export="">becomes browsing-context connected</dfn> when the <span
2101-
data-x="concept-node-insert-ext">insertion steps</span> are invoked with it as the argument and it
2102-
is now <span>browsing-context connected</span>. A node <dfn data-lt="become browsing-context
2103-
disconnected" data-export="">becomes browsing-context disconnected</dfn> either when the <span
2104-
data-x="concept-node-remove-ext">removing steps</span> are invoked with it as the argument and it
2105-
is now no longer <span>browsing-context connected</span>, or when its <span>shadow-including
2106-
root</span> no longer has a <span data-x="concept-document-bc">browsing context</span>.
2101+
data-x="concept-node-insert-ext">insertion steps</span> are invoked with it as the first argument
2102+
and it is now <span>browsing-context connected</span>. A node <dfn data-lt="become
2103+
browsing-context disconnected" data-export="">becomes browsing-context disconnected</dfn> either
2104+
when the <span data-x="concept-node-remove-ext">removing steps</span> are invoked with it as the
2105+
argument and it is now no longer <span>browsing-context connected</span>, or when its
2106+
<span>shadow-including root</span> no longer has a <span data-x="concept-document-bc">browsing
2107+
context</span>.
21072108

21082109

21092110
<h4>Scripting</h4>
@@ -3194,7 +3195,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
31943195
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#concept-node-pre-insert">pre-insert</dfn>, <dfn data-x="concept-node-insert" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert">insert</dfn>, <dfn data-x="concept-node-append" data-x-href="https://dom.spec.whatwg.org/#concept-node-append">append</dfn>, <dfn data-x="concept-node-replace" data-x-href="https://dom.spec.whatwg.org/#concept-node-replace">replace</dfn>, <dfn data-x="concept-node-replace-all" data-x-href="https://dom.spec.whatwg.org/#concept-node-replace-all">replace all</dfn>, <dfn data-x="concept-node-remove" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove">remove</dfn>, and <dfn data-x="concept-node-adopt" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt">adopt</dfn> algorithms for nodes</li>
31953196
<li>The <dfn data-x="concept-node-insert-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert-ext">insertion steps</dfn>,
31963197
<dfn data-x="concept-node-remove-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove-ext">removing steps</dfn>,
3197-
<dfn data-x="concept-node-adopt-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt-ext">adopting steps</dfn>, and
3198+
<dfn data-x="concept-node-adopt-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt-ext">adopting steps</dfn>,
3199+
<dfn data-x="concept-node-children-added" data-x-href="https://dom.spec.whatwg.org/#concept-node-children-added-ext">children added steps</dfn>, and
31983200
<dfn data-x-href="https://dom.spec.whatwg.org/#concept-node-text-change-ext">child text content change steps</dfn> hooks for elements</li>
31993201
<li>The <dfn data-x="concept-element-attributes-change" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-change">change</dfn>, <dfn data-x="concept-element-attributes-append" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-append">append</dfn>, <dfn data-x="concept-element-attributes-remove" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-remove">remove</dfn>, <dfn data-x="concept-element-attributes-replace" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-replace">replace</dfn>, and <dfn data-x="concept-element-attributes-set-value" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-set-value">set value</dfn> algorithms for attributes</li>
32003202
<li>The <dfn data-x="concept-element-attributes-change-ext" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-change-ext">attribute change steps</dfn> hook for attributes</li>
@@ -15043,8 +15045,21 @@ interface <dfn>HTMLStyleElement</dfn> : <span>HTMLElement</span> {
1504315045

1504415046
<div w-nodev>
1504515047

15046-
<p>The user agent must run the <span>update a <code>style</code> block</span> algorithm whenever
15047-
one of the following conditions occur:</p>
15048+
<p>To run the <span data-x="concept-node-insert-ext">insertion steps</span> for a
15049+
<code>style</code> element with <var>style</var> and <var>deferredStepsQueue</var>, the user
15050+
agent must act as follows:</p>
15051+
15052+
<ol>
15053+
<li><p>If <var>style</var> is on the <span>stack of open elements</span>, then return.<p></li>
15054+
15055+
<li><p>If <var>style</var> is not <span>connected</span>, then return.</p></li>
15056+
15057+
<li><p><span>Enqueue</span> the steps to <span data-x="update a style block">update</span>
15058+
<var>style</var> to <var>deferredStepsQueue</var>.</p></li>
15059+
</ol>
15060+
15061+
<p>Additionally, the user agent must run the <span>update a <code>style</code> block</span>
15062+
algorithm whenever one of the following conditions occur:</p>
1504815063
<!-- note that a browsing context isn't needed:
1504915064
https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2739 -->
1505015065

@@ -15053,8 +15068,7 @@ interface <dfn>HTMLStyleElement</dfn> : <span>HTMLElement</span> {
1505315068
parser</span> or <span>XML parser</span>.</p></li>
1505415069

1505515070
<li><p>The element is not on the <span>stack of open elements</span> of an <span>HTML
15056-
parser</span> or <span>XML parser</span>, and it <span>becomes connected</span> or <span
15057-
data-x="becomes disconnected">disconnected</span>.</p></li>
15071+
parser</span> or <span>XML parser</span>, and it <span>becomes disconnected</span>.</p></li>
1505815072

1505915073
<li><p>The element's <span>child text content change steps</span> run.</p></li>
1506015074
</ul>
@@ -58110,24 +58124,30 @@ o............A....e
5811058124

5811158125
<hr>
5811258126

58113-
<p>When a <code>script</code> element that is not marked as being <span>"parser-inserted"</span>
58114-
experiences one of the events listed in the following list, the user agent must
58115-
<span>immediately</span> <span data-x="prepare a script">prepare</span> the <code>script</code>
58116-
element:</p>
58127+
<p>To run the <span data-x="concept-node-insert-ext">insertion steps</span> for a
58128+
<code>script</code> element with <var>script</var> and <var>deferredStepsQueue</var>, the user
58129+
agent must act as follows:</p>
5811758130

58118-
<ul>
58131+
<ol>
58132+
<li><p>If <var>script</var> is marked as being <span>"parser-inserted"</span>, then
58133+
return.<p></li>
5811958134

58120-
<li>The <code>script</code> element <span>becomes connected</span>.</li>
58135+
<li><p>If <var>script</var> is not <span>connected</span>, then return.</p></li>
5812158136

58122-
<li>The <code>script</code> element is <span>connected</span> and a node or document fragment is
58123-
<span data-x="nodes are inserted">inserted</span> into the <code>script</code> element, after any
58124-
<code>script</code> elements <span data-x="nodes are inserted">inserted</span> at that time.</li>
58137+
<li><p><span>Enqueue</span> the steps to <span data-x="prepare a script">prepare</span>
58138+
<var>script</var> to <var>deferredStepsQueue</var>.</p></li>
58139+
</ol>
5812558140

58126-
<li>The <code>script</code> element is <span>connected</span> and has a <code
58127-
data-x="attr-script-src">src</code> attribute set where previously the element had no such
58128-
attribute.</li>
58141+
<p>To run the <span data-x="concept-node-children-added">children added steps</span> for a
58142+
<code>script</code> element with <var>script</var> and <var>deferredStepsQueue</var>, the user
58143+
agent must run the <span data-x="concept-node-insert-ext">insertion steps</span> with
58144+
<var>script</var> and <var>deferredStepsQueue</var>.</p>
5812958145

58130-
</ul>
58146+
<p>Additionally, when a <code>script</code> element that is not marked as being
58147+
<span>"parser-inserted"</span> is <span>connected</span> and has a <code
58148+
data-x="attr-script-src">src</code> attribute set where previously the element had no such
58149+
attribute, the user agent must <span>immediately</span> <span
58150+
data-x="prepare a script">prepare</span> the <code>script</code> element.</p>
5813158151

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

0 commit comments

Comments
 (0)