From a89005d709bc8fe88fc5bf627a7dd77e935c21dc Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Mon, 22 Jan 2024 10:09:17 -0800 Subject: [PATCH] Don't inject synthetic Debugger.disable message in modern CDP backend (#42400) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42400 Changelog: [Internal] TSIA - iOS counterpart of D52040149 on Android. The overarching principle is that nothing outside of an Agent should be doing anything with the CDP message stream. Here we have a case of `RCTInspectorDevServerHelper` basically impersonating the CDP frontend in order to paper over an apparent lifetime management bug in the old backend; this gets in the way of implementing reloads natively so we disable it under the new backend. NOTE: I'm gating out both the call site in `RCTBridge` (to signal intent) *and* the actual body of `disableDebugger` (in case any out-of-tree code happens to be using this method). Reviewed By: voideanvalue Differential Revision: D50967799 fbshipit-source-id: 759718bf155b8b16c7db54ac2d2507bc71c93436 --- packages/react-native/React/Base/RCTBridge.mm | 7 +++++-- .../React/DevSupport/RCTInspectorDevServerHelper.mm | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react-native/React/Base/RCTBridge.mm b/packages/react-native/React/Base/RCTBridge.mm index 50cf8c676f2..d7e75552044 100644 --- a/packages/react-native/React/Base/RCTBridge.mm +++ b/packages/react-native/React/Base/RCTBridge.mm @@ -279,8 +279,11 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) - (void)didReceiveReloadCommand { #if RCT_ENABLE_INSPECTOR - // Disable debugger to resume the JsVM & avoid thread locks while reloading - [RCTInspectorDevServerHelper disableDebugger]; + auto &inspectorFlags = facebook::react::jsinspector_modern::InspectorFlags::getInstance(); + if (!inspectorFlags.getEnableModernCDPRegistry()) { + // Disable debugger to resume the JsVM & avoid thread locks while reloading + [RCTInspectorDevServerHelper disableDebugger]; + } #endif [[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeWillReloadNotification object:self userInfo:nil]; diff --git a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm index 2db91e64b0c..662aa39eca5 100644 --- a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm +++ b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm @@ -145,7 +145,10 @@ static void sendEventToAllConnections(NSString *event) + (void)disableDebugger { - sendEventToAllConnections(kDebuggerMsgDisable); + auto &inspectorFlags = facebook::react::jsinspector_modern::InspectorFlags::getInstance(); + if (!inspectorFlags.getEnableModernCDPRegistry()) { + sendEventToAllConnections(kDebuggerMsgDisable); + } } + (id)connectWithBundleURL:(NSURL *)bundleURL