Skip to content

Commit 571af89

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Crash the app when Legacy Arch is enabled
Summary: 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 Differential Revision: D83066377
1 parent b9e6e34 commit 571af89

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ - (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)delegate
380380
moduleProvider:(RCTBridgeModuleListProvider)block
381381
launchOptions:(NSDictionary *)launchOptions
382382
{
383+
[RCTBridge throwIfOnLegacyArch];
384+
383385
if (self = [super init]) {
384386
RCTEnforceNewArchitectureValidation(RCTNotAllowedInBridgeless, self, nil);
385387
_delegate = delegate;
@@ -393,6 +395,17 @@ - (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)delegate
393395
return self;
394396
}
395397

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

398411
- (void)dealloc

0 commit comments

Comments
 (0)