mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 02:05:07 +02:00
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.
46 lines
1.9 KiB
HTML
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>
|