Files
ladybird/Tests/LibWeb/Text/input/css/shadow-root-stylesheet-add-remove-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

46 lines
1.9 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<div id="host"></div>
<script>
function settleAndReset(triggerElement) {
getComputedStyle(triggerElement).color;
getComputedStyle(triggerElement).color;
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");
for (let i = 0; i < 25; ++i) {
const lightDomBystander = document.createElement("span");
lightDomBystander.className = "shadow-target-class";
lightDomBystander.textContent = `light bystander ${i}`;
host.appendChild(lightDomBystander);
}
const shadowRoot = host.attachShadow({ mode: "open" });
shadowRoot.innerHTML = `<div id="shadow-target" class="shadow-target-class">shadow target</div>`;
const shadowTarget = shadowRoot.getElementById("shadow-target");
const shadowStyle = document.createElement("style");
shadowStyle.textContent = ".shadow-target-class { color: rgb(0, 128, 0); }";
settleAndReset(shadowTarget);
shadowRoot.appendChild(shadowStyle);
getComputedStyle(shadowTarget).color;
verifyInvalidationsStayBounded("shadow-local stylesheet add ignores matching light-DOM bystanders", 4);
settleAndReset(shadowTarget);
shadowStyle.remove();
getComputedStyle(shadowTarget).color;
verifyInvalidationsStayBounded("shadow-local stylesheet remove ignores matching light-DOM bystanders", 4);
});
</script>