Define the implicit root better in presence of adoption to a different browsing-context tree.
emilio opened this issue · 3 comments
https://w3c.github.io/IntersectionObserver/#intersectionobserver-intersection-root says that the implicit root is the document node of the "top-level browsing context".
That makes sense, but if you're observing a node and adopt it into a new window, there are two potential candidates:
- The browsing context in which the intersection observer was created.
- The browsing context in which the target lives.
Both of those can have different viewports, as https://bugzilla.mozilla.org/attachment.cgi?id=9180905 shows. Which one should be chosen? If we choose the first, the target will presumably never intersect. If we choose the second, then we report intersections against the newly-opened window.
I think both of them would be reasonable. Gecko does something non-sensical in this case. WebKit seems to do the first, and Blink seems to do the second:
- https://webkit-search.igalia.com/webkit/rev/0cf28a346a4ad67f08eb1150c17fdb48ef6b29c7/Source/WebCore/dom/Document.cpp#7643-7645,7719
- https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/intersection_observer/intersection_geometry.cc;l=123;drc=5305c09e4169c2aa9f2c92cb8aace4a6ce232fc5;bpv=1;bpt=1
We should decide what is the right thing to do here and clarify the spec.
The comment in the WebKit code suggests that they intend to match chromium's behavior, which would be fine with me.
I think a case could be made for either behavior; but if I put myself in the shoes of the developer, I could imagine being surprised at not receiving an "intersecting" notification when I insert a target element into another window.
I think a case could be made for either behavior; but if I put myself in the shoes of the developer, I could imagine being surprised at not receiving an "intersecting" notification when I insert a target element into another window.
Yeah, on the other hand it seems weird/sketchy that only for the implicit case one IntersectionObserver can refer to multiple roots, depending on the observation target...
For now I aligned with Gecko with WebKit in https://bugzilla.mozilla.org/show_bug.cgi?id=1670327, because it was more on the lines of what the Gecko code was trying to do before that patch.