ladybird/Tests/LibWeb/Text/input/css/getComputedStyle-pseudo-element.html
Andreas Kling 86e0e281a0 LibWeb: Avoid unnecessary pseudo-element style recomputation
Track the synthetic pseudo-elements that matched while computing an
originating element's normal style. Store the transient match set as a
bitfield, then copy those bits into ComputedProperties. Use them during
style invalidation to skip pseudo style recomputation when neither the
old nor new originating style matched pseudo rules and no pseudo style
already exists.

This shaves roughly 500 ms off loading the Ladybird GitHub repository.

Materialize synthetic pseudo styles on demand for CSSOM reads so
getComputedStyle(element, "::before") still computes skipped styles when
script asks for them. Add coverage for a universal pseudo selector, and
update style invalidation counter expectations for the reduced work.
2026-06-18 19:50:34 +02:00

40 lines
1.2 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<style>
#foo {
color: grey;
background-color: yellow;
}
#foo::before {
content: "hi";
background-color: cyan;
}
::after {
content: "bye";
color: green;
}
</style>
<div id="foo"></div>
<script>
test(() => {
const foo = document.getElementById("foo");
const style = getComputedStyle(foo);
const beforeStyle = getComputedStyle(foo, "::before");
const afterStyle = getComputedStyle(foo, "::after");
const propertyValues = [
"color",
"background-color",
];
println("#foo:");
for (const property of propertyValues) {
println(` ${property}: ${style.getPropertyValue(property)}`);
}
println("#foo::before:");
for (const property of propertyValues) {
println(` ${property}: ${beforeStyle.getPropertyValue(property)}`);
}
println("#foo::after:");
println(` content: ${afterStyle.getPropertyValue("content")}`);
println(` color: ${afterStyle.getPropertyValue("color")}`);
});
</script>