Skip to content

Resolve IntersectionObserver percentage margins against width (#60332) - #60332

Closed
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D134823780
Closed

rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D134823780

Conversation

@rubennorte

@rubennorte rubennorte commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary:

Context

The Intersection Observer specification resolves percentage margins on all four edges against the width of the undilated root or scrollport rectangle. For both rootMargin and scrollMargin, it states:

Percentages are resolved relative to the width of the undilated rectangle.

React Native instead resolved top and bottom percentages against height, producing incorrect intersection bounds on non-square rectangles.

Changes

Make resolveEdgeMargins take an explicit referenceLength instead of a rectangle size, and pass the undilated width at each IntersectionObserver call site. Resolve all percentage edges against that reference while leaving absolute margins and per-scrollport resolution unchanged. Regenerate the C++ API snapshots for the signature change.

Clarify the API documentation and extend existing integration coverage for non-square roots, positive and negative margins, scaled and nested scrollports, and combined root and scroll margins.

Changelog:
[General][Fixed] - Resolve IntersectionObserver percentage rootMargin and scrollMargin values against rectangle width on all sides

Differential Revision: D134823780

@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 27, 2026
@meta-codesync

meta-codesync Bot commented Nov 27, 2026

Copy link
Copy Markdown

@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D134823780.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 27, 2026
…60332)

Summary:

## Context
The [Intersection Observer specification](https://w3c.github.io/IntersectionObserver/#root-intersection-rectangle) resolves percentage margins on all four edges against the width of the undilated root or scrollport rectangle. For both `rootMargin` and `scrollMargin`, it states:

> Percentages are resolved relative to the width of the undilated rectangle.

React Native instead resolved top and bottom percentages against height, producing incorrect intersection bounds on non-square rectangles.

## Changes
Make `resolveEdgeMargins` take an explicit `referenceLength` instead of a rectangle size, and pass the undilated width at each IntersectionObserver call site. Resolve all percentage edges against that reference while leaving absolute margins and per-scrollport resolution unchanged. Regenerate the C++ API snapshots for the signature change.

Clarify the API documentation and extend existing integration coverage for non-square roots, positive and negative margins, scaled and nested scrollports, and combined root and scroll margins.

Changelog:
[General][Fixed] - Resolve `IntersectionObserver` percentage `rootMargin` and `scrollMargin` values against rectangle width on all sides

Differential Revision: D134823780
@meta-codesync meta-codesync Bot changed the title Resolve IntersectionObserver percentage margins against width Resolve IntersectionObserver percentage margins against width (#60332) Nov 27, 2026

@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.

@rubennorte

Copy link
Copy Markdown
Member Author

Abandoned as I verified this "bug" exists also in Chrome, Firefox and Safari. Implementing this "bug" for browser compatibility is more valuable than blindly following the spec.

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. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants