mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-30 14:20:21 +00:00
LibWeb: Style invalidation for DOM node removal needs to happen earlier
We can't invalidate after the removal has taken effect, since that means invalidation won't be able to find potentially affected siblings and ancestors by traversing from the invalidation target.
This commit is contained in:
parent
adfc69bc67
commit
1045000c28
Notes:
github-actions[bot]
2024-11-06 20:44:01 +00:00
Author: https://github.com/awesomekling
Commit: 1045000c28
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2204
6 changed files with 23 additions and 27 deletions
|
@ -6,7 +6,7 @@ Rerun
|
|||
|
||||
Found 2 tests
|
||||
|
||||
2 Fail
|
||||
2 Pass
|
||||
Details
|
||||
Result Test Name MessageFail Adding multiple nodes at once should invalidate :first-child correctly.
|
||||
Fail Adding multiple nodes at once should invalidate :last-child correctly.
|
||||
Result Test Name MessagePass Adding multiple nodes at once should invalidate :first-child correctly.
|
||||
Pass Adding multiple nodes at once should invalidate :last-child correctly.
|
|
@ -6,6 +6,6 @@ Rerun
|
|||
|
||||
Found 1 tests
|
||||
|
||||
1 Fail
|
||||
1 Pass
|
||||
Details
|
||||
Result Test Name MessageFail Remove/Insert earlier sibling
|
||||
Result Test Name MessagePass Remove/Insert earlier sibling
|
|
@ -6,6 +6,6 @@ Rerun
|
|||
|
||||
Found 1 tests
|
||||
|
||||
1 Fail
|
||||
1 Pass
|
||||
Details
|
||||
Result Test Name MessageFail Remove/Insert adjacent sibling of parent
|
||||
Result Test Name MessagePass Remove/Insert adjacent sibling of parent
|
|
@ -6,6 +6,6 @@ Rerun
|
|||
|
||||
Found 1 tests
|
||||
|
||||
1 Fail
|
||||
1 Pass
|
||||
Details
|
||||
Result Test Name MessageFail Remove/Insert earlier sibling of ancestor
|
||||
Result Test Name MessagePass Remove/Insert earlier sibling of ancestor
|
|
@ -6,6 +6,6 @@ Rerun
|
|||
|
||||
Found 1 tests
|
||||
|
||||
1 Fail
|
||||
1 Pass
|
||||
Details
|
||||
Result Test Name MessageFail Remove/Insert earlier sibling of parent
|
||||
Result Test Name MessagePass Remove/Insert earlier sibling of parent
|
|
@ -748,9 +748,6 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::append_child(JS::NonnullGCPtr<
|
|||
// https://dom.spec.whatwg.org/#concept-node-remove
|
||||
void Node::remove(bool suppress_observers)
|
||||
{
|
||||
bool was_connected = is_connected();
|
||||
bool had_layout_node = layout_node();
|
||||
|
||||
// 1. Let parent be node’s parent
|
||||
auto* parent = this->parent();
|
||||
|
||||
|
@ -795,6 +792,18 @@ void Node::remove(bool suppress_observers)
|
|||
// 10. Let oldNextSibling be node’s next sibling.
|
||||
JS::GCPtr<Node> old_next_sibling = next_sibling();
|
||||
|
||||
if (is_connected()) {
|
||||
// Since the tree structure is about to change, we need to invalidate both style and layout.
|
||||
// In the future, we should find a way to only invalidate the parts that actually need it.
|
||||
invalidate_style(StyleInvalidationReason::NodeRemove);
|
||||
|
||||
// NOTE: If we didn't have a layout node before, rebuilding the layout tree isn't gonna give us one
|
||||
// after we've been removed from the DOM.
|
||||
if (layout_node()) {
|
||||
document().invalidate_layout_tree();
|
||||
}
|
||||
}
|
||||
|
||||
// 11. Remove node from its parent’s children.
|
||||
parent->remove_child_impl(*this);
|
||||
|
||||
|
@ -887,19 +896,6 @@ void Node::remove(bool suppress_observers)
|
|||
// 21. Run the children changed steps for parent.
|
||||
parent->children_changed();
|
||||
|
||||
if (was_connected) {
|
||||
// Since the tree structure has changed, we need to invalidate both style and layout.
|
||||
// In the future, we should find a way to only invalidate the parts that actually need it.
|
||||
|
||||
invalidate_style(StyleInvalidationReason::NodeRemove);
|
||||
|
||||
// NOTE: If we didn't have a layout node before, rebuilding the layout tree isn't gonna give us one
|
||||
// after we've been removed from the DOM.
|
||||
if (had_layout_node) {
|
||||
document().invalidate_layout_tree();
|
||||
}
|
||||
}
|
||||
|
||||
document().bump_dom_tree_version();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue