Element moving between shadow-trees for no-op between lifecycles.
FlatTreeNodeData is cleared on insertion so that nodes moving between shadow trees do not keep stale parent information since we use the FlatTreeNodeData ancestor to mark ancestors style dirty without updating the slot assignment. This is normally fine since inserting a child node of a shadow host will mark the host for slot re-assignment, and the slot re-assignment will update FlatTreeNodeData accordingly. The diffing of flat tree children in NotifySlottedNodesOfFlatTreeChange will mark the inserted node for style recalc via FlatTreeParentChanged. There is however a glitch which can happen if a node is removed from a shadow host, inserted into a different node, and then moved back into the original shadow host without having any re-slotting happening in between. If the node ends up in the same flat tree position, we will not be able to detect that it needs FlatTreeParentChanged to be marked for style recalc. Example: <div id="host"> <:shadow-root> <slot></slot> </:shadow-root> <span>PASS</span></div> <div id="other"></div> <script> // Make everything clean. FlatTreeNodeData ancestor for the span is // the slot. host.offsetTop; let slotted = host.querySelector("span"); // The span is removed, the layout object is detached, and the // ComputedStyle is cleared. slotted.remove(); // Insert span into the #other element, FlatTreeNodeData for the span // is cleared. The host is marked for slot re-assignment. other.appendChild(slotted); // The span is re-added as a child of #host, but nothing is marked // style dirty since the #host has a shadow root and the span is not // yet part of the flat tree. host.appendChild(slotted); // Slot re-assignment happens, but the result of slotting is the same // as for the last lifecycle update, and nothing is marked dirty. That // results in the span not getting a ComputedStyle nor a LayoutObject. host.offsetTop; </script> The solution is currently to do a FlatTreeParentChanged for the case where we: 1. Already have a FlatTreeNodeData. 2. The FlatTreeNodeData ancestor is null before the slot assignments. 3. The node is assigned to a slot. It is definitely correct and necessary that we call FlatTreeParentChanged in this case, but we end up doing it twice for other elements which were added to the host, which used to be a child of another host (FlatTreeNodeData being non-null), and will also have FlatTreeParentChanged being called in the diffing as well. The question is if that will cause perf regressions, typically in microbenchmarks. Bug: 1072475 Change-Id: I5e697570b74599b0a3e01ca869eac022105fc6b9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2160930 Commit-Queue: Rune Lillesveen <futhark@chromium.org> Reviewed-by:Mason Freed <masonfreed@chromium.org> Cr-Commit-Position: refs/heads/master@{#763537}
Showing
Please register or sign in to comment