Skip to content

Truly independent web browser

LibWeb: Keep a style pass's answers across inputs that move nothing

Andreas Kling4712d3ef0b1d
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
index 67a9940279c..4b228d393c4 100644
--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
@@ -1103,20 +1103,28 @@ impl StyleEngine {
node_is_arriving(node),
);
}
- self.settle_batched_inputs();
+ // NB: Settling discards the answers a style pass the host is installing published for its rows still to come,
+ // so a batch that records nothing, such as the states the host publishes as it installs a row whose states
+ // stand, settles nothing.
+ if !tree_deltas.is_empty() || !local_feature_deltas.is_empty() {
+ self.settle_batched_inputs();
+ }
+ let mut states_moved = false;
for delta in state_deltas {
let Some(node) = StyleNodeID::from_raw(delta.node) else {
continue;
};
- self.record_batched_state(
+ states_moved |= self.record_batched_state(
node,
decode_state_fact(delta.fact),
delta.new_value,
node_is_arriving(node),
);
}
- self.settle_batched_inputs();
+ if states_moved {
+ self.settle_batched_inputs();
+ }
for delta in element_declaration_deltas {
let Some(node) = StyleNodeID::from_raw(delta.node) else {
diff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
index 610816db7b1..f253650e30d 100644
--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
@@ -3170,21 +3170,26 @@ impl StyleEngine {
///
/// State invalidators may conservatively republish a related group of pseudo-classes when one
/// member changes. The settled fact is therefore the old side; assuming every publication is
- /// a Boolean toggle would invent transitions for the unchanged members of that group.
+ /// a Boolean toggle would invent transitions for the unchanged members of that group. Such a
+ /// member is no input at all, and the answer says whether the state moved.
pub(crate) fn record_batched_state(
&mut self,
node: StyleNodeID,
fact: StateFact,
new_value: bool,
arriving_node: bool,
- ) {
+ ) -> bool {
let old_value = self.retained.facts.states_of_node(node).contains(fact);
+ if old_value == new_value && !arriving_node {
+ return false;
+ }
self.record_batched_input(
InputKey::State(node, fact),
InputValue::State(old_value),
InputValue::State(new_value),
arriving_node,
);
+ true
}
/// Install the fixed facts carried by one element arrival. The tree row already routes the
diff --git a/Libraries/LibWeb/Rust/src/css/style/tests.rs b/Libraries/LibWeb/Rust/src/css/style/tests.rs
index 3656308656e..434b97f1127 100644
--- a/Libraries/LibWeb/Rust/src/css/style/tests.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/tests.rs
@@ -7840,6 +7840,20 @@ fn cold_answer_verification_uses_committed_facts_with_pending_inputs() {
assert_eq!(engine.exact_match_answer_for_verification(nodes[1]).unwrap().len(), 1);
}
+#[test]
+fn a_batched_state_that_moves_nothing_is_no_input() {
+ let (mut engine, nodes) = linear_document();
+ discard_transaction(&mut engine);
+
+ assert!(!engine.record_batched_state(nodes[1], StateFact::PlaceholderShown, false, false));
+ assert!(!engine.facts.has_dirty_staging());
+ assert!(engine.host.journal.is_empty());
+
+ assert!(engine.record_batched_state(nodes[1], StateFact::PlaceholderShown, true, false));
+ assert!(engine.facts.has_dirty_staging());
+ assert!(!engine.host.journal.is_empty());
+}
+
#[test]
fn state_input_commits_after_its_old_row_is_snapshotted() {
let (mut engine, nodes) = linear_document();