From fd40cd920245fd923eb23384807f93dfd5d60497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 27 Nov 2026 09:42:55 -0800 Subject: [PATCH] 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 --- .../react/renderer/graphics/RectangleEdges.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h b/packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h index e555a3a1f262..11b689537d11 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h +++ b/packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h @@ -102,6 +102,16 @@ using EdgeMargins = RectangleEdges; * Resolves margins into absolute insets against the given size. * Percentages on the vertical edges resolve against the height, and those on * the horizontal edges resolve against the width. + * + * This intentionally matches Chrome, Firefox, and Safari's rootMargin behavior + * rather than the spec, which says "Percentages are resolved relative to the + * width of the undilated rectangle." Chrome and Safari also use height for + * vertical scrollMargin percentages. A width-only change is unlikely to be + * web-compatible, so preserve browser parity here. + * https://w3c.github.io/IntersectionObserver/#root-intersection-rectangle + * https://issues.chromium.org/issues/40725112 + * Chromium's ResolveMargin uses height for top/bottom and width for left/right: + * https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/intersection_observer/intersection_geometry.cc */ inline EdgeInsets resolveEdgeMargins(const EdgeMargins &margins, const Size &size) noexcept {