Skip to content

Don't report IntersectionObserver targets fully clipped by an ancestor as intersecting - #60152

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
rubennorte:intersection-observer-fully-clipped
Nov 19, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
rubennorte:intersection-observer-fully-clipped

Conversation

@rubennorte

Copy link
Copy Markdown
Member

Summary:

When an ancestor between the target and the root (a ScrollView or an overflow: hidden view) clips the target away entirely, getClippedTargetBoundingRect returned Rect{}: a zero-size rect at the origin. intersectOrNull then treated that as an edge-adjacent intersection whenever the root rectangle contained the origin. That's always the case for the implicit root (the origin is its corner), and almost always for an explicit root (the empty rect is translated to the root's origin).

Because an intersection ratio of 0 crosses a threshold of 0, observers with the default threshold (or an rnRootThreshold containing 0) reported these targets with isIntersecting: true, as long as their unclipped bounding box overlapped the root. rootMargin makes this easy to hit because it widens that overlap. For example, with rootMargin: '500px 0px', every item of a ScrollView within 500px of the viewport is reported as intersecting, even though the ScrollView clips it.

A fully clipped target now produces no intersection, so it's reported as not intersecting with an empty intersectionRect. This matches the intersection-observer/clip-path.html Web Platform Test: a target fully clipped by an ancestor, while its bounding box is still inside the viewport, expects isIntersecting: false.

Observers with thresholds above 0 are unaffected. They already reported these targets as not intersecting, with the same entry values.

Found while working on scrollMargin support, which is stacked on top of this.

Changelog:

[GENERAL] [FIXED] - IntersectionObserver no longer reports targets fully clipped by an ancestor as intersecting

Test Plan:

Added Fantom tests for a target fully clipped by an intermediate ScrollView, with the default threshold and with rootMargin. Both fail without this change.

yarn fantom packages/react-native/src/private/webapis/intersectionobserver/

110 passed, 1 skipped.

yarn flow-check
yarn lint

Clean.

Summary:
When an ancestor between the target and the root (a ScrollView or an
`overflow: hidden` view) clips the target away entirely,
`getClippedTargetBoundingRect` returned `Rect{}`: a zero-size rect at the
origin. `intersectOrNull` then treated that as an edge-adjacent intersection
whenever the root rectangle contained the origin, which is always the case
for the implicit root (the origin is its corner) and almost always for an
explicit root (the empty rect is translated to the root's origin).

Because a threshold of 0 is crossed by an intersection ratio of 0, observers
with the default `threshold` (or an `rnRootThreshold` containing 0) reported
such targets with `isIntersecting: true`, as long as their unclipped bounding
box overlapped the root. `rootMargin` makes this easy to hit, since it widens
that overlap: e.g. with `rootMargin: '500px 0px'`, every item of a ScrollView
within 500px of the viewport is reported as intersecting even though the
ScrollView clips it.

A fully clipped target now produces no intersection, so it's reported as not
intersecting with an empty `intersectionRect`. This matches the
`intersection-observer/clip-path.html` Web Platform Test, where a target
fully clipped by an ancestor while its bounding box is inside the viewport
expects `isIntersecting: false`. Observers with thresholds above 0 are
unaffected: they already reported these targets as not intersecting, with
the same entry values.

Changelog:
[GENERAL] [FIXED] - IntersectionObserver no longer reports targets fully clipped by an ancestor as intersecting

Test Plan:
New Fantom tests cover a target fully clipped by an intermediate ScrollView
with the default threshold, and with `rootMargin`. Both fail without this
change.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 19, 2026
@meta-codesync

meta-codesync Bot commented Nov 19, 2026

Copy link
Copy Markdown

@rubennorte has imported this pull request. If you are a Meta employee, you can view this in D133249484.

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync
meta-codesync Bot merged commit 8771d39 into react:main Nov 19, 2026
101 of 102 checks passed
@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 19, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @rubennorte in 8771d39

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants