From 4f8d215d8e4c3967674c12e36d19a44966aec91c Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 20 Mar 2025 13:08:29 -0700 Subject: [PATCH] Ensure UIManagerHelper does not access UIManagerModule (#50159) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50159 Ensure UIManagerHelper does not access UIManagerModule changelog: [internal] internal Reviewed By: cortinico, alanleedev Differential Revision: D70742205 fbshipit-source-id: f7eabfb7d28b4debc667a9b0cfd55741b373380b --- .../com/facebook/react/uimanager/UIManagerHelper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java index c5004369b89..fa9776040ff 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java @@ -22,6 +22,8 @@ import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactNoCrashSoftException; import com.facebook.react.bridge.ReactSoftExceptionLogger; import com.facebook.react.bridge.UIManager; +import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel; +import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger; import com.facebook.react.uimanager.common.UIManagerType; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.EventDispatcherProvider; @@ -69,6 +71,14 @@ public class UIManagerHelper { return uiManager; } + // The following code is compiled-out when `context.isBridgeless() == true && + // ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE == true ` because: + // - BridgelessReactContext.isBridgeless() is set to true statically + // - BridgeReactContext is compiled-out when UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE == true + // + // To detect a potential regression we add the following assertion ERROR + LegacyArchitectureLogger.assertWhenLegacyArchitectureMinifyingEnabled( + "UIManagerHelper.getUIManager(context, uiManagerType)", LegacyArchitectureLogLevel.ERROR); if (!context.hasCatalystInstance()) { ReactSoftExceptionLogger.logSoftException( TAG,