LibWeb: Invalidate layout tree at nearest non-anonymous ancestor

When marking a part of the layout tree for rebuild, if the subtree root
that we're marking has an anonymous parent, we now mark from the nearest
non-anonymous ancestor instead.

This ensures that subtrees inside anonymous wrappers don't just get
duplicated (i.e recreated but inserted instead of replaced).
This commit is contained in:
Andreas Kling 2025-06-03 16:56:15 +02:00 committed by Andreas Kling
parent 93cd17db74
commit 6dba720370
Notes: github-actions[bot] 2025-06-03 22:44:28 +00:00
3 changed files with 52 additions and 1 deletions

View file

@ -1634,8 +1634,19 @@ void Node::set_needs_layout_tree_update(bool value, SetNeedsLayoutTreeUpdateReas
break;
ancestor->m_child_needs_layout_tree_update = true;
}
if (auto layout_node = this->layout_node())
if (auto layout_node = this->layout_node()) {
layout_node->set_needs_layout_update(SetNeedsLayoutReason::LayoutTreeUpdate);
// If the layout node has an anonymous parent, rebuild from the nearest non-anonymous ancestor.
// FIXME: This is not optimal, and we should figure out how to rebuild a smaller part of the tree.
if (layout_node->parent() && layout_node->parent()->is_anonymous()) {
GC::Ptr<Layout::Node> ancestor = layout_node->parent();
while (ancestor && ancestor->is_anonymous())
ancestor = ancestor->parent();
if (ancestor)
ancestor->dom_node()->set_needs_layout_tree_update(true, reason);
}
}
}
}