From 4aedcc767095bd5fd33a643e68311920ea18a5f5 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Sun, 10 Jul 2016 12:23:42 -0700 Subject: [PATCH] Fix double completion callback in RCTJavascriptLoader Reviewed By: foghina, mmmulani Differential Revision: D3541511 fbshipit-source-id: 9a0a4be635ca910cb1a5c875a0f4a2b82c51cf71 --- React/Base/RCTJavaScriptLoader.m | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/React/Base/RCTJavaScriptLoader.m b/React/Base/RCTJavaScriptLoader.m index fbc5cc1c9..a44dc5baf 100755 --- a/React/Base/RCTJavaScriptLoader.m +++ b/React/Base/RCTJavaScriptLoader.m @@ -60,7 +60,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) } magicNumber = NSSwapLittleIntToHost(magicNumber); - if (magicNumber == RCTRAMBundleMagicNumber) { NSData *source = [NSData dataWithBytes:&magicNumber length:sizeof(magicNumber)]; NSError *error = nil; @@ -73,16 +72,16 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) sourceLength = statInfo.st_size; } onComplete(error, source, sourceLength); + } else { + // Reading in a large bundle can be slow. Dispatch to the background queue to do it. + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSError *error = nil; + NSData *source = [NSData dataWithContentsOfFile:scriptURL.path + options:NSDataReadingMappedIfSafe + error:&error]; + onComplete(error, source, source.length); + }); } - - // Reading in a large bundle can be slow. Dispatch to the background queue to do it. - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - NSError *error = nil; - NSData *source = [NSData dataWithContentsOfFile:scriptURL.path - options:NSDataReadingMappedIfSafe - error:&error]; - onComplete(error, source, source.length); - }); return; }