Skip to content

Commit

Permalink
Filter out TurboModules from extraModulesForBridge
Browse files Browse the repository at this point in the history
Summary:
When the TurboModule system is enabled, all TM-compatible NativeModules should not go through the legacy system. We have this filtering elsewhere in the bridge, but not for eagerly initialized NativeModules with custom initializers (i.e: modules returned from extraModulesForBridge). This diff adds that filtering for modules returned from extraModulesForBridge.

NOTE: NativeModule initializers can still perform side-effects. So, it's still best to not create the TM-compatible NativeModule inside extraModulesForBridge. This diff just adds an additional layer of defense within the bridge.

Changelog: [Internal]

Differential Revision: D26264531

fbshipit-source-id: 26179d9094f67d6d6315a65cdb2dc614e5397bf3
  • Loading branch information
RSNara authored and facebook-github-bot committed Feb 6, 2021
1 parent cd6c9f3 commit d02211c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,20 @@ - (void)registerExtraModules
{
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTCxxBridge initModulesWithDispatchGroup:] extraModules", nil);

NSArray<id<RCTBridgeModule>> *extraModules = nil;
NSArray<id<RCTBridgeModule>> *appExtraModules = nil;
if ([self.delegate respondsToSelector:@selector(extraModulesForBridge:)]) {
extraModules = [self.delegate extraModulesForBridge:_parentBridge];
appExtraModules = [self.delegate extraModulesForBridge:_parentBridge];
} else if (self.moduleProvider) {
extraModules = self.moduleProvider();
appExtraModules = self.moduleProvider();
}

NSMutableArray<id<RCTBridgeModule>> *extraModules = [NSMutableArray new];

// Prevent TurboModules from appearing the the NativeModule system
for (id<RCTBridgeModule> module in appExtraModules) {
if (!(RCTTurboModuleEnabled() && [module conformsToProtocol:@protocol(RCTTurboModule)])) {
[extraModules addObject:module];
}
}

RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");
Expand Down

0 comments on commit d02211c

Please sign in to comment.