From 7995638a61b7f5680c699a404916a0443d8b5a3c Mon Sep 17 00:00:00 2001 From: rorycai Date: Fri, 13 Jun 2025 13:59:51 +0800 Subject: [PATCH] RN: Return zero measure values in measure API when ReactRootView cannot be found in view hierarchy --- packages/react-native/React/Modules/RCTUIManager.mm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/react-native/React/Modules/RCTUIManager.mm b/packages/react-native/React/Modules/RCTUIManager.mm index d552a9f28eae..d1716fccaaf8 100644 --- a/packages/react-native/React/Modules/RCTUIManager.mm +++ b/packages/react-native/React/Modules/RCTUIManager.mm @@ -1381,6 +1381,14 @@ - (void)_dispatchPropsDidChangeEvents rootView = rootView.superview; } + // It is possible that the RootView can't be found because this view is no longer on the screen + // and has been removed by clipping (eg. by setting the `removeClippedSubview` prop to `true`) + if (![rootView isReactRootView]) { + RCTLogError(@"measure cannot find react root view for view with tag #%@", reactTag); + callback(@[ @(0), @(0), @(0), @(0), @(0), @(0) ]); + return; + } + // By convention, all coordinates, whether they be touch coordinates, or // measurement coordinates are with respect to the root view. CGRect frame = view.frame;