Fix assertion when modules are accessed early on in bridge startup

This commit is contained in:
Nick Lockwood 2015-08-26 09:28:14 -07:00
parent 9ffbfaeb35
commit 7bf157c92c
2 changed files with 9 additions and 4 deletions

View File

@ -407,9 +407,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
- (NSDictionary *)modules
{
RCTAssert(!self.isValid || _modulesByName != nil, @"Bridge modules have not yet been initialized. "
"You may be trying to access a module too early in the startup procedure.");
if (RCT_DEBUG && self.isValid && _modulesByName == nil) {
RCTLogError(@"Bridge modules have not yet been initialized. You may be "
"trying to access a module too early in the startup procedure.");
}
return _modulesByName;
}

View File

@ -226,7 +226,11 @@ void _RCTLogFormat(
}
}
}];
[[RCTBridge currentBridge].redBox showErrorMessage:message withStack:stack];
dispatch_async(dispatch_get_main_queue(), ^{
// red box is thread safe, but by deferring to main queue we avoid a startup
// race condition that causes the module to be accessed before it has loaded
[[RCTBridge currentBridge].redBox showErrorMessage:message withStack:stack];
});
}
// Log to JS executor