Skip to content

fix: rootMargin ignored when IntersectionObserver root clips - #58177

Open
edkimmel wants to merge 1 commit into
react:mainfrom
edkimmel:fix/intersection-observer-rootmargin-clip
Open

fix: rootMargin ignored when IntersectionObserver root clips#58177
edkimmel wants to merge 1 commit into
react:mainfrom
edkimmel:fix/intersection-observer-rootmargin-clip

Conversation

@edkimmel

@edkimmel edkimmel commented Aug 27, 2026

Copy link
Copy Markdown

Summary

Hit this using IntersectionObserver on a ScrollView with rootMargin to preload content below the fold. rootBounds grew by the margin, but intersectionRatio stayed 0 for anything past the clip.

We're clipping the target to the root's overflow (the ScrollView / overflow: hidden box) before intersecting with the margin-expanded rect. That's not what the spec does.

Compute the intersection: walk containing blocks while container is not root and clip there, then intersect with the root intersection rectangle, which already includes rootMargin. The spec also calls out that rootMargin only applies to the root — clipping by any other ancestor is unchanged.

This stops overflow-clipping the observation root itself. Intermediate clippers stay as they are, so a viewport-rooted observer still can't see past a ScrollView. That's scrollMargin, which we don't implement.

--

Lots of words to say: This enables rootMargin to correctly extend the viewport of ScrollViews or any other view with overflow clipping when using that view as the root. This also gives users a path around missing scrollMargin.

Changelog:

[GENERAL] [FIXED] - IntersectionObserver rootMargin now affects intersection against a clipping root

Test Plan

  • existing "clipping root with rootMargin" test: 10px margin on a 100x100 overflow:hidden root should intersect 60px of a child sitting at y=50, not 50px
  • new ScrollView + rootMargin: 150px + threshold: [0.01] — target fully below the fold reports intersecting
  • new viewport-root control — same layout, still not intersecting (intermediate ScrollView still clips)

…tion root

The spec clips overflow ancestors *until* the root, then intersects with the
root intersection rectangle, which includes rootMargin. We were clipping the
target to the root's own overflow (ScrollView, overflow: hidden) first, so
rootMargin expanded rootBounds but not the intersection area.

Skip overflow clipping on the specified ancestor for IntersectionObserver.
Intermediate clippers are unchanged.
@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 Aug 27, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 27, 2026
@meta-codesync

meta-codesync Bot commented Aug 28, 2026

Copy link
Copy Markdown

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

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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant