From 42db2f84051f37f293d0dcb2a9d4bad0ea842371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 12 Aug 2025 05:41:11 -0700 Subject: [PATCH] Split ReactInstanceConfig.enableDebugging into enableInspector and enableDevMode (#53201) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53201 Changelog: [internal] This splits the `ReactHost` option `enableDebugging` into more granular options: - `enableInspector` which enables the connection with the inspector/debugger. - `enableDevMode` which enables the use of bundles from Metro, reloads, etc. This allows us to enable the inspector in Fantom without consuming bundles from Metro. This should be backwards compatible with existing apps. In the future, we should be able to inject custom `DevSupportManager` instances into the `ReactHost` so we can customize all options with any level of granularity (the same way we do on Android, for example). Reviewed By: rshest Differential Revision: D79804006 fbshipit-source-id: c28e788e5006cdbeb1a373d44b4e5aec1acec702 --- .../react/runtime/ReactHost.cpp | 96 ++++++++++--------- .../react/runtime/ReactInstanceConfig.h | 12 ++- 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp b/packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp index b53b2b83bcf..b35df76cf65 100644 --- a/packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp +++ b/packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp @@ -137,51 +137,52 @@ void ReactHost::createReactInstance() { WebSocketClientFactoryKey); // Create devServerHelper - if (reactInstanceConfig_.enableDebugging) { - if (!devServerHelper_) { - devServerHelper_ = std::make_shared( - reactInstanceConfig_.appId, - reactInstanceConfig_.deviceName, - reactInstanceConfig_.devServerHost, - reactInstanceConfig_.devServerPort, - httpClientFactory, - [this]( - const std::string& moduleName, - const std::string& methodName, - folly::dynamic&& args) { - reactInstance_->callFunctionOnModule( - moduleName, methodName, std::move(args)); - }); - } - if (!inspector_) { - inspector_ = std::make_shared( - reactInstanceConfig_.appId, - reactInstanceConfig_.deviceName, - webSocketClientFactory, - httpClientFactory); - inspector_->ensureHostTarget( - [this]() { reloadReactInstance(); }, - [weakDevUIDelegate = std::weak_ptr( - reactInstanceData_->devUIDelegate)]( - bool showDebuggerOverlay, - std::function&& resumeDebuggerFn) { - if (auto debugUIDelegate = weakDevUIDelegate.lock()) { - if (showDebuggerOverlay) { - debugUIDelegate->showDebuggerOverlay( - std::move(resumeDebuggerFn)); - } else { - debugUIDelegate->hideDebuggerOverlay(); - } + if (!devServerHelper_ && + (reactInstanceConfig_.enableInspector || + reactInstanceConfig_.enableDevMode)) { + devServerHelper_ = std::make_shared( + reactInstanceConfig_.appId, + reactInstanceConfig_.deviceName, + reactInstanceConfig_.devServerHost, + reactInstanceConfig_.devServerPort, + httpClientFactory, + [this]( + const std::string& moduleName, + const std::string& methodName, + folly::dynamic&& args) { + reactInstance_->callFunctionOnModule( + moduleName, methodName, std::move(args)); + }); + } + + if (!inspector_ && reactInstanceConfig_.enableInspector) { + inspector_ = std::make_shared( + reactInstanceConfig_.appId, + reactInstanceConfig_.deviceName, + webSocketClientFactory, + httpClientFactory); + inspector_->ensureHostTarget( + [this]() { reloadReactInstance(); }, + [weakDevUIDelegate = + std::weak_ptr(reactInstanceData_->devUIDelegate)]( + bool showDebuggerOverlay, + std::function&& resumeDebuggerFn) { + if (auto debugUIDelegate = weakDevUIDelegate.lock()) { + if (showDebuggerOverlay) { + debugUIDelegate->showDebuggerOverlay(std::move(resumeDebuggerFn)); + } else { + debugUIDelegate->hideDebuggerOverlay(); } - }); - } - if (!packagerConnection_) { - packagerConnection_ = std::make_unique( - webSocketClientFactory, - devServerHelper_->getPackagerConnectionUrl(), - [this]() { reloadReactInstance(); }, - []() {}); - } + } + }); + } + + if (!packagerConnection_ && reactInstanceConfig_.enableDevMode) { + packagerConnection_ = std::make_unique( + webSocketClientFactory, + devServerHelper_->getPackagerConnectionUrl(), + [this]() { reloadReactInstance(); }, + []() {}); } // Create the React Instance @@ -194,7 +195,7 @@ void ReactHost::createReactInstance() { reactInstanceData_->messageQueueThread, /* allocInOldGenBeforeTTI */ false); - if (reactInstanceConfig_.enableDebugging) { + if (reactInstanceConfig_.enableInspector) { react_native_assert( inspector_ != nullptr && "Inspector is not initialized"); } @@ -262,7 +263,8 @@ void ReactHost::createReactInstance() { reactInstanceData_->turboModuleManagerDelegates, jsInvoker = std::move(jsInvoker), logBoxSurfaceDelegate = reactInstanceData_->logBoxSurfaceDelegate, - devServerHelper = devServerHelper_, + devServerHelper = + reactInstanceConfig_.enableDevMode ? devServerHelper_ : nullptr, animatedNodesManagerProvider = reactInstanceData_->animatedNodesManagerProvider, onJsError = reactInstanceData_->onJsError, @@ -421,7 +423,7 @@ bool ReactHost::loadScript( const std::string& bundlePath, const std::string& sourcePath) noexcept { bool isLoaded = false; - if (devServerHelper_) { + if (reactInstanceConfig_.enableDevMode && devServerHelper_) { devServerHelper_->setSourcePath(sourcePath); isLoaded = loadScriptFromDevServer(); } diff --git a/packages/react-native/ReactCxxPlatform/react/runtime/ReactInstanceConfig.h b/packages/react-native/ReactCxxPlatform/react/runtime/ReactInstanceConfig.h index d90b42a3547..43a0accd658 100644 --- a/packages/react-native/ReactCxxPlatform/react/runtime/ReactInstanceConfig.h +++ b/packages/react-native/ReactCxxPlatform/react/runtime/ReactInstanceConfig.h @@ -13,13 +13,15 @@ namespace facebook::react { struct ReactInstanceConfig { -#ifdef REACT_NATIVE_DEBUG - bool enableDebugging{true}; -#else - bool enableDebugging{false}; -#endif std::string appId; std::string deviceName; +#ifdef REACT_NATIVE_DEBUG + bool enableDevMode{true}; + bool enableInspector{true}; +#else + bool enableDevMode{false}; + bool enableInspector{false}; +#endif std::string devServerHost{"localhost"}; uint32_t devServerPort{8081}; };