Skip to content

DOM APIs which replace all children end up firing superfluous slotchange events #764

Open
@rniwa

Description

@rniwa

When replacing all children of a node, via textContent for example, removing each child of the node results in the invocation of the concept to 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 is evaluated, slot2 and slot3 are no longer in the tree.

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions