Files
ladybird/Tests/LibWeb/Text/input/css/insert-rule-shadow-root-slotted-invalidation.html
Andreas Kling 4e92765211 LibWeb: Narrow @keyframes insertRule() invalidation
Handle inline stylesheet @keyframes insertions without falling back to
broad owner invalidation. Recompute only elements whose computed
animation-name already references the inserted keyframes name.

Document-scoped insertions still walk the shadow-including tree so
existing shadow trees pick up inherited animations, and shadow-root
stylesheets fan out through the host root so :host combinators can
refresh host-side consumers as well. Also introduce the shared
ShadowRootStylesheetEffects analysis so later stylesheet mutation paths
can reuse the same per-scope escape classification.
2026-04-23 16:45:22 +02:00

41 lines
1.8 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<div id="host"><span id="slotted" class="item">slotted</span><span id="inherited">inherited</span></div>
<script>
asyncTest(async done => {
const host = document.getElementById("host");
const slotted = document.getElementById("slotted");
const inherited = document.getElementById("inherited");
const shadowRoot = host.attachShadow({ mode: "open" });
shadowRoot.innerHTML = `
<style id="shadow-style">
::slotted(.item) {
animation-name: inserted;
animation-duration: 1s;
animation-fill-mode: both;
}
</style>
<slot></slot>
`;
const styleSheet = shadowRoot.getElementById("shadow-style").sheet;
println(`slotted before rule: ${getComputedStyle(slotted).color}`);
shadowRoot.appendChild(document.createElement("b"));
styleSheet.insertRule("::slotted(.item) { color: rgb(0, 0, 255); }", styleSheet.cssRules.length);
println(`slotted after rule: ${getComputedStyle(slotted).color}`);
println(`inherited before slot rule: ${getComputedStyle(inherited).color}`);
styleSheet.insertRule("slot { border-color: rgb(0, 0, 0); color: rgb(255, 0, 0); }", styleSheet.cssRules.length);
println(`inherited after slot rule: ${getComputedStyle(inherited).color}`);
println(`opacity before keyframes: ${getComputedStyle(slotted).opacity}`);
shadowRoot.appendChild(document.createElement("i"));
styleSheet.insertRule("@keyframes inserted { from { opacity: 0.25; } to { opacity: 0.25; } }", styleSheet.cssRules.length);
await animationFrame();
println(`opacity after keyframes: ${getComputedStyle(slotted).opacity}`);
done();
});
</script>