From 9d6fa7d77e2cfcc23183d7924a30e3d7b0bbfa04 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Thu, 16 Oct 2025 23:26:47 -0700 Subject: [PATCH] Use 'explicit root' instead of 'custom root' terminology (#54177) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54177 Changelog: [Internal] - Rename the term "custom root" to "explicit root" to align with w3c spec. And "implicit root" for the document root. Reviewed By: mdvacca Differential Revision: D84795887 fbshipit-source-id: afec23f6763af56c6de1d3fce2f9501187559fb9 --- .../intersection/IntersectionObserver.cpp | 16 ++++++++-------- .../__tests__/IntersectionObserver-itest.js | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.cpp b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.cpp index d7ee1b49ae2..539db81b804 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.cpp +++ b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.cpp @@ -87,7 +87,7 @@ static Rect computeIntersection( const Rect& rootBoundingRect, const Rect& targetBoundingRect, const ShadowNodeFamily::AncestorList& targetToRootAncestors, - bool hasCustomRoot) { + bool hasExplicitRoot) { auto absoluteIntersectionRect = Rect::intersect(rootBoundingRect, targetBoundingRect); @@ -109,7 +109,7 @@ static Rect computeIntersection( auto clippedTargetFromRoot = getClippedTargetBoundingRect(targetToRootAncestors); - auto clippedTargetBoundingRect = hasCustomRoot ? Rect{ + auto clippedTargetBoundingRect = hasExplicitRoot ? Rect{ .origin=rootBoundingRect.origin + clippedTargetFromRoot.origin, .size=clippedTargetFromRoot.size} : clippedTargetFromRoot; @@ -135,14 +135,14 @@ std::optional IntersectionObserver::updateIntersectionObservation( const RootShadowNode& rootShadowNode, HighResTimeStamp time) { - bool hasCustomRoot = observationRootShadowNodeFamily_.has_value(); + bool hasExplicitRoot = observationRootShadowNodeFamily_.has_value(); - auto rootAncestors = hasCustomRoot + auto rootAncestors = hasExplicitRoot ? observationRootShadowNodeFamily_.value()->getAncestors(rootShadowNode) : ShadowNodeFamily::AncestorList{}; // Absolute coordinates of the root - auto rootBoundingRect = hasCustomRoot + auto rootBoundingRect = hasExplicitRoot ? getBoundingRect(rootAncestors) : getRootNodeBoundingRect(rootShadowNode); @@ -151,13 +151,13 @@ IntersectionObserver::updateIntersectionObservation( // Absolute coordinates of the target auto targetBoundingRect = getBoundingRect(targetAncestors); - if ((hasCustomRoot && rootAncestors.empty()) || targetAncestors.empty()) { + if ((hasExplicitRoot && rootAncestors.empty()) || targetAncestors.empty()) { // If observation root or target is not a descendant of `rootShadowNode` return setNotIntersectingState( rootBoundingRect, targetBoundingRect, {}, time); } - auto targetToRootAncestors = hasCustomRoot + auto targetToRootAncestors = hasExplicitRoot ? targetShadowNodeFamily_->getAncestors(*getShadowNode(rootAncestors)) : targetAncestors; @@ -165,7 +165,7 @@ IntersectionObserver::updateIntersectionObservation( rootBoundingRect, targetBoundingRect, targetToRootAncestors, - hasCustomRoot); + hasExplicitRoot); Float targetBoundingRectArea = targetBoundingRect.size.width * targetBoundingRect.size.height; diff --git a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js index 405cca9490c..61beb046dce 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js @@ -129,7 +129,7 @@ describe('IntersectionObserver', () => { ); }); - it('should provide access to custom `root`', () => { + it('should provide access to explicit `root`', () => { const rootRef = React.createRef(); const root = Fantom.createRoot(); @@ -1144,7 +1144,7 @@ describe('IntersectionObserver', () => { }); }); - describe('with custom root', () => { + describe('with explicit root', () => { it('should report partial non-intersecting initial state correctly', () => { const nodeRef = createRef(); const scrollNodeRef = createRef(); @@ -1911,7 +1911,7 @@ describe('IntersectionObserver', () => { expect(entries.length).toBe(1); expect(entries[0]).toBeInstanceOf(IntersectionObserverEntry); expect(entries[0].intersectionRatio).toBe(1); - // This is the ratio of intersection area / (custom) root area + // This is the ratio of intersection area / (explicit) root area expect(entries[0].rnRootIntersectionRatio).toBe(0.25); expect(entries[0].isIntersecting).toBe(true); expect(entries[0].target).toBe(node); @@ -1976,7 +1976,7 @@ describe('IntersectionObserver', () => { expect(entries.length).toBe(1); expect(entries[0]).toBeInstanceOf(IntersectionObserverEntry); expect(entries[0].intersectionRatio).toBe(0.5); - // This is the ratio of intersection area / (custom) root area + // This is the ratio of intersection area / (explicit) root area expect(entries[0].rnRootIntersectionRatio).toBe(0.5); expect(entries[0].isIntersecting).toBe(true); expect(entries[0].target).toBe(node);