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
This commit is contained in:
Rubén Norte
2025-08-12 05:41:11 -07:00
committed by Facebook GitHub Bot
parent c2c2e6b7c2
commit 42db2f8405
2 changed files with 56 additions and 52 deletions
@@ -137,51 +137,52 @@ void ReactHost::createReactInstance() {
WebSocketClientFactoryKey);
// Create devServerHelper
if (reactInstanceConfig_.enableDebugging) {
if (!devServerHelper_) {
devServerHelper_ = std::make_shared<DevServerHelper>(
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<Inspector>(
reactInstanceConfig_.appId,
reactInstanceConfig_.deviceName,
webSocketClientFactory,
httpClientFactory);
inspector_->ensureHostTarget(
[this]() { reloadReactInstance(); },
[weakDevUIDelegate = std::weak_ptr<IDevUIDelegate>(
reactInstanceData_->devUIDelegate)](
bool showDebuggerOverlay,
std::function<void()>&& 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<DevServerHelper>(
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<Inspector>(
reactInstanceConfig_.appId,
reactInstanceConfig_.deviceName,
webSocketClientFactory,
httpClientFactory);
inspector_->ensureHostTarget(
[this]() { reloadReactInstance(); },
[weakDevUIDelegate =
std::weak_ptr<IDevUIDelegate>(reactInstanceData_->devUIDelegate)](
bool showDebuggerOverlay,
std::function<void()>&& resumeDebuggerFn) {
if (auto debugUIDelegate = weakDevUIDelegate.lock()) {
if (showDebuggerOverlay) {
debugUIDelegate->showDebuggerOverlay(std::move(resumeDebuggerFn));
} else {
debugUIDelegate->hideDebuggerOverlay();
}
});
}
if (!packagerConnection_) {
packagerConnection_ = std::make_unique<PackagerConnection>(
webSocketClientFactory,
devServerHelper_->getPackagerConnectionUrl(),
[this]() { reloadReactInstance(); },
[]() {});
}
}
});
}
if (!packagerConnection_ && reactInstanceConfig_.enableDevMode) {
packagerConnection_ = std::make_unique<PackagerConnection>(
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();
}
@@ -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};
};