Re: [whatwg/dom] Allow `MutationObserver` to observe (certain) element property changes (Issue #1340)

LeaVerou left a comment (whatwg/dom#1340)

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. And introducing such properties to `MutationObserverInit` is also much more in line with its existing API.

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


-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1340#issuecomment-3647610486
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1340/3647610486@github.com>

Received on Friday, 12 December 2025 18:14:49 UTC