-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fast path in Node::assign_slottables_for_a_tree is wrong #35188
Copy link
Copy link
Closed
Labels
A-content/domInteracting with the DOM from web contentInteracting with the DOM from web contentI-perf-slowUnnecessary performance degredation.Unnecessary performance degredation.I-wrongAn incorrect behaviour is observed.An incorrect behaviour is observed.
Description
code:
servo/components/script/dom/node.rs
Lines 1321 to 1328 in 3bcab36
| /// <https://dom.spec.whatwg.org/#assign-slotables-for-a-tree> | |
| pub(crate) fn assign_slottables_for_a_tree(&self) { | |
| // NOTE: This method traverses all descendants of the node and is potentially very | |
| // expensive. If the node is not a shadow root then assigning slottables to it won't | |
| // have any effect, so we take a fast path out. | |
| if !self.is::<ShadowRoot>() { | |
| return; | |
| } |
This assumption is wrong. If the root is not a shadow tree then we will never assign new slottables to it, but existing assigned slottables may be removed.
This snippet demonstrates the issue:
<body>
<div id="host">
Before
<div id="content" slot="foo">This is some Text</div>
</div>
<script defer>
let host = document.getElementById("host");
let root = host.attachShadow({mode: "closed"});
let slot = document.createElement("slot");
slot.style = "color: green;"
slot.name = "foo";
root.appendChild(slot);
slot.remove();
// Should be empty, the slot is not in the DOM tree anymore
console.log(slot.assignedNodes());
</script>Without the fast path many tests start to fail in CI because they take too long, so we will have to come up with a new optimization instead. (At least this was the case in the past)
Also, the same optimization is present in ladybird (I originally copied it from them), so they're likely wrong too.
Part of #34318
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-content/domInteracting with the DOM from web contentInteracting with the DOM from web contentI-perf-slowUnnecessary performance degredation.Unnecessary performance degredation.I-wrongAn incorrect behaviour is observed.An incorrect behaviour is observed.