Skip to content

Commit 6738327

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 6738327

File tree

1 file changed

+50
-29
lines changed

1 file changed

+50
-29
lines changed

source

+50-29
Original file line numberDiff line numberDiff line change
@@ -2072,10 +2072,10 @@ 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
@@ -2088,8 +2088,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
20882088
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>
@@ -3195,6 +3196,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
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>,
31973198
<dfn data-x="concept-node-adopt-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt-ext">adopting steps</dfn>, and
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,22 @@ 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 abort those
15054+
steps.<p></li>
15055+
15056+
<li><p>If <var>style</var> is not <span>connected</span>, then abort those steps.</p></li>
15057+
15058+
<li><p><span>Enqueue</span> the steps to <span data-x="update a style block">update</span>
15059+
<var>style</var> to <var>deferredStepsQueue</var>.</p></li>
15060+
</ol>
15061+
15062+
<p>Additionally, the user agent must run the <span>update a <code>style</code> block</span>
15063+
algorithm whenever one of the following conditions occur:</p>
1504815064
<!-- note that a browsing context isn't needed:
1504915065
https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2739 -->
1505015066

@@ -15053,8 +15069,7 @@ interface <dfn>HTMLStyleElement</dfn> : <span>HTMLElement</span> {
1505315069
parser</span> or <span>XML parser</span>.</p></li>
1505415070

1505515071
<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>
15072+
parser</span> or <span>XML parser</span>, and it <span>becomes disconnected</span>.</p></li>
1505815073

1505915074
<li><p>The element's <span>child text content change steps</span> run.</p></li>
1506015075
</ul>
@@ -58110,24 +58125,30 @@ o............A....e
5811058125

5811158126
<hr>
5811258127

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>
58128+
<p>To run the <span data-x="concept-node-insert-ext">insertion steps</span> for a
58129+
<code>script</code> element with <var>script</var> and <var>deferredStepsQueue</var>, the user
58130+
agent must act as follows:</p>
5811758131

58118-
<ul>
58132+
<ol>
58133+
<li><p>If <var>script</var> is marked as being <span>"parser-inserted"</span>, then
58134+
abort those steps.<p></li>
5811958135

58120-
<li>The <code>script</code> element <span>becomes connected</span>.</li>
58136+
<li><p>If <var>script</var> is not <span>connected</span>, then abort those steps.</p></li>
5812158137

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>
58138+
<li><p><span>Enqueue</span> the steps to <span data-x="prepare a script">prepare</span>
58139+
<var>script</var> to <var>deferredStepsQueue</var>.</p></li>
58140+
</ol>
5812558141

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>
58142+
<p>To run the <span data-x="concept-node-children-added">children added steps</span> for a
58143+
<code>script</code> element with <var>script</var> and <var>deferredStepsQueue</var>, the user
58144+
agent must run the <span data-x="concept-node-insert-ext">insertion steps</span> with
58145+
<var>script</var> and <var>deferredStepsQueue</var>.</p>
5812958146

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

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

0 commit comments

Comments
 (0)