diff --git a/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp b/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp index a4e5b254a00c..41d81767df35 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp @@ -147,7 +147,7 @@ class HostAgent::Impl final { if (InspectorFlags::getInstance().getNetworkInspectionEnabled()) { if (req.method == "Network.enable") { auto& inspector = getInspectorInstance(); - if (inspector.getSystemState().registeredPagesCount > 1) { + if (inspector.getSystemState().registeredHostsCount > 1) { frontendChannel_( cdp::jsonError( req.id, @@ -231,7 +231,7 @@ class HostAgent::Impl final { "ReactNativeApplication.metadataUpdated", createHostMetadataPayload(hostMetadata_))); auto& inspector = getInspectorInstance(); - bool isSingleHost = inspector.getSystemState().registeredPagesCount <= 1; + bool isSingleHost = inspector.getSystemState().registeredHostsCount <= 1; if (!isSingleHost) { emitSystemStateChanged(isSingleHost); } diff --git a/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp b/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp index b0d2f7a5ffd4..065dd0e53c3b 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp @@ -67,8 +67,8 @@ class InspectorImpl : public IInspector { public: explicit SystemStateListener(InspectorSystemState& state) : state_(state) {} - void onPageAdded(int /*pageId*/) override { - state_.registeredPagesCount++; + void unstable_onHostTargetAdded() override { + state_.registeredHostsCount++; } private: @@ -94,6 +94,7 @@ class InspectorImpl : public IInspector { ConnectFunc connectFunc_; InspectorTargetCapabilities capabilities_; }; + mutable std::mutex mutex_; int nextPageId_{1}; std::map pages_; @@ -142,9 +143,13 @@ int InspectorImpl::addPage( pageId, Page{pageId, description, vm, std::move(connectFunc), capabilities}); - for (const auto& listenerWeak : listeners_) { - if (auto listener = listenerWeak.lock()) { - listener->onPageAdded(pageId); + // Strong assumption: If prefersFuseboxFrontend is set, the page added is a + // HostTarget and not a legacy Hermes runtime target. + if (capabilities.prefersFuseboxFrontend) { + for (const auto& listenerWeak : listeners_) { + if (auto listener = listenerWeak.lock()) { + listener->unstable_onHostTargetAdded(); + } } } diff --git a/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h b/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h index 3117b216ac2d..aa256a4bf7d0 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h @@ -53,7 +53,7 @@ using InspectorPage = InspectorPageDescription; struct InspectorSystemState { /** The total count of pages registered during the app lifetime. */ - int registeredPagesCount; + int registeredHostsCount; }; /// IRemoteConnection allows the VM to send debugger messages to the client. @@ -83,7 +83,7 @@ class JSINSPECTOR_EXPORT ILocalConnection : public IDestructible { class JSINSPECTOR_EXPORT IPageStatusListener : public IDestructible { public: virtual ~IPageStatusListener() = 0; - virtual void onPageAdded(int /*pageId*/) {} + virtual void unstable_onHostTargetAdded() {} virtual void onPageRemoved(int /*pageId*/) {} }; diff --git a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp index 237f625ef547..956f6246c8b7 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp @@ -50,7 +50,7 @@ TracingAgent::~TracingAgent() { bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) { if (req.method == "Tracing.start") { auto& inspector = getInspectorInstance(); - if (inspector.getSystemState().registeredPagesCount > 1) { + if (inspector.getSystemState().registeredHostsCount > 1) { frontendChannel_( cdp::jsonError( req.id,