From 2f0e9146f9ead4ae429778341fda25c0d45a8377 Mon Sep 17 00:00:00 2001
From: Anne van Kesteren When authoring custom element constructors,
authors are bound by the following conformance requirements:Requirements for custom element constructors
+ Requirements for custom element constructors and
+ reactions
When authoring custom element reactions, + authors should avoid manipulating the node tree as this can lead to unexpected results.
+ +An element's connectedCallback
can be queued before the element is
+ disconnected, but as the callback queue is still processed, it results in a connectedCallback
for an element that is no longer connected:
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
+ A custom element is an element that is + Tomek Wytrębowicz, Tommy Thorsen, Tony Ross, Tooru Fujisawa,