Bug 1927714 - Missing style invalidation in ShadowRoot::AddSlot(). r=smaug, a=dmeehan

Usually RemoveSlot takes care of this, but if it's not the first slot it
doesn't.

Differential Revision: https://phabricator.services.mozilla.com/D227334
This commit is contained in:
Emilio Cobos Álvarez 2024-10-30 23:24:33 +00:00
parent 94aee03af5
commit f8c0802719
4 changed files with 43 additions and 0 deletions

View File

@ -253,6 +253,8 @@ void ShadowRoot::AddSlot(HTMLSlotElement* aSlot) {
return; return;
} }
InvalidateStyleAndLayoutOnSubtree(aSlot);
HTMLSlotElement* oldSlot = currentSlots->SafeElementAt(1); HTMLSlotElement* oldSlot = currentSlots->SafeElementAt(1);
if (SlotAssignment() == SlotAssignmentMode::Named) { if (SlotAssignment() == SlotAssignmentMode::Named) {
if (oldSlot) { if (oldSlot) {

View File

@ -0,0 +1,15 @@
<!doctype html>
<div id="host">
<template shadowrootmode="open">
<slot></slot>
<slot></slot>
</template>
<div id="child1">Child1</div>
<div id="child2" slot="named-slot">Child2</div>
</div>
<script>
host.getBoundingClientRect();
host.shadowRoot.querySelectorAll("slot")[1].name = "named-slot";
host.style.display = "flex";
host.getBoundingClientRect();
</script>

View File

@ -0,0 +1,6 @@
<!doctype html>
<title>CSS Test Reference</title>
<div id="host">
<div>Child1</div>
<div>Child2</div>
</div>

View File

@ -0,0 +1,20 @@
<!doctype html>
<meta charset="utf-8">
<title>CSS Scoping: Dynamic reassignment of a named slot child.</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="help" href="https://drafts.csswg.org/css-scoping/#selectors-data-model">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1927714">
<link rel="match" href="shadow-reassign-dynamic-006-ref.html">
<div id="host">
<template shadowrootmode="open">
<slot></slot>
<slot></slot>
</template>
<div id="child1">Child1</div>
<div id="child2" slot="named-slot">Child2</div>
</div>
<script>
host.getBoundingClientRect();
host.shadowRoot.querySelectorAll("slot")[1].name = "named-slot";
host.getBoundingClientRect();
</script>