Skip to content

Commit

Permalink
Custom element reactions ought not to modify the node tree
Browse files Browse the repository at this point in the history
Supersedes and closes whatwg#4127. Closes WICG/webcomponents#760.
  • Loading branch information
annevk authored and Alice Boxhall committed Jan 7, 2019
1 parent bdecbb2 commit 6ea10cf
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion source
Original file line number Diff line number Diff line change
Expand Up @@ -66304,7 +66304,8 @@ console.log(plasticButton.outerHTML); // will output '<button is="plastic-but
console.assert(outOfDocument instanceof ExampleElement);
&lt;/script></code></pre>

<h4 id="custom-element-conformance">Requirements for custom element constructors</h4>
<h4 id="custom-element-conformance">Requirements for custom element constructors and
reactions</h4>

<p>When authoring <span data-x="custom element constructor">custom element constructors</span>,
authors are bound by the following conformance requirements:</p>
Expand Down Expand Up @@ -66344,6 +66345,37 @@ console.log(plasticButton.outerHTML); // will output '&lt;button is="plastic-but
done inside a constructor-initiated <span>microtask</span>, as a <span data-x="perform a microtask
checkpoint">microtask checkpoint</span> can occur immediately after construction.</p>

<p>When authoring <span data-x="concept-custom-element-reaction">custom element reactions</span>,
authors should avoid manipulating the node tree as this can lead to unexpected results.</p>

<div class="example">
<p>An element's <code data-x="">connectedCallback</code> can be queued before the element is
disconnected, but as the callback queue is still processed, it results in a <code
data-x="">connectedCallback</code> for an element that is no longer connected:</p>

<pre><code class="js" data-x="">class CParent extends HTMLElement {
connectedCallback() {
this.firstChild.remove();
}
}
customElements.define("c-parent", CParent);

class CChild extends HTMLElement {
connectedCallback() {
console.log("CChild connectedCallback: isConnected =", this.isConnected);
}
}
customElements.define("c-child", CChild);

const parent = new CParent(),
child = new CChild();
parent.append(child);
document.body.append(parent);

// Logs:
// CChild connectedCallback: isConnected = false</code></pre>
</div>

<h4 id="custom-elements-core-concepts">Core concepts</h4>

<p>A <dfn data-export="">custom element</dfn> is an element that is <span
Expand Down Expand Up @@ -122778,6 +122810,7 @@ INSERT INTERFACES HERE
Tom Pike,
Tom Schuster,
Tomasz Jakut, <!-- Comandeer on GitHub -->
Tomek Wytrębowicz,
Tommy Thorsen,
Tony Ross,
Tooru Fujisawa,
Expand Down

0 comments on commit 6ea10cf

Please sign in to comment.