From 2ae23d9f36ca7140448fc9cafda3fef281cf5b3c Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 11 Jul 2016 13:15:59 -0700 Subject: [PATCH] Flush pending calls off the main-thread Reviewed By: majak Differential Revision: D3535193 fbshipit-source-id: 8c4736629eab3c723641f0c3fb449c168cd492a1 --- React/Base/RCTBatchedBridge.m | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index bad2a4de3..1f80fa390 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -187,11 +187,13 @@ RCT_EXTERN NSArray *RCTGetModuleClasses(void); } else { // Allow testing without a script dispatch_async(dispatch_get_main_queue(), ^{ - [self didFinishLoading]; [[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification object:self->_parentBridge userInfo:@{@"bridge": self}]; }); + + [self flushPendingCalls]; + onSourceLoad(nil, nil, 0); } } @@ -477,14 +479,15 @@ RCT_EXTERN NSArray *RCTGetModuleClasses(void); NSRunLoop *targetRunLoop = [self->_javaScriptExecutor isKindOfClass:[RCTJSCExecutor class]] ? [NSRunLoop currentRunLoop] : [NSRunLoop mainRunLoop]; [self->_displayLink addToRunLoop:targetRunLoop]; - // Perform the state update and notification on the main thread, so we can't run into + // Perform the notification on the main thread, so we can't run into // timing issues with RCTRootView dispatch_async(dispatch_get_main_queue(), ^{ - [self didFinishLoading]; [[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification object:self->_parentBridge userInfo:@{@"bridge": self}]; }); + + [self flushPendingCalls]; }]; #if RCT_DEV @@ -495,17 +498,18 @@ RCT_EXTERN NSArray *RCTGetModuleClasses(void); NSNumber *port = self.bundleURL.port; [self enqueueJSCall:@"HMRClient.enable" args:@[@"ios", path, host, RCTNullIfNil(port)]]; } - #endif - } -- (void)didFinishLoading +- (void)flushPendingCalls { [_performanceLogger markStopForTag:RCTPLBridgeStartup]; - _loading = NO; + [_javaScriptExecutor executeBlockOnJavaScriptQueue:^{ for (dispatch_block_t call in self->_pendingCalls) { + _loading = NO; + + for (dispatch_block_t call in _pendingCalls) { call(); } }];