Re: [whatwg/dom] Allow `MutationObserver` to observe across `<slot>`s (Issue #1415)

sorvell left a comment (whatwg/dom#1415)

This would be a useful addition. 

Right now, although it's a little clunky, I think you can leverage `slotchange` to do most of this:

```js
const myObserver = new MutationObserver(callback);

let previousAssigned = new Set();

slot.addEventListener('slotchange', (e) => {
  myObserver.disconnect();
  const assigned = new Set(this.observeSlot.assignedElements({flatten: true}));
  assigned.forEach(el => {
    myObserver.observe(el, {attributes: true});
  });

  // if needed, an process slot changes similar to other mutation observer childList mutations...
  const addedNodes = Array.from(assigned.difference(previousAssigned));
  const removedNodes = Array.from(previousAssigned.difference(assigned));
  callback([{target: slot, addedNodes, removedNodes}])

  previousAssigned = assigned;
})
```

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

Message ID: <whatwg/dom/issues/1415/3440085533@github.com>

Received on Friday, 24 October 2025 00:32:36 UTC