From 0cfe76399c3f38d8120e83e634475d00a55a718a Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 23 Dec 2015 13:31:44 -0800 Subject: [PATCH] Improve red boxes coming from RCTWebSocketExecutor Reviewed By: tadeuzagallo Differential Revision: D2775452 fb-gh-sync-id: b709e0e725ab76468700466b804237eed9158bfd --- Libraries/WebSocket/RCTWebSocketExecutor.m | 14 +++++++++----- React/Base/RCTBatchedBridge.m | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Libraries/WebSocket/RCTWebSocketExecutor.m b/Libraries/WebSocket/RCTWebSocketExecutor.m index c5813bc5c..e84539a73 100644 --- a/Libraries/WebSocket/RCTWebSocketExecutor.m +++ b/Libraries/WebSocket/RCTWebSocketExecutor.m @@ -66,9 +66,9 @@ RCT_EXPORT_MODULE() [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:startDevToolsURL] delegate:nil]; if (![self connectToProxy]) { - RCTLogError(@"Connection to %@ timed out. Are you running node proxy? If \ - you are running on the device, check if you have the right IP \ - address in `RCTWebSocketExecutor.m`.", _url); + RCTLogError(@"Connection to %@ timed out. Are you running node proxy? If " + "you are running on the device, check if you have the right IP " + "address in `RCTWebSocketExecutor.m`.", _url); [self invalidate]; return; } @@ -81,7 +81,7 @@ RCT_EXPORT_MODULE() } if (!runtimeIsReady) { RCTLogError(@"Runtime is not ready. Make sure Chrome is running and not " - "paused on a breakpoint or exception and try reloading again."); + "paused on a breakpoint or exception and try reloading again."); [self invalidate]; return; } @@ -125,7 +125,11 @@ RCT_EXPORT_MODULE() - (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error { - RCTLogError(@"WebSocket connection failed with error %@", error); + dispatch_semaphore_signal(_socketOpenSemaphore); + dispatch_async(dispatch_get_main_queue(), ^{ + // Give the setUp method an opportunity to report an error first + RCTLogError(@"WebSocket connection failed with error %@", error); + }); } - (void)sendMessage:(NSDictionary *)message waitForReply:(RCTWSMessageCallback)callback diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index ce9bfb763..8e00e93f7 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -585,7 +585,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR - (void)logMessage:(NSString *)message level:(NSString *)level { - if (RCT_DEBUG) { + if (RCT_DEBUG && [_javaScriptExecutor isValid]) { [self enqueueJSCall:@"RCTLog.logIfNoNativeHook" args:@[level, message]]; }