Skip to content

IntersectionObserver should not notify targets in detached documents#65550

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
Ahmad-S792:eng/IntersectionObserver-should-not-notify-targets-in-detached-documents
May 25, 2026
Merged

IntersectionObserver should not notify targets in detached documents#65550
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
Ahmad-S792:eng/IntersectionObserver-should-not-notify-targets-in-detached-documents

Conversation

@Ahmad-S792
Copy link
Copy Markdown
Contributor

@Ahmad-S792 Ahmad-S792 commented May 24, 2026

b49b5a0

IntersectionObserver should not notify targets in detached documents
https://bugs.webkit.org/show_bug.cgi?id=300729
rdar://162699098

Reviewed by Chris Dumez.

HTML's "update the rendering" steps build the docs list from "all
fully active Document objects" [1], so the intersection observer
update step (Step 19) [1] never runs for a detached document. A
target whose owning Document is not fully active therefore cannot
legitimately produce an intersection.

WebKit still queued an initial zero-rect, not-intersecting entry for
such targets, so target-in-detached-document.html saw one notification
before the target was adopted into a fully-active document where the
specification expect none.

Fix it by skipping such targets in updateObservations without
advancing previousThresholdIndex, so a later adoptNode is treated as
the first observation.

This skip is gated on implicit root observers, "Update the rendering"
[1] (Step 19) invoke "run the update intersection observations
steps" [2] which iterates "all IntersectionObservers whose root is
in the DOM tree of document … this includes implicit root
observers". The explicit-root [3] case is left alone and continues
to be tested by explicit-root-different-document.html.

Drop the skipped target from m_targetsWaitingForFirstObservation so a
permanently detached target/document can be collected
(i.e., intersection-observer/no-document-leak.html).

[1] https://html.spec.whatwg.org/#update-the-rendering
[2] https://w3c.github.io/IntersectionObserver/#run-the-update-intersection-observations-steps
[3] https://w3c.github.io/IntersectionObserver/#intersectionobserver-explicit-root-observer

* LayoutTests/imported/w3c/web-platform-tests/intersection-observer/target-in-detached-document-expected.txt: Progression
* Source/WebCore/page/IntersectionObserver.cpp:
(WebCore::IntersectionObserver::updateObservations):

Canonical link: https://commits.webkit.org/313834@main

c84a26e

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ✅ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ❌ 🧪 win-tests ✅ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 loading-orange 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 loading-orange 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim ✅ 🧪 mac-site-isolation
✅ 🛠 watch
✅ 🛠 watch-sim

@Ahmad-S792 Ahmad-S792 self-assigned this May 24, 2026
@Ahmad-S792 Ahmad-S792 added the Layout and Rendering For bugs with layout and rendering of Web pages. label May 24, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 24, 2026
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label May 24, 2026
@Ahmad-S792 Ahmad-S792 force-pushed the eng/IntersectionObserver-should-not-notify-targets-in-detached-documents branch from f800c2c to c84a26e Compare May 24, 2026 06:03
@Ahmad-S792 Ahmad-S792 marked this pull request as ready for review May 25, 2026 10:06
@Ahmad-S792 Ahmad-S792 requested a review from cdumez as a code owner May 25, 2026 10:06
@Ahmad-S792 Ahmad-S792 added the merge-queue Applied to send a pull request to merge-queue label May 25, 2026
https://bugs.webkit.org/show_bug.cgi?id=300729
rdar://162699098

Reviewed by Chris Dumez.

HTML's "update the rendering" steps build the docs list from "all
fully active Document objects" [1], so the intersection observer
update step (Step 19) [1] never runs for a detached document. A
target whose owning Document is not fully active therefore cannot
legitimately produce an intersection.

WebKit still queued an initial zero-rect, not-intersecting entry for
such targets, so target-in-detached-document.html saw one notification
before the target was adopted into a fully-active document where the
specification expect none.

Fix it by skipping such targets in updateObservations without
advancing previousThresholdIndex, so a later adoptNode is treated as
the first observation.

This skip is gated on implicit root observers, "Update the rendering"
[1] (Step 19) invoke "run the update intersection observations
steps" [2] which iterates "all IntersectionObservers whose root is
in the DOM tree of document … this includes implicit root
observers". The explicit-root [3] case is left alone and continues
to be tested by explicit-root-different-document.html.

Drop the skipped target from m_targetsWaitingForFirstObservation so a
permanently detached target/document can be collected
(i.e., intersection-observer/no-document-leak.html).

[1] https://html.spec.whatwg.org/#update-the-rendering
[2] https://w3c.github.io/IntersectionObserver/#run-the-update-intersection-observations-steps
[3] https://w3c.github.io/IntersectionObserver/#intersectionobserver-explicit-root-observer

* LayoutTests/imported/w3c/web-platform-tests/intersection-observer/target-in-detached-document-expected.txt: Progression
* Source/WebCore/page/IntersectionObserver.cpp:
(WebCore::IntersectionObserver::updateObservations):

Canonical link: https://commits.webkit.org/313834@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/IntersectionObserver-should-not-notify-targets-in-detached-documents branch from c84a26e to b49b5a0 Compare May 25, 2026 10:36
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 313834@main (b49b5a0): https://commits.webkit.org/313834@main

Reviewed commits have been landed. Closing PR #65550 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit b49b5a0 into WebKit:main May 25, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Layout and Rendering For bugs with layout and rendering of Web pages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants