From fe04d83ef50319f7c7521fc45f83ed9de3571374 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 24 Dec 2023 12:32:25 +0100 Subject: [PATCH] LibWeb: Process all pending lazy loading intersection observations This fixes an issue where images outside the viewport could prevent loading of images inside the viewport, depending on DOM order. --- ...ng-not-blocked-by-img-outside-viewport.txt | 1 + ...g-not-blocked-by-img-outside-viewport.html | 19 +++++++++++++++++++ Userland/Libraries/LibWeb/DOM/Document.cpp | 8 ++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/IntersectionObserver/img-lazy-loading-not-blocked-by-img-outside-viewport.txt create mode 100644 Tests/LibWeb/Text/input/IntersectionObserver/img-lazy-loading-not-blocked-by-img-outside-viewport.html diff --git a/Tests/LibWeb/Text/expected/IntersectionObserver/img-lazy-loading-not-blocked-by-img-outside-viewport.txt b/Tests/LibWeb/Text/expected/IntersectionObserver/img-lazy-loading-not-blocked-by-img-outside-viewport.txt new file mode 100644 index 0000000000..465701e346 --- /dev/null +++ b/Tests/LibWeb/Text/expected/IntersectionObserver/img-lazy-loading-not-blocked-by-img-outside-viewport.txt @@ -0,0 +1 @@ +PASS \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/IntersectionObserver/img-lazy-loading-not-blocked-by-img-outside-viewport.html b/Tests/LibWeb/Text/input/IntersectionObserver/img-lazy-loading-not-blocked-by-img-outside-viewport.html new file mode 100644 index 0000000000..14cd7843a9 --- /dev/null +++ b/Tests/LibWeb/Text/input/IntersectionObserver/img-lazy-loading-not-blocked-by-img-outside-viewport.html @@ -0,0 +1,19 @@ + + diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 9a9095f6db..1fe096f6f0 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -3357,8 +3357,12 @@ void Document::start_intersection_observing_a_lazy_loading_element(Element& elem } // 3. If resumptionSteps is null, then return. - if (!resumption_steps) - return JS::js_undefined(); + if (!resumption_steps) { + // NOTE: This is wrong in the spec, since we want to keep processing + // entries even if one of them doesn't have resumption steps. + // FIXME: Spec bug: https://github.com/whatwg/html/issues/10019 + continue; + } // 4. Stop intersection-observing a lazy loading element for entry.target. // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#stop-intersection-observing-a-lazy-loading-element