From b0704236034bbca0932f6db6d3244ad4e59d425b Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Mon, 4 Sep 2023 07:59:06 -0700 Subject: [PATCH] Remove Flipper actions in Dev Menu, add new Open Debugger action (#39124) Summary: ## Context RFC: Decoupling Flipper from React Native core: https://github.com/react-native-community/discussions-and-proposals/pull/641 ## Changes - Removes Flipper-backed "Launch Debugger" and "Launch React DevTools" actions from the Dev Menu. - Adds replacement "Launch Debugger" action triggering the new one-click Hermes debugger flow for 0.73. Changelog: [iOS][Changed] Remove Flipper actions in Dev Menu, add new Open Debugger action Reviewed By: motiz88, blakef Differential Revision: D46220076 --- .../React/CoreModules/RCTDevMenu.mm | 21 ++++--------------- .../DevSupport/RCTInspectorDevServerHelper.h | 1 + .../DevSupport/RCTInspectorDevServerHelper.mm | 20 ++++++++++++++++++ 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTDevMenu.mm b/packages/react-native/React/CoreModules/RCTDevMenu.mm index 1a8b81ead4d23b..4db65d3a910577 100644 --- a/packages/react-native/React/CoreModules/RCTDevMenu.mm +++ b/packages/react-native/React/CoreModules/RCTDevMenu.mm @@ -260,29 +260,16 @@ - (void)setDefaultJSBundle if (!devSettings.isProfilingEnabled) { #if RCT_ENABLE_INSPECTOR if (devSettings.isDeviceDebuggingAvailable) { - // For on-device debugging we link out to Flipper. - // Since we're assuming Flipper is available, also include the DevTools. - // Note: For parity with the Android code. + // On-device JS debugging (CDP). Render action to open debugger frontend. [items addObject:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString * { return @"Open Debugger"; } handler:^{ [RCTInspectorDevServerHelper - openURL:@"flipper://null/Hermesdebuggerrn?device=React%20Native" - withBundleURL:bundleManager.bundleURL - withErrorMessage:@"Failed to open Flipper. Please check that Metro is running."]; - }]]; - - [items addObject:[RCTDevMenuItem - buttonItemWithTitleBlock:^NSString * { - return @"Open React DevTools"; - } - handler:^{ - [RCTInspectorDevServerHelper - openURL:@"flipper://null/React?device=React%20Native" - withBundleURL:bundleManager.bundleURL - withErrorMessage:@"Failed to open Flipper. Please check that Metro is running."]; + openDebugger:bundleManager.bundleURL + withErrorMessage: + @"Failed to open debugger. Please check that the dev server is running."]; }]]; } #endif diff --git a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.h b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.h index 08397c36ab0ba7..b41734010b8bf2 100644 --- a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.h +++ b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.h @@ -18,6 +18,7 @@ + (RCTInspectorPackagerConnection *)connectWithBundleURL:(NSURL *)bundleURL; + (void)disableDebugger; + (void)openURL:(NSString *)url withBundleURL:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessage; ++ (void)openDebugger:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessage; @end #endif diff --git a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm index cf404f3900c0e3..442e07214b0a31 100644 --- a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm +++ b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm @@ -89,6 +89,26 @@ + (void)openURL:(NSString *)url withBundleURL:(NSURL *)bundleURL withErrorMessag }] resume]; } ++ (void)openDebugger:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessage +{ + NSString *appId = [[[NSBundle mainBundle] bundleIdentifier] + stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet]; + + NSURL *url = [NSURL + URLWithString:[NSString stringWithFormat:@"http://%@/open-debugger?appId=%@", getServerHost(bundleURL), appId]]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"POST"]; + + [[[NSURLSession sharedSession] + dataTaskWithRequest:request + completionHandler:^( + __unused NSData *_Nullable data, __unused NSURLResponse *_Nullable response, NSError *_Nullable error) { + if (error != nullptr) { + RCTLogWarn(@"%@", errorMessage); + } + }] resume]; +} + + (void)disableDebugger { sendEventToAllConnections(kDebuggerMsgDisable);