commit 2e6efd4b859845423c41471ea2745901ae23adec
parent c2978100634eaa606806aaab09dabb8590a5c138
Author: Stefan Zager <szager@chromium.org>
Date: Tue, 21 Oct 2025 10:36:18 +0000
Bug 1994506 [wpt PR 55459] - Do not synchronously generate IntersectionObserver notifications, a=testonly
Automatic update from web-platform-tests
Do not synchronously generate IntersectionObserver notifications
Prior to this CL, we would synchronously generate a not-intersecting
notification when a target element was removed from the DOM. That
doesn't match the spec -- there is no affordance for generating
notifications outside of the "update the rendering" steps.
This CL removes all the synchronous forced computation of intersections.
It makes IntersectionObserverController continue tracking disconnected
targets until they have a chance to issue a "not-intersecting"
notification during a rendering update.
Bug: chromium:40914013
Change-Id: I332dc4e95dc9cffbe7d05ec63eb3cd6122c431a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7038511
Reviewed-by: Philip Rogers <pdr@chromium.org>
Commit-Queue: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1531750}
--
wpt-commits: ca587879e05348d19e15627d9d5b6a2be0b5caf2
wpt-pr: 55459
Diffstat:
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/testing/web-platform/tests/intersection-observer/reinsert-element.html b/testing/web-platform/tests/intersection-observer/reinsert-element.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<meta name="viewport" content="width=device-width,initial-scale=1">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/intersection-observer-test-utils.js"></script>
+
+<style>
+pre, #log {
+ position: absolute;
+ top: 0;
+ left: 200px;
+}
+</style>
+
+<div id="target">Hello, world!</div>
+
+<script>
+promise_test(async function(t) {
+ let entries = [];
+ let target = document.getElementById("target");
+ let observer = new IntersectionObserver(function(changes) {
+ entries = entries.concat(changes);
+ });
+ observer.observe(target);
+ await waitForNotification();
+ assert_equals(entries.length, 1);
+ assert_true(entries[0].isIntersecting);
+ target.remove();
+ document.body.appendChild(target);
+ await waitForNotification();
+ assert_equals(entries.length, 1);
+ assert_true(entries[0].isIntersecting);
+}, "An element that is removed and reinserted without an intervening" +
+ " rendering update doesn't generate a 'not-intersecting' notification.");
+</script>
diff --git a/testing/web-platform/tests/intersection-observer/target-in-detached-document.html b/testing/web-platform/tests/intersection-observer/target-in-detached-document.html
@@ -38,11 +38,11 @@ runTestCycle(function() {
function step0() {
document.adoptNode(target);
document.body.appendChild(target);
- checkLastEntry(entries, 0, [0, 0, 0, 0, 0, 0, 0, 0]);
+ assert_equals(entries.length, 0, "No initial notification while in detached document.");
runTestCycle(step1, "Adopt target.");
}
function step1() {
- checkLastEntry(entries, 1, [8, 108, 8, 108, 8, 108, 8, 108, 0, vw, 0, vh, true]);
+ checkLastEntry(entries, 0, [8, 108, 8, 108, 8, 108, 8, 108, 0, vw, 0, vh, true]);
}
</script>