From 81b74ec1ed3792c0b406c30b0a1c01219a2d6243 Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Thu, 8 Nov 2018 13:55:00 -0800 Subject: [PATCH] Give eagerly loaded modules precedent over lazily loaded one. Summary: Before lazily-loading code existed, modules that were already loaded into memory took precedent over modules that were additionally registered. With lazily loading modules, instead of giving eagerly loaded modules precdence, it throws a redbox. This diff fixes that behavior. Reviewed By: PeteTheHeat Differential Revision: D12983805 fbshipit-source-id: fe4fcf35d5c2ca6f9f4e3f0d1d8c2ca35468fb1b --- React/CxxBridge/RCTCxxBridge.mm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index c5bcb308e02ffb..f80e59e25a4627 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -534,6 +534,12 @@ - (void)_initializeBridgeLocked:(std::shared_ptr)executorFact } - (NSArray *)registerModulesForClasses:(NSArray *)moduleClasses +{ + return [self _registerModulesForClasses:moduleClasses lazilyDiscovered:NO]; +} + +- (NSArray *)_registerModulesForClasses:(NSArray *)moduleClasses + lazilyDiscovered:(BOOL)lazilyDiscovered { RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTCxxBridge initModulesWithDispatchGroup:] autoexported moduleData", nil); @@ -549,7 +555,7 @@ - (void)_initializeBridgeLocked:(std::shared_ptr)executorFact // Check for module name collisions RCTModuleData *moduleData = _moduleDataByName[moduleName]; if (moduleData) { - if (moduleData.hasInstance) { + if (moduleData.hasInstance || lazilyDiscovered) { // Existing module was preregistered, so it takes precedence continue; } else if ([moduleClass new] == nil) { @@ -682,7 +688,7 @@ - (void)registerExtraLazyModules lazilyDiscovered:(BOOL)lazilyDiscovered { // Set up moduleData for automatically-exported modules - NSArray *moduleDataById = [self registerModulesForClasses:modules]; + NSArray *moduleDataById = [self _registerModulesForClasses:modules lazilyDiscovered:lazilyDiscovered]; if (lazilyDiscovered) { #if RCT_DEBUG