Skip to content

Truly independent web browser

LibWeb: Note the sibling reads of the walk invalidation takes leftwards

Andreas Kling4476f5c041b2
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
index e7b9c33976b..5dbdf8bd787 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
@@ -14,6 +14,7 @@ use super::super::input_types::{
STYLE_REACTION_FONT_INPUTS_CHANGED, STYLE_REACTION_PUBLISHED_STYLE, STYLE_REACTION_RECOMPUTE_DESCENDANT_STYLES,
StyleEnvironment, StyleUpdate, TreeRelations,
};
+use super::super::selector_evaluation::StructuralRead;
use super::super::transaction_view::TransactionFactSide;
use super::super::*;
use super::drive::DriveRecords;
@@ -3676,6 +3677,15 @@ impl<'a> Follower<'a> {
true => projection.previous_element_sibling_on(TransactionFactSide::Before, node),
false => projection.previous_element_sibling(node),
};
+ // NB: An element this answers does not match for may never be matched across its siblings, which is what has its
+ // parent's later changes look at them.
+ let note_read = |read| {
+ let side = match before {
+ true => TransactionFactSide::Before,
+ false => TransactionFactSide::After,
+ };
+ projection.note_structural_read(side, element, read);
+ };
// Whether any of the candidates matches, or might.
let any = |follower: &mut Self, candidates: &mut dyn Iterator<Item = StyleNodeID>| {
let mut answer = Some(false);
@@ -3690,12 +3700,18 @@ impl<'a> Follower<'a> {
};
match combinator {
ReachCombinator::Child => any(self, &mut parent(element).into_iter()),
- ReachCombinator::NextSibling => any(self, &mut previous_sibling(element).into_iter()),
+ ReachCombinator::NextSibling => {
+ note_read(StructuralRead::PreviousSibling);
+ any(self, &mut previous_sibling(element).into_iter())
+ }
ReachCombinator::Descendant => any(self, &mut std::iter::successors(parent(element), |&node| parent(node))),
- ReachCombinator::LaterSibling => any(
- self,
- &mut std::iter::successors(previous_sibling(element), |&node| previous_sibling(node)),
- ),
+ ReachCombinator::LaterSibling => {
+ note_read(StructuralRead::EarlierSiblings);
+ any(
+ self,
+ &mut std::iter::successors(previous_sibling(element), |&node| previous_sibling(node)),
+ )
+ }
// NB: An element that left stood below the host it had.
ReachCombinator::ShadowChild => any(
self,
diff --git a/Tests/LibWeb/Text/expected/css/sibling-arrives-before-element-that-matched-nothing-across-siblings.txt b/Tests/LibWeb/Text/expected/css/sibling-arrives-before-element-that-matched-nothing-across-siblings.txt
new file mode 100644
index 00000000000..fefe3dfb603
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/sibling-arrives-before-element-that-matched-nothing-across-siblings.txt
@@ -0,0 +1,12 @@
+later, alone: 0px
+later, with a sibling before it: 2px
+later, alone again: 0px
+next, alone: 0px
+next, with a sibling before it: 2px
+next, alone again: 0px
+named-later, alone: 0px
+named-later, with a sibling before it: 2px
+named-later, alone again: 0px
+named-next, alone: 0px
+named-next, with a sibling before it: 2px
+named-next, alone again: 0px
diff --git a/Tests/LibWeb/Text/input/css/sibling-arrives-before-element-that-matched-nothing-across-siblings.html b/Tests/LibWeb/Text/input/css/sibling-arrives-before-element-that-matched-nothing-across-siblings.html
new file mode 100644
index 00000000000..17b1d9ad327
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/sibling-arrives-before-element-that-matched-nothing-across-siblings.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<style>
+ :first-child ~ .later { margin-left: 2px; }
+ :first-child + .next { margin-left: 2px; }
+ .first ~ .named-later { margin-left: 2px; }
+ .first + .named-next { margin-left: 2px; }
+</style>
+<script src="../include.js"></script>
+<script>
+ // An element that takes a class with no sibling before it matches nothing, which leaves no selector to read its
+ // siblings. A sibling arriving before it still reaches it.
+ asyncTest(async done => {
+ const frame = () => new Promise(resolve => requestAnimationFrame(resolve));
+ for (const className of ["later", "next", "named-later", "named-next"]) {
+ const parent = document.createElement("div");
+ const target = document.createElement("div");
+ parent.append(target);
+ document.body.append(parent);
+ await frame();
+ target.classList.add(className);
+ println(`${className}, alone: ${getComputedStyle(target).marginLeft}`);
+ await frame();
+ const sibling = document.createElement("div");
+ sibling.className = "first";
+ parent.prepend(sibling);
+ println(`${className}, with a sibling before it: ${getComputedStyle(target).marginLeft}`);
+ await frame();
+ sibling.remove();
+ println(`${className}, alone again: ${getComputedStyle(target).marginLeft}`);
+ }
+ done();
+ });
+</script>