diff --git a/packages/react-native/React/Base/RCTBridge.mm b/packages/react-native/React/Base/RCTBridge.mm index e235c49d9113a0..2b62694d214fa5 100644 --- a/packages/react-native/React/Base/RCTBridge.mm +++ b/packages/react-native/React/Base/RCTBridge.mm @@ -380,6 +380,11 @@ - (instancetype)initWithDelegate:(id)delegate 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 @@ - (instancetype)initWithDelegate:(id)delegate 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