From 34f9019340fa9c7712b3155903adec654e80320f Mon Sep 17 00:00:00 2001
From: Anne van Kesteren
If callback is null, then return
If callbackName is "attributeChangedCallback
", then:
If callback is non-null, then:
Let attributeName be the first element of args.
If callbackName is "attributeChangedCallback
", then:
Let attributeName be the first element of args.
If definition's observed attributes does - not contain attributeName, then return.
If definition's observed attributes + does not contain attributeName, then return.
Add a new callback reaction to element's custom element + reaction queue, with callback function callback and arguments + args.
Add a new callback reaction to element's custom element - reaction queue, with callback function callback and arguments - args.
Enqueue an element on the appropriate element queue given element.
If callback is non-null, then:
Let skip be false.
If callbackName is "attributeChangedCallback
", then:
If definition's observed attributes - does not contain attributeName, then return.
Add a new callback reaction to element's custom element - reaction queue, with callback function callback and arguments - args.
If skip is false, then add a new callback reaction to + element's custom element reaction queue, with callback function + callback and arguments args.
Unfortunately due to the nature of the queueing these reactions there can be somewhat + unexpected corner cases: + +
class CParent extends HTMLElement {
+ connectedCallback() {
+ const child = this.childNodes[0];
+ this.removeChild(child);
+ }
+}
+customElements.define("c-parent", CParent);
+
+class CChild extends HTMLElement {
+ connectedCallback() {
+ console.log("CChild connectedCallback isConnected=" + this.isConnected.toString());
+ }
+}
+customElements.define("c-child", CChild);
+
+const container = document.createElement("div");
+container.innerHTML = "<c-parent><c-child></c-child></c-parent>";
+customElements.upgrade(container);
+document.body.appendChild(container);
+// CChild connectedCallback isConnected=false
+ To enqueue a custom element upgrade reaction, given an element element and custom element definition definition, run the following steps:
@@ -122328,6 +122356,7 @@ INSERT INTERFACES HERE Tom Pike, Tom Schuster, Tomasz Jakut, + Tomek Wytrębowicz, Tommy Thorsen, Tony Ross, Tooru Fujisawa, From c165c788bfe4459b022fd7b80c4f2185229bb750 Mon Sep 17 00:00:00 2001 From: Anne van KesterenUnfortunately due to the nature of the queueing these reactions there can be somewhat - unexpected corner cases: +
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() {
- const child = this.childNodes[0];
- this.removeChild(child);
+ this.firstChild.remove();
}
}
customElements.define("c-parent", CParent);
class CChild extends HTMLElement {
connectedCallback() {
- console.log("CChild connectedCallback isConnected=" + this.isConnected.toString());
+ console.log("CChild connectedCallback: isConnected =", this.isConnected);
}
}
customElements.define("c-child", CChild);
@@ -67084,7 +67084,9 @@ const container = document.createElement("div");
container.innerHTML = "<c-parent><c-child></c-child></c-parent>";
customElements.upgrade(container);
document.body.appendChild(container);
-// CChild connectedCallback isConnected=false
+
+// Logs:
+// CChild connectedCallback: isConnected = false
To enqueue a custom element upgrade reaction, given an element