Re: [w3c/webcomponents] DOM APIs which replace all children end up firing superfluous slotchange events (#764)

You also get slotchange events that can be perceived as redundant when you construct layered custom elements with slots. This seems to be correct behavior according to spec, and it happens similarly in both Chrome, Firefox and Safari. But from the developer standpoint they are somewhat unexpected and can cause confusion.

The minimal situation:
1. You have custom element B that uses custom A in its shadowRoot.
2. Both A and B have slots, and adds a slotchange listener to their shadowRoot in their constructor.
3. The slots are nested. B puts its slot in the slottable position of A.
4. If you create B, with something in its slottable position, then that will fire:
a. 2 slotchange event in A and
b. 1 slotchange events in B.

https://codepen.io/orstavik/pen/jeEqpe

This problem also grows as you nest slot and web components deeper. If you have 3 layers, C -> B -> A, then you will get a total of 6 slotchange events:
3 slotchange event in A
2 slotchange events in B
1 slotchange event in C

https://codepen.io/orstavik/pen/bmNpLv

The content of the last codepen (that can be used to create both situations) I also add as an attachment.
[redundantSlotchangeEvents.txt](https://github.com/w3c/webcomponents/files/2430274/redundantSlotchangeEvents.txt)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/764#issuecomment-425614872

Received on Saturday, 29 September 2018 04:27:58 UTC