Files
ladybird/Tests/LibWeb/Text/input/css/shadow-root-keyframes-shadow-local-invalidation-counters.html
Andreas Kling 928a5247ff LibWeb: Narrow stylesheet add/remove invalidation
Avoid broad document invalidation when adding or removing ordinary
document-owned or shadow-owned stylesheets. Reuse the targeted
StyleSheetInvalidation path for style rules, including shadow-host
escapes, pseudo-element-only selectors, and trailing-universal cases.

Keep the broad path for sheet contents whose effects are not captured
by selector invalidation alone, including @property, @font-face,
@font-feature-values, @keyframes, imported sheets, and top-level @layer
blocks. Broad-path shadow-root sheets still reach host-side consumers
through their active-scope effects.
2026-04-23 16:45:22 +02:00

59 lines
2.0 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<div id="host"></div>
<div id="bystanders"></div>
<script>
function settleAndReset(triggerElement) {
getComputedStyle(triggerElement).opacity;
getComputedStyle(triggerElement).opacity;
internals.resetStyleInvalidationCounters();
}
function verifyInvalidationsStayBounded(label, maxInvalidations) {
const invalidations = internals.getStyleInvalidationCounters().styleInvalidations;
if (invalidations <= maxInvalidations)
println(`PASS: ${label} (${invalidations} invalidations)`);
else
println(`FAIL: ${label} (${invalidations} invalidations)`);
}
test(() => {
const host = document.getElementById("host");
const bystanders = document.getElementById("bystanders");
for (let i = 0; i < 25; ++i) {
const bystander = document.createElement("div");
bystander.textContent = `bystander ${i}`;
bystander.style.animationName = "fade";
bystander.style.animationDuration = "1s";
bystander.style.animationFillMode = "both";
bystanders.appendChild(bystander);
}
const shadowRoot = host.attachShadow({ mode: "open" });
shadowRoot.innerHTML = `
<style>
#target {
animation-name: fade;
animation-duration: 1s;
animation-fill-mode: both;
}
</style>
<div id="target">shadow target</div>
`;
const target = shadowRoot.getElementById("target");
const sheet = shadowRoot.querySelector("style").sheet;
settleAndReset(target);
sheet.insertRule(`
@keyframes fade {
from { opacity: 0.25; }
to { opacity: 0.25; }
}
`, sheet.cssRules.length);
getComputedStyle(target).opacity;
verifyInvalidationsStayBounded("shadow-local keyframes insert ignores matching light-DOM bystanders", 4);
});
</script>