Skip to content

Commit ced2bde

Browse files
committed
Use a queue of deferred steps in the node insertion algorithm
1 parent 55b4dbb commit ced2bde

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

dom.bs

+28-10
Original file line numberDiff line numberDiff line change
@@ -2389,12 +2389,10 @@ of a <var>node</var> into a <var>parent</var> before a <var>child</var>, run the
23892389
</ol>
23902390

23912391
<p><a lt="Other applicable specifications">Specifications</a> may define
2392-
<dfn export id=concept-node-insert-ext>insertion steps</dfn> for all or some <a for=/>nodes</a>. The
2393-
algorithm is passed <var ignore>insertedNode</var>, as indicated in the <a for=/>insert</a>
2394-
algorithm below.
2395-
<!-- See https://github.com/whatwg/dom/issues/34#issuecomment-125571750 for why we might need to
2396-
adjust this further based on the requirements of the script element. There might be other ways
2397-
to define that though as Olli suggests, so leaving that out for now. -->
2392+
<dfn export id=concept-node-insert-ext>insertion steps</dfn> or
2393+
<dfn export id=concept-node-children-added>children added steps</dfn> for all or some
2394+
<a for=/>nodes</a>. The two algorithms are passed <var ignore>insertedNode</var> and
2395+
<var ignore>deferredStepsQueue</var>, as indicated in the <a for=/>insert</a> algorithm below.
23982396

23992397
<p>To <dfn export id=concept-node-insert>insert</dfn> a <var>node</var> into a <var>parent</var>
24002398
before a <var>child</var>, with an optional <i>suppress observers flag</i>, run these steps:
@@ -2440,8 +2438,12 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
24402438
<li><p>Let <var>previousSibling</var> be <var>child</var>'s <a>previous sibling</a> or
24412439
<var>parent</var>'s <a>last child</a> if <var>child</var> is null.
24422440

2441+
<li><p>Let <var>deferredStepsQueue</var> be an empty <a>queue</a>.
2442+
2443+
<li><p>Let <var>textChanged</var> be false.
2444+
24432445
<li>
2444-
<p>For each <var>node</var> in <var>nodes</var>, in <a>tree order</a>:
2446+
<p><a for=list>For each</a> <var>node</var> in <var>nodes</var>:
24452447

24462448
<ol>
24472449
<li><p>If <var>child</var> is null, then <a for=set>append</a> <var>node</var> to
@@ -2453,8 +2455,7 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
24532455
<li><p>If <var>parent</var> is a <a for=Element>shadow host</a> and <var>node</var> is a
24542456
<a>slotable</a>, then <a>assign a slot</a> for <var>node</var>.
24552457

2456-
<li>If <var>node</var> is a {{Text}} node, run the <a>child text content change steps</a> for
2457-
<var>parent</var>.
2458+
<li>If <var>node</var> is a {{Text}} node, then set <var>textChanged</var> to true.
24582459

24592460
<li><p>If <var>parent</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a>, and
24602461
<var>parent</var> is a <a>slot</a> whose <a for=slot>assigned nodes</a> is the empty list,
@@ -2467,7 +2468,8 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
24672468
<var>node</var>, in <a>shadow-including tree order</a>:
24682469

24692470
<ol>
2470-
<li><p>Run the <a>insertion steps</a> with <var>inclusiveDescendant</var>.
2471+
<li><p>Run the <a>insertion steps</a> with <var>inclusiveDescendant</var> and
2472+
<var>deferredStepsQueue</var>.
24712473

24722474
<li>
24732475
<p>If <var>inclusiveDescendant</var> is <a>connected</a>, then:
@@ -2490,6 +2492,22 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
24902492
</li>
24912493
</ol>
24922494

2495+
<li><p>If <var>textChanged</var> is true, then run the <a>child text content change steps</a> for
2496+
<var>parent</var>.
2497+
2498+
<li><p>If <var>nodes</var> is not empty, then run the <a>children added steps</a> with
2499+
<var>parent</var> and <var>deferredStepsQueue</var>.
2500+
2501+
<li>
2502+
<p>While <var>deferredStepsQueue</var> <a for=list>is not empty</a>:
2503+
2504+
<ol>
2505+
<li><p>Let <var>deferredSteps</var> be the result of <a for=queue>dequeueing</a>
2506+
<var>deferredStepsQueue</var>.
2507+
2508+
<li><p>Run <var>deferredSteps</var>.
2509+
</ol>
2510+
24932511
<li><p>If <i>suppress observers flag</i> is unset, then <a>queue a tree mutation record</a> for
24942512
<var>parent</var> with <var>nodes</var>, « », <var>previousSibling</var>, and <var>child</var>.
24952513
</ol>

0 commit comments

Comments
 (0)