Skip to content

Truly independent web browser

LibWeb: Plan a list again in full where its last child was restyled

Andreas Kling099ec31b957f
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder/list_unit.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder/list_unit.rs
index c08d9fb6678..6fabd87533c 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_builder/list_unit.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder/list_unit.rs
@@ -671,7 +671,9 @@ fn append_window(
if anchor.text_index().is_some() && arena.text_has_source_range(row) {
return None;
}
- if marks.needs(anchor) && marks.reuse_reasons(anchor) & !layout_tree_update_reuse_reason::RESTYLE == 0 {
+ // NB: The walk keeps the box of the child the window starts at. A restyle may give that child a new box,
+ // whatever else it was marked for.
+ if marks.may_build_box_again(anchor) {
return None;
}
// NB: An in-flow box tells the walk what the boxes of the list before it are: inline ones where it is inline,
@@ -684,14 +686,11 @@ fn append_window(
// whatever else its list was marked for, and every node whose boxes left the list for another one, such as
// the viewport's for the top layer, whichever list answered its mark.
let earlier_child_changed = marked_children.iter().any(|&child| {
- let reasons = marks.reuse_reasons(child);
child != anchor
&& !in_window.contains(&child)
&& (arena.layout_parent_with_box(child) != Some(element)
- || (marks.needs(child)
- && (reasons == 0
- || reasons & layout_tree_update_reuse_reason::RESTYLE != 0
- || arena.bound_row(child).is_invalid())))
+ || marks.may_build_box_again(child)
+ || (marks.needs(child) && arena.bound_row(child).is_invalid()))
});
(!earlier_child_changed).then_some(ListWindow {
start: Some(anchor),
@@ -1008,11 +1007,7 @@ fn first_entry_after_changed_generated_content(
};
// NB: The box built again, or restyled and not kept, does to what follows what the old one did, unless the
// style changed it.
- let reasons = marks.reuse_reasons(child);
- if !arena.bound_row(child).is_invalid()
- && marks.needs(child)
- && (reasons == 0 || reasons & layout_tree_update_reuse_reason::RESTYLE != 0)
- {
+ if !arena.bound_row(child).is_invalid() && marks.may_build_box_again(child) {
if marks.generated_content_changed(child)
|| (marks.list_item_changed(child)
&& (resets_reversed_counter() || kept_entries_show_counter_values(entry)))
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs
index 132fa282b53..953c77eefbf 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs
@@ -107,6 +107,13 @@ impl LayoutTreeUpdateMarks {
self.get(node) & layout_tree_update_reuse_reason::ALL
}
+ /// Whether the build builds the box of this node again, or may: where only a full rebuild will do, or where a
+ /// restyle may give the node a box of another kind, whatever else it was marked for.
+ pub(crate) fn may_build_box_again(&self, node: StyleNodeID) -> bool {
+ let reasons = self.reuse_reasons(node);
+ self.needs(node) && (reasons == 0 || reasons & layout_tree_update_reuse_reason::RESTYLE != 0)
+ }
+
/// Whether a style change of the element changed what its box does to the counters or the quote depth after it.
pub(crate) fn generated_content_changed(&self, node: StyleNodeID) -> bool {
self.get(node) & GENERATED_CONTENT_CHANGED != 0
diff --git a/Tests/LibWeb/Crash/Layout/append-after-last-child-whose-restyle-builds-its-box-again.html b/Tests/LibWeb/Crash/Layout/append-after-last-child-whose-restyle-builds-its-box-again.html
new file mode 100644
index 00000000000..faad59c74f8
--- /dev/null
+++ b/Tests/LibWeb/Crash/Layout/append-after-last-child-whose-restyle-builds-its-box-again.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<div id="list"><div id="last"></div></div>
+<script>
+ document.body.offsetWidth;
+ last.appendChild(document.createElement("span"));
+ last.style.display = "flex";
+ list.appendChild(document.createElement("div"));
+ document.body.offsetWidth;
+</script>