Re: [whatwg/dom] Make it possible to observe connected-ness of a node (#533)

LeaVerou left a comment (whatwg/dom#533)

> > 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`
> 
> `ownerDocument` is never `null` so this won't work.

Ah, right, d'uh! πŸ€¦πŸ½β€β™€οΈ
Now I’m wondering if we need a property that works like this… πŸ˜… 
Basically something like:

```js
get document () {
 let root = this.getRootNode({ composed: true });
 return root.nodeType === Node.DOCUMENT_TYPE ? root : null;
}
```

Whether such a DOM property exists or not, we _could_ introduce a `document` option that works this way.
Or, alternatively, a `root` option that lets you observe changes to either the composed root, the tree root, or both.
That actually seems to be even more broadly useful than what I was proposing above.

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

Message ID: <whatwg/dom/issues/533/3648097899@github.com>

Received on Friday, 12 December 2025 20:48:56 UTC