Skip to content

Commit e5fca6c

Browse files
cipolleschivzaidman
authored andcommitted
Crash the app when Legacy Arch is enabled (#53911)
Summary: Pull Request resolved: #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
1 parent b1994dd commit e5fca6c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/react-native/React/Base/RCTBridge.mm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ - (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)delegate
380380
moduleProvider:(RCTBridgeModuleListProvider)block
381381
launchOptions:(NSDictionary *)launchOptions
382382
{
383+
// Only enabld this assertion in OSS
384+
#if COCOAPODS
385+
[RCTBridge throwIfOnLegacyArch];
386+
#endif
387+
383388
if (self = [super init]) {
384389
RCTEnforceNewArchitectureValidation(RCTNotAllowedInBridgeless, self, nil);
385390
_delegate = delegate;
@@ -393,6 +398,17 @@ - (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)delegate
393398
return self;
394399
}
395400

401+
// Wrap the exception throwing in a static method to avoid the warning: "The code following the exception will never be
402+
// executed". This might create build failures internally where we treat warnings as errors.
403+
+ (void)throwIfOnLegacyArch
404+
{
405+
@throw [NSException
406+
exceptionWithName:NSInternalInconsistencyException
407+
reason:
408+
@"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."
409+
userInfo:nil];
410+
}
411+
396412
RCT_NOT_IMPLEMENTED(-(instancetype)init)
397413

398414
- (void)dealloc

0 commit comments

Comments
 (0)