Permalink
Browse files

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
  • Loading branch information...
d16r authored and facebook-github-bot committed Nov 8, 2018
1 parent fe49809 commit 81b74ec1ed3792c0b406c30b0a1c01219a2d6243
Showing with 8 additions and 2 deletions.
  1. +8 −2 React/CxxBridge/RCTCxxBridge.mm
@@ -534,6 +534,12 @@ - (void)_initializeBridgeLocked:(std::shared_ptr<JSExecutorFactory>)executorFact
}

- (NSArray<RCTModuleData *> *)registerModulesForClasses:(NSArray<Class> *)moduleClasses
{
return [self _registerModulesForClasses:moduleClasses lazilyDiscovered:NO];
}

- (NSArray<RCTModuleData *> *)_registerModulesForClasses:(NSArray<Class> *)moduleClasses
lazilyDiscovered:(BOOL)lazilyDiscovered
{
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways,
@"-[RCTCxxBridge initModulesWithDispatchGroup:] autoexported moduleData", nil);
@@ -549,7 +555,7 @@ - (void)_initializeBridgeLocked:(std::shared_ptr<JSExecutorFactory>)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<RCTModuleData *> *moduleDataById = [self registerModulesForClasses:modules];
NSArray<RCTModuleData *> *moduleDataById = [self _registerModulesForClasses:modules lazilyDiscovered:lazilyDiscovered];

if (lazilyDiscovered) {
#if RCT_DEBUG

0 comments on commit 81b74ec

Please sign in to comment.