Skip to content

Commit

Permalink
Give eagerly loaded modules precedent over lazily loaded one.
Browse files Browse the repository at this point in the history
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 81b74ec
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 81b74ec

Please sign in to comment.