Skip to content

Commit

Permalink
Fix assertion when modules are accessed early on in bridge startup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Aug 26, 2015
1 parent 9ffbfae commit 7bf157c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions React/Base/RCTBatchedBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,10 @@ - (BOOL)isValid

- (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;
}

Expand Down
6 changes: 5 additions & 1 deletion React/Base/RCTLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7bf157c

Please sign in to comment.