diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/first-child-last-child.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/first-child-last-child.txt index 460dd55d356..bbb983c1821 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/first-child-last-child.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/first-child-last-child.txt @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-001.txt index 57c3bdc6074..8e1d335c1f2 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-001.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-001.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail Remove/Insert earlier sibling \ No newline at end of file +Result Test Name MessagePass Remove/Insert earlier sibling \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-002.txt index 0aeaeae5087..f19041f0a4e 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-002.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-002.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail Remove/Insert adjacent sibling of parent \ No newline at end of file +Result Test Name MessagePass Remove/Insert adjacent sibling of parent \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-003.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-003.txt index d635cfcc684..0d0c1611532 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-003.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-003.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail Remove/Insert earlier sibling of ancestor \ No newline at end of file +Result Test Name MessagePass Remove/Insert earlier sibling of ancestor \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-004.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-004.txt index 1be88bb0b20..ad2e5b7a151 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-004.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/invalidation/insert-sibling-004.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail Remove/Insert earlier sibling of parent \ No newline at end of file +Result Test Name MessagePass Remove/Insert earlier sibling of parent \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 0d50c148209..526365bcac0 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -748,9 +748,6 @@ WebIDL::ExceptionOr> 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 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(); }