Skip to content

Commit

Permalink
Process custom element connectedCallback immediately during parsing
Browse files Browse the repository at this point in the history
Fixes WICG/webcomponents#551 by ensuring that
insertions into the DOM trigger connectedCallback immediately, instead
of putting the callback reaction on the the backup element queue and
letting it get triggered at the next microtask checkpoint. This means
connectedCallback will generally be invoked when the element has zero
children, as expected, instead of a random number depending on when the
next custom element is seen.
  • Loading branch information
domenic authored and Alice Boxhall committed Jan 7, 2019
1 parent 312df5c commit 03f25f4
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -103585,31 +103585,39 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {
in a given namespace, the user agent must run these steps:</p>

<ol>

<li><p>Let the <var>adjusted insertion location</var> be the <span>appropriate place for
inserting a node</span>.</p></li>

<li><p><span>Create an element for the token</span> in the given namespace, with the intended
<!-- this insertion stuff should be cleaned up: https://github.com/whatwg/html/issues/1706 -->

<li><p>Let <var>element</var> be the result of <span data-x="create an element for the
token">creating an element for the token</span> in the given namespace, with the intended
parent being the element in which the <var>adjusted insertion location</var> finds
itself.</p></li>

<li>
<p>If it is possible to insert <var>element</var> at the <var>adjusted insertion location</var>,
then:</p>

<ol>
<li><p>Push a new <span>element queue</span> onto the <span>custom element reactions
stack</span>.</li>

<p>If it is possible to insert an element at the <var>adjusted insertion
location</var>, then insert the newly created element at the <var>adjusted insertion
location</var>.</p>
<li><p>Insert <var>element</var> at the <var>adjusted insertion location</var>.</p></li>

<p class="note">If the <var>adjusted insertion location</var> cannot accept more
elements, e.g. because it's a <code>Document</code> that already has an element child, then the
newly created element is dropped on the floor.</p>
<li><p>Pop the <span>element queue</span> from the <span>custom element reactions stack</span>,
and <span>invoke custom element reactions</span> in that queue.</p></li>
</ol>

<p class="note">If the <var>adjusted insertion location</var> cannot accept more
elements, e.g. because it's a <code>Document</code> that already has an element child, then
<var>element</var> is dropped on the floor.</p>
</li>

<li><p>Push the element onto the <span>stack of open elements</span> so that it is the new
<li><p>Push <var>element</var> onto the <span>stack of open elements</span> so that it is the new
<span>current node</span>.</p></li>

<li><p>Return the newly created element.</p></li>

<li><p>Return <var>element</var>.</p></li>
</ol>

<p>When the steps below require the user agent to <dfn>insert an HTML element</dfn> for a token,
Expand Down

0 comments on commit 03f25f4

Please sign in to comment.