Skip to content

Commit c0d8888

Browse files
authored
Improve the inspector page name for modern debugger (#15375)
* visual studio 2026 strict check fix * Add HostTargetMetadata with app name and device name for inspector page naming * lint:fix * Change files * revert VS 2026 strict checks fix * review comments
1 parent 10f7e9f commit c0d8888

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Add HostTargetMetadata with app name and device name for inspector page naming",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/ReactHost/ReactHost.cpp

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,32 @@ class ReactInspectorHostTargetDelegate : public jsinspector_modern::HostTargetDe
285285
ReactInspectorHostTargetDelegate(Mso::WeakPtr<ReactHost> &&reactHost) noexcept : m_reactHost(std::move(reactHost)) {}
286286

287287
jsinspector_modern::HostTargetMetadata getMetadata() override {
288-
// TODO: (vmoroz) provide more info
289-
return {
290-
.integrationName = "React Native Windows (Host)",
291-
};
288+
jsinspector_modern::HostTargetMetadata metadata{};
289+
metadata.integrationName = "React Native Windows (Host)";
290+
metadata.platform = "windows";
291+
292+
if (Mso::CntPtr<ReactHost> reactHost = m_reactHost.GetStrongPtr()) {
293+
const ReactOptions &options = reactHost->Options();
294+
if (!options.Identity.empty()) {
295+
std::string identity = options.Identity;
296+
// Replace illegal characters with underscore
297+
for (char &c : identity) {
298+
if (c == '\\' || c == '/' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' ||
299+
c == '|') {
300+
c = '_';
301+
}
302+
}
303+
metadata.appDisplayName = identity;
304+
}
305+
}
306+
307+
wchar_t computerName[MAX_COMPUTERNAME_LENGTH + 1];
308+
DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
309+
if (GetComputerNameW(computerName, &size)) {
310+
metadata.deviceName = winrt::to_string(computerName);
311+
}
312+
313+
return metadata;
292314
}
293315

294316
void onReload(jsinspector_modern::HostTargetDelegate::PageReloadRequest const &request) override {
@@ -589,9 +611,20 @@ void ReactHost::AddInspectorPage() noexcept {
589611
jsinspector_modern::InspectorTargetCapabilities capabilities;
590612
capabilities.nativePageReloads = true;
591613
capabilities.prefersFuseboxFrontend = true;
592-
// TODO: (vmoroz) improve the page name
614+
615+
auto metadata = m_inspectorHostTargetDelegate->getMetadata();
616+
std::string pageName;
617+
if (metadata.appDisplayName.has_value() && !metadata.appDisplayName.value().empty()) {
618+
pageName = metadata.appDisplayName.value();
619+
} else {
620+
pageName = "React Native Windows (Experimental)";
621+
}
622+
if (metadata.deviceName.has_value() && !metadata.deviceName.value().empty()) {
623+
pageName += " (" + metadata.deviceName.value() + ")";
624+
}
625+
593626
inspectorPageId = jsinspector_modern::getInspectorInstance().addPage(
594-
"React Native Windows (Experimental)",
627+
pageName,
595628
"Hermes",
596629
[weakInspectorHostTarget =
597630
std::weak_ptr(m_inspectorHostTarget)](std::unique_ptr<jsinspector_modern::IRemoteConnection> remote)

vnext/src-win/src/private/specs_DEPRECATED/components/Xaml/XamlHostNativeComponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
'use strict';
99

10-
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
11-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
10+
import type {ViewProps} from 'react-native';
11+
import {codegenNativeComponent} from 'react-native';
1212
import type {HostComponent} from '../../../../../src/private/types/HostComponent';
1313

1414
type XamlHostProps = $ReadOnly<{|

0 commit comments

Comments
 (0)