Skip to content

Commit 30cbe97

Browse files
authored
Exclude legacy Hermes targets from single host assertion (#54790)
1 parent 6227d99 commit 30cbe97

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class HostAgent::Impl final {
147147
if (InspectorFlags::getInstance().getNetworkInspectionEnabled()) {
148148
if (req.method == "Network.enable") {
149149
auto& inspector = getInspectorInstance();
150-
if (inspector.getSystemState().registeredPagesCount > 1) {
150+
if (inspector.getSystemState().registeredHostsCount > 1) {
151151
frontendChannel_(
152152
cdp::jsonError(
153153
req.id,
@@ -231,7 +231,7 @@ class HostAgent::Impl final {
231231
"ReactNativeApplication.metadataUpdated",
232232
createHostMetadataPayload(hostMetadata_)));
233233
auto& inspector = getInspectorInstance();
234-
bool isSingleHost = inspector.getSystemState().registeredPagesCount <= 1;
234+
bool isSingleHost = inspector.getSystemState().registeredHostsCount <= 1;
235235
if (!isSingleHost) {
236236
emitSystemStateChanged(isSingleHost);
237237
}

packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class InspectorImpl : public IInspector {
6767
public:
6868
explicit SystemStateListener(InspectorSystemState& state) : state_(state) {}
6969

70-
void onPageAdded(int /*pageId*/) override {
71-
state_.registeredPagesCount++;
70+
void unstable_onHostTargetAdded() override {
71+
state_.registeredHostsCount++;
7272
}
7373

7474
private:
@@ -94,6 +94,7 @@ class InspectorImpl : public IInspector {
9494
ConnectFunc connectFunc_;
9595
InspectorTargetCapabilities capabilities_;
9696
};
97+
9798
mutable std::mutex mutex_;
9899
int nextPageId_{1};
99100
std::map<int, Page> pages_;
@@ -142,9 +143,13 @@ int InspectorImpl::addPage(
142143
pageId,
143144
Page{pageId, description, vm, std::move(connectFunc), capabilities});
144145

145-
for (const auto& listenerWeak : listeners_) {
146-
if (auto listener = listenerWeak.lock()) {
147-
listener->onPageAdded(pageId);
146+
// Strong assumption: If prefersFuseboxFrontend is set, the page added is a
147+
// HostTarget and not a legacy Hermes runtime target.
148+
if (capabilities.prefersFuseboxFrontend) {
149+
for (const auto& listenerWeak : listeners_) {
150+
if (auto listener = listenerWeak.lock()) {
151+
listener->unstable_onHostTargetAdded();
152+
}
148153
}
149154
}
150155

packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ using InspectorPage = InspectorPageDescription;
5353

5454
struct InspectorSystemState {
5555
/** The total count of pages registered during the app lifetime. */
56-
int registeredPagesCount;
56+
int registeredHostsCount;
5757
};
5858

5959
/// IRemoteConnection allows the VM to send debugger messages to the client.
@@ -83,7 +83,7 @@ class JSINSPECTOR_EXPORT ILocalConnection : public IDestructible {
8383
class JSINSPECTOR_EXPORT IPageStatusListener : public IDestructible {
8484
public:
8585
virtual ~IPageStatusListener() = 0;
86-
virtual void onPageAdded(int /*pageId*/) {}
86+
virtual void unstable_onHostTargetAdded() {}
8787
virtual void onPageRemoved(int /*pageId*/) {}
8888
};
8989

packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TracingAgent::~TracingAgent() {
5454
bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
5555
if (req.method == "Tracing.start") {
5656
auto& inspector = getInspectorInstance();
57-
if (inspector.getSystemState().registeredPagesCount > 1) {
57+
if (inspector.getSystemState().registeredHostsCount > 1) {
5858
frontendChannel_(
5959
cdp::jsonError(
6060
req.id,

0 commit comments

Comments
 (0)