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

When [replacing all children](https://dom.spec.whatwg.org/#concept-node-replace-all) of a node, via [`textContent`](https://dom.spec.whatwg.org/#dom-node-textcontent) for example, [removing](https://dom.spec.whatwg.org/#concept-node-remove) each child of the node results in the invocation of [the concept to assign slotables for a tree](https://dom.spec.whatwg.org/#assign-slotables-for-a-tree).

For example, consider the following shadow tree:
`<p id="target"><slot id="slot1"></slot><slot id="slot2"></slot><slot id="slot3"></slot></p>`

If `target.textContent = ''` is evaluated, it would result in the removal of `slot1`, followed by that of `slot2` and `slot3`. As a result, we would fire `slotchange` event on `slot2` and `slot3` despite of the fact those slots would have never been "rendered" with assigned nodes in practice.

This results in `slotchange` event handlers of `slot2` and `slot3` potentially doing unnecessary & useless work.

Relatedly, Firefox's implementation seems to fire `slotchange` on `slot2` & `slot3` when `target.remove()` is evaluated, which seems wrong because the time at which [the concept to assign slotables for a tree](https://dom.spec.whatwg.org/#assign-slotables-for-a-tree) is evaluated, `slot2` and `slot3` are no longer in the tree.

See https://gist.github.com/rniwa/1a24c77317a50785ae8885e58f35966c for the demo.


-- 
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

Received on Thursday, 30 August 2018 23:57:54 UTC