Exclude legacy Hermes targets from single host assertion (#54790)

This commit is contained in:
Alex Hunt authored and GitHub committed 2025-12-05 17:52:32 +00:00
1 parent 6227d99c57
commit 30cbe978da
4 files changed
+15 -10

No files matched your search

@@ -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);
}
@@ -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<int, Page> 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();
}
}
}
@@ -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*/) {}
};
@@ -54,7 +54,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,