Skip to content

Commit c800503

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Exclude legacy Hermes targets from single host assertion (facebook#54784)
Summary: Pull Request resolved: facebook#54784 ### Context This is a follow-up to D86201689 following user feedback on `0.83.0-rc.2`: react-native-community/discussions-and-proposals#954 (reply in thread). The problem was that we were incorrectly attributing any and all `IInspector::addPage()` calls to represent a new React Native Host being registered. However, this API also remains common to the legacy Hermes `ConnectionDemux` runtime target setup (which does not represent a host target). ### This diff We now fork this code path internally based on `InspectorTargetCapabilities.prefersFuseboxFrontend`, in order to track `registeredHostsCount` accurately (i.e. **only** for HostTarget page registrations). Changelog: [General][Fixed] - React Native DevTools: Fix a bug where we would incorrectly flag apps using additonal Hermes runtimes (e.g. Reanimated) as being multi-host Reviewed By: hoxyq Differential Revision: D88386623 fbshipit-source-id: 49a82faa6c857de41e8e9a757f5fdd850f09c3dd
1 parent 253fdf4 commit c800503

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

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
@@ -50,7 +50,7 @@ TracingAgent::~TracingAgent() {
5050
bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
5151
if (req.method == "Tracing.start") {
5252
auto& inspector = getInspectorInstance();
53-
if (inspector.getSystemState().registeredPagesCount > 1) {
53+
if (inspector.getSystemState().registeredHostsCount > 1) {
5454
frontendChannel_(
5555
cdp::jsonError(
5656
req.id,

0 commit comments

Comments
 (0)