Skip to content

Can't direct debug Hermes when consuming the Microsoft.ReactNative nuget packages #11252

@jonthysell

Description

@jonthysell

Problem Description

In order for Hermes direct debugging to work, the RNW code needs to set up the Hermes Inspector (which connects to Metro for source maps). However the code in Microsoft.ReactNative is #ifdef HERMES_ENABLE_DEBUGGER:

void DevSupportManager::EnsureHermesInspector(
[[maybe_unused]] const std::string &packagerHost,
[[maybe_unused]] const uint16_t packagerPort) noexcept {
#ifdef HERMES_ENABLE_DEBUGGER
static std::once_flag once;
std::call_once(once, [this, &packagerHost, packagerPort]() {
std::string packageName("RNW");
wchar_t fullName[PACKAGE_FULL_NAME_MAX_LENGTH]{};
UINT32 size = ARRAYSIZE(fullName);
if (SUCCEEDED(GetCurrentPackageFullName(&size, fullName))) {
// we are in an unpackaged app
packageName = winrt::to_string(fullName);
}
std::string deviceName("RNWHost");
auto hostNames = winrt::Windows::Networking::Connectivity::NetworkInformation::GetHostNames();
if (hostNames && hostNames.First() && hostNames.First().Current()) {
deviceName = winrt::to_string(hostNames.First().Current().DisplayName());
}
m_inspectorPackagerConnection = std::make_shared<InspectorPackagerConnection>(
facebook::react::DevServerHelper::get_InspectorDeviceUrl(packagerHost, packagerPort, deviceName, packageName),
m_BundleStatusProvider);
m_inspectorPackagerConnection->connectAsync();
});

This compile time flag is set by the targets file for the hermes-windows nuget (when building debug or by setting a property to build in release flavor too):

https://github.com/microsoft/hermes-windows/blob/7606e2f393372b7018a734ac70c4b151ff7929e6/.ado/ReactNative.Hermes.Windows.targets#L26

However this means its only applied when building RNW from source. The RNW nuget packages are built in release flavor.

Note, this is blocked by the fact that you can't even use Hermes with the RNW nugets at all (see #11251) but even if that were fixed, there'd still be extra work to allow direct debugging since it's behind HERMES_ENABLE_DEBUGGER.

Steps To Reproduce

  1. Build a new RNW app with the experimental nugets and hermes
  2. Run the new app with direct debugging enabled

Expected Results

Able to connect a direct debugger.

CLI version

npx react-native --version

Environment

info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.25300
    CPU: (24) x64 AMD Ryzen Threadripper PRO 3945WX 12-Cores
    Memory: 51.33 GB / 63.86 GB
  Binaries:
    Node: 16.15.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
      Versions: 10.0.18362.0, 10.0.19041.0, 10.0.22000.0, 10.0.22621.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.11.33214.272 (Visual Studio Enterprise 2019), 17.4.33213.308 (Visual Studio Enterprise 2022)
  Languages:
    Java: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0
    react-native: 0.71.0 => 0.71.0
    react-native-windows: 0.71.1 => 0.71.1
  npmGlobalPackages:
    *react-native*: Not Found

Target Platform Version

10.0.19041

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

Debug

Snack, code example, screenshot, or link to a repository

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions