| Summary: | IntersectionObserver intersectionRatio < 1 observed | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ahmad Saleem <ahmad.saleem792> |
| Component: | Layout and Rendering | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | ap, bfulgham, karlcow, rniwa, simon.fraser, vitor.roriz, webkit-bug-importer, zalan |
| Priority: | P2 | Keywords: | BrowserCompat, GoodFirstBug, InRadar |
| Version: | Safari 15 | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
|
Description
Ahmad Saleem
2022-08-04 18:08:20 PDT
This seems to happen when the element being observed has a fractional width. (lldb) fr va intersectionState
(WebCore::IntersectionObservationState) intersectionState = {
absoluteTargetRect = { x = 222.59375, y = 0.0, width = 958.4375, height = 167.8125 }
absoluteRootBounds = { x = 0.0, y = 0.0, width = 1389.0, height = 898.0 }
absoluteIntersectionRect = { x = 223.0, y = 0.0, width = 958.0, height = 168.0 }
isIntersecting = true
}
Note the x position of absoluteTargetRect and absoluteIntersectionRect are slightly different.
It's getting converted to an integral rect via:
LayoutRect rectInFrameViewSpace(renderer->view().frameView().contentsToView(snappedIntRect(*rectInFrameAbsoluteSpace)));
This can be fixed by using the FloatRect version of `contentsToView()` but the Chromium bug suggests there are other issues too. diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index 5d3d20c820a0e9f03642a412ad9aff493bb25ff3..5cd70b074858012e752a5f35cafaa84b97e600d0 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -8043,7 +8043,7 @@ static std::optional<LayoutRect> computeClippedRectInRootContentsSpace(const Lay
if (!intersects)
return std::nullopt;
- LayoutRect rectInFrameViewSpace(renderer->view().frameView().contentsToView(snappedIntRect(*rectInFrameAbsoluteSpace)));
+ LayoutRect rectInFrameViewSpace = LayoutRect { renderer->view().frameView().contentsToView(*rectInFrameAbsoluteSpace) };
auto* ownerRenderer = renderer->frame().ownerRenderer();
if (!ownerRenderer)
return std::nullopt;
(In reply to Simon Fraser (smfr) from comment #6) > diff --git a/Source/WebCore/dom/Document.cpp > b/Source/WebCore/dom/Document.cpp > index > 5d3d20c820a0e9f03642a412ad9aff493bb25ff3.. > 5cd70b074858012e752a5f35cafaa84b97e600d0 100644 > --- a/Source/WebCore/dom/Document.cpp > +++ b/Source/WebCore/dom/Document.cpp > @@ -8043,7 +8043,7 @@ static std::optional<LayoutRect> > computeClippedRectInRootContentsSpace(const Lay > if (!intersects) > return std::nullopt; > > - LayoutRect > rectInFrameViewSpace(renderer->view().frameView(). > contentsToView(snappedIntRect(*rectInFrameAbsoluteSpace))); > + LayoutRect rectInFrameViewSpace = LayoutRect { > renderer->view().frameView().contentsToView(*rectInFrameAbsoluteSpace) }; > auto* ownerRenderer = renderer->frame().ownerRenderer(); > if (!ownerRenderer) > return std::nullopt; To fix this - I need to make pull request of this change? I am not super skilled in C++ and still learning GitHub mojo in Webkit. I am happy take it offline on Webkit Slack for any guidance on how to fix this. Thanks! Pull request: https://github.com/WebKit/WebKit/pull/3553 I've just noticed we have already imported tests for it and we are succeeding on both without a patch: 1. /LayoutTests/imported/w3c/web-platform-tests/intersection-observer/intersection-ratio-with-fractional-bounds.html 2. /LayoutTests/imported/w3c/web-platform-tests/intersection-observer/intersection-ratio-with-fractional-bounds-2.html Reading the chromium thread https://bugs.chromium.org/p/chromium/issues/detail?id=1020466, for them this would happen when [a] running the test in a process-isolated cross-origin iframe, like when hosting it in fiddle, [b] regular case, out of iframe. Their related fix is to address [b], which doesn't happen for us. While [a] happens for gecko, blink and webkit and it seems to be related to the propagation window resizing to the iframe process. I reproduced this locally in a test case with no frames (the JS fiddle). Committed 254244@main (b5701774e49f): <https://commits.webkit.org/254244@main> Reviewed commits have been landed. Closing PR #3553 and removing active labels. |