From 3e1d718b7ff646d7d3dc1bbbee6af0fb511e4f76 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sun, 13 Apr 2025 21:36:00 +0200 Subject: [PATCH] LibWeb: Ignore boxes without layout node in intersection observer steps Check if box has associated layout node is not mentioned in the spec, but it is required to match behavior of other browsers that do not invoke intersection observer steps for boxes without layout node. --- Libraries/LibWeb/DOM/Document.cpp | 4 ++-- ...thout-layout-node-should-not-intersect.txt | 2 ++ ...hout-layout-node-should-not-intersect.html | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/IntersectionObserver/box-without-layout-node-should-not-intersect.txt create mode 100644 Tests/LibWeb/Text/input/IntersectionObserver/box-without-layout-node-should-not-intersect.html diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 64ff0637b70..0e8e5d7ac95 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -4663,8 +4663,8 @@ void Document::run_the_update_intersection_observations_steps(HighResolutionTime auto intersection_root_document = intersection_root.visit([](auto& node) -> GC::Ref { return node->document(); }); - if (!(observer->root().has() && &target->document() == intersection_root_document.ptr()) - || !(intersection_root.has>() && !target->is_descendant_of(*intersection_root.get>()))) { + // NOTE: Check if target has a layout node is not in the spec but required to match other browsers. + if (target->layout_node() && (!(observer->root().has() && &target->document() == intersection_root_document.ptr()) || !(intersection_root.has>() && !target->is_descendant_of(*intersection_root.get>())))) { // 4. Set targetRect to the DOMRectReadOnly obtained by getting the bounding box for target. target_rect = target->get_bounding_client_rect(); diff --git a/Tests/LibWeb/Text/expected/IntersectionObserver/box-without-layout-node-should-not-intersect.txt b/Tests/LibWeb/Text/expected/IntersectionObserver/box-without-layout-node-should-not-intersect.txt new file mode 100644 index 00000000000..263bc73a056 --- /dev/null +++ b/Tests/LibWeb/Text/expected/IntersectionObserver/box-without-layout-node-should-not-intersect.txt @@ -0,0 +1,2 @@ +flip #container to visible +#nested is visible diff --git a/Tests/LibWeb/Text/input/IntersectionObserver/box-without-layout-node-should-not-intersect.html b/Tests/LibWeb/Text/input/IntersectionObserver/box-without-layout-node-should-not-intersect.html new file mode 100644 index 00000000000..ee9d07c239c --- /dev/null +++ b/Tests/LibWeb/Text/input/IntersectionObserver/box-without-layout-node-should-not-intersect.html @@ -0,0 +1,24 @@ + + + + \ No newline at end of file