From dc132a4fd4ca8dc28dc7dbb2406ac67dac1a0ee7 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 24 Sep 2025 02:45:46 -0700 Subject: [PATCH] Crash the app when Legacy Arch is enabled (#53911) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53911 This change mimics what we implemented on Android to crash the app. This is in general never going t be triggered. It will be triggered only if users are actually going through the old way to initialize React Native, i.e. by using the RCTRootView class which creates thebridge, or if they are creating the bridge themselves. ## Changelog: [iOS][Added] - Crash the app if they force the legacy architecture. Reviewed By: RSNara, cortinico Differential Revision: D83066377 fbshipit-source-id: 0907effceb9a3655ec8d6bde8e0986f50f1ab663 --- packages/react-native/React/Base/RCTBridge.mm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/react-native/React/Base/RCTBridge.mm b/packages/react-native/React/Base/RCTBridge.mm index e235c49d911..2b62694d214 100644 --- a/packages/react-native/React/Base/RCTBridge.mm +++ b/packages/react-native/React/Base/RCTBridge.mm @@ -380,6 +380,11 @@ static RCTBridge *RCTCurrentBridgeInstance = nil; moduleProvider:(RCTBridgeModuleListProvider)block launchOptions:(NSDictionary *)launchOptions { + // Only enabld this assertion in OSS +#if COCOAPODS + [RCTBridge throwIfOnLegacyArch]; +#endif + if (self = [super init]) { RCTEnforceNewArchitectureValidation(RCTNotAllowedInBridgeless, self, nil); _delegate = delegate; @@ -393,6 +398,17 @@ static RCTBridge *RCTCurrentBridgeInstance = nil; return self; } +// Wrap the exception throwing in a static method to avoid the warning: "The code following the exception will never be +// executed". This might create build failures internally where we treat warnings as errors. ++ (void)throwIfOnLegacyArch +{ + @throw [NSException + exceptionWithName:NSInternalInconsistencyException + reason: + @"You are trying to initialize the legacy architecture. This is not supported anymore and will be removed in the next version of React Native. Please use the New Architecture instead." + userInfo:nil]; +} + RCT_NOT_IMPLEMENTED(-(instancetype)init) - (void)dealloc