A bug report from orstavik77@gmail.com
--
bug summary:
UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.16 Safari/537.36
Steps to reproduce the problem:
customElements.define("needs-chrome-fix-bug", class X extends HTMLElement{});
const div = document.createElement("needs-chrome-fix-bug");
const slot = document.createElement("slot");
const slot2 = document.createElement("slot");
div.appendChild(slot);
div.attachShadow({mode: "open"});
div.shadowRoot.appendChild(slot2);
const assignedNodesOutside = slot.assignedNodes({flatten: true});
const assignedNodesInside = slot2.assignedNodes({flatten: true});
console.assert(assignedNodesOutside.length === 0);
console.assert(assignedNodesInside.length === 0);
console.log(assignedNodesOutside);
console.log(assignedNodesInside);
What is the expected behavior?
BUG: slot2.assignedNodes({flatten: true}) should return an empty list, not a list containing the top slot element.
CORRECT BEHAVIOR: slot.assignedNodes({flatten: true}) does return an empty list, as expected, not a list containing itself.
What went wrong?
This problem only occurs when the top slot element is placed in the top document. Such a slot element is of course wrong, as slot elements should only be placed inside a shadowDOM. But the erroneous slot element at the top level, should still be removed by the assignedNodes({flatten: true}) when run recursively.
Full testcase here:
https://codepen.io/orstavik/pen/jvgVro?editors=1000
Did this work before? N/A
Does this work in other browsers? Yes, Firefox with web comps enabled
Chrome version: 70.0.3538.16 Channel: n/a
OS Version:
Flash Version:
For more tests, see:
https://codepen.io/orstavik/pen/jvgVro?editors=1000
Comment 1 by hayato@chromium.org
, Sep 26orstavik77@ Thanks for reporting. I think the current behavior is correct. I remember we changed the DOM Standard so that a slot element which is *not* in a shadow tree should not be considered as a *slot*. That means we don't try to *flatten* a slot element which is not in a shadow tree. Such a slot element behaves as if it were *normal* elements. So they would remain in the result of .assignedNodes({flatten: true}). The relevant Standard is here: https://dom.spec.whatwg.org/#finding-slots-and-slotables > To find flattened slotables for a given slot slot, run these steps: > .. > 5. For each node in slotables: > 1. If node is a slot whose root is a shadow root, then: > 1. Let temporaryResult be the result of finding flattened slotables given node. > 2. Append each slotable in temporaryResult, in order, to result. > 2. Otherwise, append node to result.