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

jpzwarte created an issue (whatwg/dom#1415)

### What problem are you trying to solve?

As a custom element author, you have a couple of mechanism available to you to detect changes in slotted elements:
1. The `slotchange` event
2. `MutationObserver`

For most cases `slotchange` is enough, but if you want to detect changes to attributes for example, you need `MutationObserver`.

Now as long as you have no nested slots, then everything is fine. However, as soon as you have a nested slot, `MutationObserver` also no longer works. For example:

```html
<x-foo>
  <template shadowrootmode="open">
    <x-bar>
      <template shadowrootmode="open">
        <slot></slot>
      </template>      
      <slot></slot>
    </x-bar>
  </template>
  <button>Button</button>
</x-foo>
```

In the above scenario `<x-bar>` would have a `MutationObserver` that monitors it's own host element. It will not fire when the button changes or a second button is added.

I propose a new option to the `MutationObserver.observe()` method called `flatten` or `composed` (name TBD) that would instruct the observer to also observe any slotted children of any slots it is observing.

### What solutions exist today?

None

### How would you solve it?

New `flatten` or `composed` option to `MutationObserver.observe()`

### Anything else?

_No response_

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

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

Received on Tuesday, 21 October 2025 13:43:23 UTC