Skip to content

Commit fd40cd9

Browse files
rubennortefacebook-github-bot
authored andcommitted
Document browser-compatible IntersectionObserver margins
Summary: ## Context The Intersection Observer specification says percentage margins on every edge resolve against width. Chrome, Firefox, and Safari instead resolve vertical rootMargin percentages against height. Chrome and Safari also do so for scrollMargin, matching React Native. Preserve browser compatibility rather than changing existing consumers. ## Changes Document the intentional compatibility divergence in `resolveEdgeMargins`, linking the specification, Chromium implementation, and https://issues.chromium.org/issues/40725112. No runtime behavior, helper signature, tests, or API snapshots change. Changelog: [Internal] Differential Revision: D134834007
1 parent 3b49389 commit fd40cd9

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ using EdgeMargins = RectangleEdges<MarginValue>;
102102
* Resolves margins into absolute insets against the given size.
103103
* Percentages on the vertical edges resolve against the height, and those on
104104
* the horizontal edges resolve against the width.
105+
*
106+
* This intentionally matches Chrome, Firefox, and Safari's rootMargin behavior
107+
* rather than the spec, which says "Percentages are resolved relative to the
108+
* width of the undilated rectangle." Chrome and Safari also use height for
109+
* vertical scrollMargin percentages. A width-only change is unlikely to be
110+
* web-compatible, so preserve browser parity here.
111+
* https://w3c.github.io/IntersectionObserver/#root-intersection-rectangle
112+
* https://issues.chromium.org/issues/40725112
113+
* Chromium's ResolveMargin uses height for top/bottom and width for left/right:
114+
* https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/intersection_observer/intersection_geometry.cc
105115
*/
106116
inline EdgeInsets resolveEdgeMargins(const EdgeMargins &margins, const Size &size) noexcept
107117
{

0 commit comments

Comments
 (0)