From 7bf157c92c368e7b87a34ff681e2c545f171f742 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Wed, 26 Aug 2015 09:28:14 -0700 Subject: [PATCH] Fix assertion when modules are accessed early on in bridge startup --- React/Base/RCTBatchedBridge.m | 7 ++++--- React/Base/RCTLog.m | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index ad0cc39eef2..5ef4c65026e 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -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; } diff --git a/React/Base/RCTLog.m b/React/Base/RCTLog.m index a8679da9e04..ebbf6a1b85b 100644 --- a/React/Base/RCTLog.m +++ b/React/Base/RCTLog.m @@ -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