Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<meta charset="utf-8">
<title>Sibling invalidation between elements assigned to different slots</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.t1.trigger1 + .p .inj { color: green }
.t2.trigger2 + .p { color: green }
.t3.trigger3 + .p .inj { color: green }
.t4.trigger4 ~ .p .inj { color: green }
.t5:has(.trigger5) + .p .inj { color: green }
.t6:has(.trigger6) + .p { color: green }
.t7.trigger7 + .p .inj { color: green }
.t8.trigger8 + .p .inj { color: green }
.t9:has(.x9) + .p { color: green }
.t10:has(~ .trigger10) + .p { color: green }
.t11.trigger11 + .p { color: green }
.t12.trigger12 + .p .inj { color: green }
.t13.trigger13 + .p .inj { color: green }
</style>
<div id="host1">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t1" id="e1"></div>
<div slot="b" class="p"><div class="inj" id="target1"></div></div>
</div>
<div id="host2">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t2" id="e2"></div>
<div slot="b" class="p" id="target2"></div>
</div>
<div id="host3">
<template shadowrootmode="open"><slot name="a"></slot><div><div><slot name="b"></slot></div></div></template>
<div slot="a" class="t3" id="e3"></div>
<div slot="b" class="p"><div class="inj" id="target3"></div></div>
</div>
<div id="host4">
<template shadowrootmode="open"><slot name="a"></slot><slot name="c"></slot><slot name="b"></slot></template>
<div slot="a" class="t4" id="e4"></div>
<div slot="c"></div>
<div slot="b" class="p"><div class="inj" id="target4"></div></div>
</div>
<div id="host5">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t5"><span id="e5"></span></div>
<div slot="b" class="p"><div class="inj" id="target5"></div></div>
</div>
<div id="host6">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t6"><span id="e6"></span></div>
<div slot="b" class="p" id="target6"></div>
</div>
<div id="unrelated"></div>
<div id="host7">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t7" id="e7"></div>
<div slot="b" class="p"><div class="inj" id="target7"></div></div>
</div>
<div id="host8">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t8" id="e8"></div>
<div slot="b" class="p"><div class="inj" id="target8"></div></div>
<div slot="a" id="other8"></div>
</div>
<div id="host9">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t9"><span class="x9" id="e9"></span></div>
<div slot="a" class="p" id="target9"></div>
</div>
<div id="host10">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t10"></div>
<div slot="a" class="p" id="target10"></div>
<div slot="b" id="e10"></div>
</div>
<div id="host11">
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<div slot="a" class="t11" id="e11"></div>
<div slot="b" class="p" id="target11"></div>
</div>
<div id="host12">
<template shadowrootmode="open">
<div>
<template shadowrootmode="open"><slot name="a"></slot><slot name="b"></slot></template>
<slot name="a" slot="a"></slot>
<slot name="b" slot="b"></slot>
</div>
</template>
<div slot="a" class="t12" id="e12"></div>
<div slot="b" class="p"><div class="inj" id="target12"></div></div>
<div slot="a" id="other12"></div>
</div>
<div id="host13">
<template shadowrootmode="open"><div id="wrapper13"><slot name="a"></slot></div><slot name="b"></slot></template>
<div slot="a" class="t13" id="e13"></div>
<div slot="b" class="p"><div class="inj" id="target13"></div></div>
</div>
<script>
setup({ explicit_done: true });
const GREEN = "rgb(0, 128, 0)";
function check(n, { extraMutation, flush = true } = {}) {
const trigger = document.getElementById("e" + n);
const target = document.getElementById("target" + n);
assert_not_equals(getComputedStyle(target).color, GREEN, "Not green initially");
target.getBoundingClientRect();
trigger.classList.add("trigger" + n);
if (extraMutation) {
extraMutation();
}
if (flush) {
target.getBoundingClientRect();
}
assert_equals(getComputedStyle(target).color, GREEN, "Green after invalidation");
}
// Wait for the document to settle, so that there are no unrelated pending style changes.
window.addEventListener("load", () => {
requestAnimationFrame(() => requestAnimationFrame(() => {
test(() => check(1), "Descendant of next sibling in a different slot");
test(() => check(2), "Next sibling in a different slot");
test(() => check(3), "Descendant of next sibling in a slot deeper in the shadow tree");
test(() => check(4), "Descendant of subsequent sibling, with an element in a third slot in between");
test(() => check(5), "Descendant of next sibling in a different slot, via :has()");
test(() => check(6), "Next sibling in a different slot, via :has()");
test(() => check(7, { extraMutation: () => {
document.getElementById("unrelated").style.backgroundColor = "blue";
}}), "Descendant of next sibling in a different slot, with other pending style changes outside the host");
test(() => check(8, { extraMutation: () => {
document.getElementById("other8").className = "changed";
}}), "Descendant of next sibling in a different slot, with other pending style changes in the same slot");
test(() => {
const target = document.getElementById("target9");
assert_equals(getComputedStyle(target).color, GREEN, "Green initially");
document.getElementById("e9").classList.remove("x9");
document.body.offsetTop;
assert_not_equals(getComputedStyle(target).color, GREEN, "Not green after invalidation");
}, "Next sibling in the same slot, via :has(), removing the :has() subject");
test(() => check(10), "Next sibling in the same slot, via :has() with a sibling in a different slot");
test(() => check(11, { flush: false }), "Next sibling in a different slot, without a layout flush");
test(() => check(12, { extraMutation: () => {
document.getElementById("other12").className = "changed";
}}), "Descendant of next sibling in a different slot, through nested slots, with other pending style changes in the same slot");
test(() => check(13, { extraMutation: () => {
document.getElementById("host13").shadowRoot.getElementById("wrapper13").className = "changed";
}}), "Descendant of next sibling in a different slot, with other pending style changes in the shadow tree");
done();
}));
});
</script>