fix: rootMargin ignored when IntersectionObserver root clips - #58177
Open
edkimmel wants to merge 1 commit into
Open
fix: rootMargin ignored when IntersectionObserver root clips#58177edkimmel wants to merge 1 commit into
edkimmel wants to merge 1 commit into
Conversation
…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.
|
@christophpurrer has imported this pull request. If you are a Meta employee, you can view this in D117876568. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hit this using IntersectionObserver on a ScrollView with
rootMarginto preload content below the fold.rootBoundsgrew by the margin, butintersectionRatiostayed 0 for anything past the clip.We're clipping the target to the root's overflow (the ScrollView /
overflow: hiddenbox) 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 thatrootMarginonly 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
rootMargin: 150px+threshold: [0.01]— target fully below the fold reports intersecting