From 3ef7de848d6d4d95fe1ce4e4cf80bbfceeabb746 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Fri, 22 Sep 2023 04:43:11 -0700 Subject: [PATCH] Improve remote debugging LogBox message, cleanup unused openURL method (#39582) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39582 Some tidying up around remote JS debugging while testing. See also https://github.com/react-native-community/cli/pull/2083. ## Changelog: [iOS][Breaking] - Remove `openURL` method from `RCTInspectorDevServerHelper` Reviewed By: cipolleschi Differential Revision: D49499068 fbshipit-source-id: 843ef6cf1af658756466854fc1a0b3edd91c1f37 --- .../React/CoreModules/RCTWebSocketExecutor.mm | 5 +++- .../DevSupport/RCTInspectorDevServerHelper.h | 1 - .../DevSupport/RCTInspectorDevServerHelper.mm | 26 +------------------ 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTWebSocketExecutor.mm b/packages/react-native/React/CoreModules/RCTWebSocketExecutor.mm index 1b03cbcd37f86a..1b7ffd29660d6a 100644 --- a/packages/react-native/React/CoreModules/RCTWebSocketExecutor.mm +++ b/packages/react-native/React/CoreModules/RCTWebSocketExecutor.mm @@ -165,7 +165,10 @@ - (void)sendMessage:(NSDictionary *)message onReply:(RCTWSMessag dispatch_async(_jsQueue, ^{ if (!self.valid) { - callback(RCTErrorWithMessage(@"Runtime is not ready for debugging. Make sure Metro is running."), nil); + callback( + RCTErrorWithMessage( + @"Runtime is not ready for debugging. Make sure Metro is running and the Remote Debugging browser window is open."), + nil); return; } diff --git a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.h b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.h index b41734010b8bf2..5be6db1c28412e 100644 --- a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.h +++ b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.h @@ -17,7 +17,6 @@ + (RCTInspectorPackagerConnection *)connectWithBundleURL:(NSURL *)bundleURL; + (void)disableDebugger; -+ (void)openURL:(NSString *)url withBundleURL:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessage; + (void)openDebugger:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessage; @end diff --git a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm index 442e07214b0a31..819e14a39fd71b 100644 --- a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm +++ b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm @@ -51,10 +51,7 @@ escapedDeviceName, escapedAppName]]; } -static NSURL *getOpenUrlEndpoint(NSURL *bundleURL) -{ - return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/open-url", getServerHost(bundleURL)]]; -} + @implementation RCTInspectorDevServerHelper RCT_NOT_IMPLEMENTED(-(instancetype)init) @@ -68,27 +65,6 @@ static void sendEventToAllConnections(NSString *event) } } -+ (void)openURL:(NSString *)url withBundleURL:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessage -{ - NSURL *endpoint = getOpenUrlEndpoint(bundleURL); - - NSDictionary *jsonBodyDict = @{@"url" : url}; - NSData *jsonBodyData = [NSJSONSerialization dataWithJSONObject:jsonBodyDict options:kNilOptions error:nil]; - - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:endpoint]; - [request setHTTPMethod:@"POST"]; - [request setHTTPBody:jsonBodyData]; - - [[[NSURLSession sharedSession] - dataTaskWithRequest:request - completionHandler:^( - __unused NSData *_Nullable data, __unused NSURLResponse *_Nullable response, NSError *_Nullable error) { - if (error != nullptr) { - RCTLogWarn(@"%@", errorMessage); - } - }] resume]; -} - + (void)openDebugger:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessage { NSString *appId = [[[NSBundle mainBundle] bundleIdentifier]