ladybird/Tests/LibWeb/Text/input/css/pseudo-style-invalidation-after-node-removal.html
Jelle Raaijmakers c56f7d9cde LibWeb: Invalidate sibling style for :only-child and :*-of-type
After f7a3f785a8, sibling nodes' styles
were no longer invalidated after a node was removed. This reuses the
flag for `:first-child` and `:last-child` to indicate that a node's
style might be affected by any structural change in its siblings.

Fixes #4631.

Resolves the `:only-child` ACID3 failure as documented in #1231.
2025-05-07 14:55:12 +03:00

30 lines
938 B
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<style>
div#a p:only-child {
background-color: green;
}
div#b p:first-of-type {
background-color: green;
}
div#c p:last-of-type {
background-color: green;
}
</style>
<div id="a"><p>foo</p><p>bar</p></div>
<div id="b"><p>foo</p><p>bar</p></div>
<div id="c"><p>foo</p><p>bar</p></div>
<script>
test(() => {
document.body.offsetWidth; // force layout
document.querySelector('div#a p:last-child').remove();
println(`div#a p: ${getComputedStyle(document.querySelector('div#a p')).backgroundColor}`);
document.querySelector('div#b p:first-child').remove();
println(`div#b p: ${getComputedStyle(document.querySelector('div#b p')).backgroundColor}`);
document.querySelector('div#c p:last-child').remove();
println(`div#c p: ${getComputedStyle(document.querySelector('div#c p')).backgroundColor}`);
});
</script>