- From: Lea Verou <notifications@github.com>
- Date: Fri, 12 Dec 2025 12:32:20 -0800
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/533/3648051760@github.com>
LeaVerou left a comment (whatwg/dom#533)
Actually, I’m not sure if observing connectedness is what we need. Consider this:
```js
let parser = new DOMParser();
let doc = (new DOMParser).parseFromString("<p>Hi</p>", "text/html");
let p = doc.querySelector("p");
console.log(p.isConnected); // true
```
It seems that instead what most use cases need is to observe (a) `ownerDocument` changes and (b) `parentNode` changes.
Then we can get all the existing custom element lifecycle hooks:
- `connectedCallback()` → `ownerDocument` goes from `null` to a non-null value
- `disconnectedCallback()` → `ownerDocument` changes from a non-null value to `null`
- `adoptedCallback()` → `ownerDocument` changes from a non-null value to a different non-null value.
- `connectedMoveCallback()` → `parentNode` changes from a non-null value to another non-null value, while `ownerDocument` remains the same
Plus introducing such properties to `MutationObserverInit` is also much more in line with its existing API where options describe the lower-level tree variables. Connectedness is a derived variable.
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/533#issuecomment-3648051760
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/dom/issues/533/3648051760@github.com>
Received on Friday, 12 December 2025 20:32:24 UTC