Skip to content

Commit 86da8ca

Browse files
authored
Debugger outstanding issues (#15392)
* move string_format to Microsoft::React namespace and * Provide the real process ID to the RuntimeSamplingProfile constructor * remove DevSupportManager::OpenDevTools not needed with modern inspector infra * yarn lint:format and fix * Change files * change files * Revert "change files" This reverts commit d8b0b38. * Change files * improve string_format implementation * remove old sampling profiler * revert IReactDispatcher * resolve nit comments
1 parent e4ec885 commit 86da8ca

17 files changed

+136
-259
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": "fix outstanding modern debugger issues",
4+
"packageName": "react-native-windows",
5+
"email": "74712637+iamAbhi-916@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Desktop.UnitTests/UtilsTest.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,85 @@ TEST_CLASS(UtilsTest)
268268
}
269269

270270
#pragma endregion Base64 Tests
271+
272+
#pragma region FormatString Tests
273+
274+
TEST_METHOD(UtilsTest_StringFormat_Simple)
275+
{
276+
std::string result = Microsoft::React::FormatString("Hello, %s!", "World");
277+
Assert::AreEqual("Hello, World!", result.c_str());
278+
}
279+
280+
TEST_METHOD(UtilsTest_StringFormat_Integer)
281+
{
282+
std::string result = Microsoft::React::FormatString("Port: %d", 8081);
283+
Assert::AreEqual("Port: 8081", result.c_str());
284+
}
285+
286+
TEST_METHOD(UtilsTest_StringFormat_Multiple)
287+
{
288+
std::string result = Microsoft::React::FormatString("%s:%d", "localhost", 8081);
289+
Assert::AreEqual("localhost:8081", result.c_str());
290+
}
291+
292+
TEST_METHOD(UtilsTest_StringFormat_Complex)
293+
{
294+
std::string result = Microsoft::React::FormatString(
295+
"http://%s/%s.bundle?platform=%s&dev=%s&hot=%s",
296+
"localhost:8081",
297+
"index",
298+
"windows",
299+
"true",
300+
"false");
301+
Assert::AreEqual(
302+
"http://localhost:8081/index.bundle?platform=windows&dev=true&hot=false",
303+
result.c_str());
304+
}
305+
306+
TEST_METHOD(UtilsTest_StringFormat_EmptyString)
307+
{
308+
std::string result = Microsoft::React::FormatString("");
309+
Assert::AreEqual("", result.c_str());
310+
}
311+
312+
TEST_METHOD(UtilsTest_StringFormat_NullPtr)
313+
{
314+
std::string result = Microsoft::React::FormatString(nullptr);
315+
Assert::AreEqual("", result.c_str());
316+
}
317+
318+
TEST_METHOD(UtilsTest_StringFormat_NoArgs)
319+
{
320+
std::string result = Microsoft::React::FormatString("no args here");
321+
Assert::AreEqual("no args here", result.c_str());
322+
}
323+
324+
TEST_METHOD(UtilsTest_StringFormat_LargeString)
325+
{
326+
std::string longString(1000, 'a');
327+
std::string result = Microsoft::React::FormatString("%s", longString.c_str());
328+
Assert::AreEqual(longString.c_str(), result.c_str());
329+
}
330+
331+
TEST_METHOD(UtilsTest_StringFormat_MixedTypes)
332+
{
333+
std::string result = Microsoft::React::FormatString(
334+
"Int: %d, Uint: %u, Hex: %x, String: %s, Float: %.2f",
335+
-42,
336+
42u,
337+
255,
338+
"test",
339+
3.14159);
340+
Assert::AreEqual("Int: -42, Uint: 42, Hex: ff, String: test, Float: 3.14", result.c_str());
341+
}
342+
343+
TEST_METHOD(UtilsTest_StringFormat_SpecialChars)
344+
{
345+
std::string result = Microsoft::React::FormatString("100%% complete");
346+
Assert::AreEqual("100% complete", result.c_str());
347+
}
348+
349+
#pragma endregion FormatString Tests
271350
};
272351

273352
// clang-format on

vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ ReactInstanceWin::ReactInstanceWin(
177177
propBag = m_options.Properties,
178178
reactContext = m_reactContext]() noexcept {
179179
whenLoaded.TryCancel(); // It only has an effect if whenLoaded was not set before
180-
Microsoft::ReactNative::HermesRuntimeHolder::storeTo(ReactPropertyBag(reactContext->Properties()), nullptr);
181180
if (onDestroyed) {
182181
onDestroyed.Get()->Invoke(reactContext);
183182
}

vnext/Microsoft.ReactNative/Views/DevMenu.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "DevMenu.h"
77

88
#include <winrt/Windows.ApplicationModel.DataTransfer.h>
9-
#include "Hermes/HermesSamplingProfiler.h"
109
#include "IReactDispatcher.h"
1110
#include "Modules/DevSettingsModule.h"
1211

@@ -68,30 +67,11 @@ void ToggleFastRefresh(Mso::CntPtr<Mso::React::IReactContext> const &reactContex
6867
DevSettings::Reload(React::ReactPropertyBag(reactContext->Properties()));
6968
}
7069

71-
winrt::fire_and_forget ToggleHermesProfiler(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept {
72-
if (!Microsoft::ReactNative::HermesSamplingProfiler::IsStarted()) {
73-
Microsoft::ReactNative::HermesSamplingProfiler::Start(reactContext);
74-
} else {
75-
auto traceFilePath = co_await Microsoft::ReactNative::HermesSamplingProfiler::Stop(reactContext);
76-
auto uiDispatcher = React::implementation::ReactDispatcher::GetUIDispatcher(reactContext->Properties());
77-
uiDispatcher.Post([traceFilePath]() {
78-
DataTransfer::DataPackage data;
79-
data.SetText(winrt::to_hstring(traceFilePath));
80-
DataTransfer::Clipboard::SetContentWithOptions(data, nullptr);
81-
});
82-
}
83-
}
84-
8570
const wchar_t *FastRefreshLabel(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept {
8671
return Mso::React::ReactOptions::UseFastRefresh(reactContext->Properties()) ? L"Disable Fast Refresh"
8772
: L"Enable Fast Refresh";
8873
}
8974

90-
const wchar_t *HermesProfilerLabel(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept {
91-
return !Microsoft::ReactNative::HermesSamplingProfiler::IsStarted() ? L"Start Hermes sampling profiler"
92-
: L"Stop and copy trace path to clipboard";
93-
}
94-
9575
struct WindowsPopupMenuDevMenu : public IDevMenu, public std::enable_shared_from_this<WindowsPopupMenuDevMenu> {
9676
WindowsPopupMenuDevMenu(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) : m_context(reactContext) {}
9777

@@ -127,12 +107,6 @@ struct WindowsPopupMenuDevMenu : public IDevMenu, public std::enable_shared_from
127107
DevSettings::ToggleElementInspector(*context);
128108
}));
129109

130-
if (Mso::React::ReactOptions::JsiEngine(m_context->Properties()) == Mso::React::JSIEngine::Hermes) {
131-
m_menu.Commands().Append(winrt::Windows::UI::Popups::UICommand(
132-
HermesProfilerLabel(m_context),
133-
[context = m_context](winrt::Windows::UI::Popups::IUICommand const &) { ToggleHermesProfiler(context); }));
134-
}
135-
136110
m_menu.ShowAsync({0, 0});
137111
}
138112

vnext/Shared/DevServerHelper.h

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <cxxreact/JSExecutor.h>
7+
#include "Utils.h"
78

89
namespace facebook {
910
namespace react {
@@ -13,13 +14,14 @@ class DevServerHelper {
1314
DevServerHelper() = default;
1415

1516
static std::string get_WebsocketProxyUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
16-
return string_format(WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
17+
return Microsoft::React::FormatString(
18+
WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
1719
}
1820

1921
static std::string get_LaunchDevToolsCommandUrl(
2022
const std::string &sourceBundleHost,
2123
const uint16_t sourceBundlePort) {
22-
return string_format(
24+
return Microsoft::React::FormatString(
2325
LaunchDevToolsCommandUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
2426
}
2527

@@ -36,16 +38,17 @@ class DevServerHelper {
3638
std::string hermesBytecodeVersionQuery;
3739
if (hermesBytecodeVersion > 0) {
3840
static constexpr const char HermesBytecodeVersionQueryFormat[] = "&runtimeBytecodeVersion=%d";
39-
hermesBytecodeVersionQuery = string_format(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion);
41+
hermesBytecodeVersionQuery =
42+
Microsoft::React::FormatString(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion);
4043
}
4144

4245
std::string appIdQuery;
4346
if (bundleAppId.size() > 0) {
4447
static constexpr const char AppIdQueryFormat[] = "&app=%s";
45-
appIdQuery = string_format(AppIdQueryFormat, bundleAppId.c_str());
48+
appIdQuery = Microsoft::React::FormatString(AppIdQueryFormat, bundleAppId.c_str());
4649
}
4750

48-
return string_format(
51+
return Microsoft::React::FormatString(
4952
BundleUrlFormat,
5053
GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str(),
5154
jsbundle.c_str(),
@@ -58,17 +61,19 @@ class DevServerHelper {
5861
}
5962

6063
static std::string get_OnChangeEndpointUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
61-
return string_format(OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
64+
return Microsoft::React::FormatString(
65+
OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
6266
}
6367

6468
static std::string get_PackagerConnectionUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
65-
return string_format(PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
69+
return Microsoft::React::FormatString(
70+
PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
6671
}
6772

6873
static std::string get_PackagerOpenStackFrameUrl(
6974
const std::string &sourceBundleHost,
7075
const uint16_t sourceBundlePort) {
71-
return string_format(
76+
return Microsoft::React::FormatString(
7277
PackagerOpenStackFrameUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
7378
}
7479

@@ -78,7 +83,7 @@ class DevServerHelper {
7883
const std::string &deviceName,
7984
const std::string &packageName,
8085
const std::string &deviceId) {
81-
return string_format(
86+
return Microsoft::React::FormatString(
8287
InspectorDeviceUrlFormat,
8388
GetDeviceLocalHost(packagerHost, packagerPort).c_str(),
8489
deviceName.c_str(),
@@ -88,7 +93,7 @@ class DevServerHelper {
8893

8994
static std::string
9095
get_OpenDebuggerUrl(const std::string &packagerHost, const uint16_t packagerPort, const std::string &deviceId) {
91-
return string_format(
96+
return Microsoft::React::FormatString(
9297
OpenDebuggerUrlFormat, GetDeviceLocalHost(packagerHost, packagerPort).c_str(), deviceId.c_str());
9398
}
9499

@@ -97,7 +102,7 @@ class DevServerHelper {
97102

98103
private:
99104
static std::string GetDeviceLocalHost(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
100-
return string_format(
105+
return Microsoft::React::FormatString(
101106
DeviceLocalHostFormat,
102107
sourceBundleHost.empty() ? DefaultPackagerHost : sourceBundleHost.c_str(),
103108
sourceBundlePort ? sourceBundlePort : DefaultPackagerPort);
@@ -118,15 +123,6 @@ class DevServerHelper {
118123

119124
static constexpr const char PackagerOkStatus[] = "packager-status:running";
120125
const int LongPollFailureDelayMs = 5000;
121-
122-
// TODO: [vmoroz] avoid using vaiadic args for the format and move it to a utility class.
123-
template <typename... Args>
124-
static std::string string_format(const char *format, Args... args) {
125-
size_t size = snprintf(nullptr, 0, format, args...) + 1;
126-
std::unique_ptr<char[]> buf(new char[size]);
127-
snprintf(buf.get(), size, format, args...);
128-
return std::string(buf.get(), buf.get() + size - 1);
129-
}
130126
};
131127

132128
} // namespace react

vnext/Shared/DevSupportManager.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,6 @@ void DevSupportManager::StopPollingLiveReload() {
253253
m_cancellation_token = true;
254254
}
255255

256-
// TODO: (vmoroz) Use or delete this function
257-
void DevSupportManager::OpenDevTools(const std::string &bundleAppId) {
258-
winrt::Windows::Web::Http::Filters::HttpBaseProtocolFilter filter;
259-
filter.CacheControl().ReadBehavior(winrt::Windows::Web::Http::Filters::HttpCacheReadBehavior::NoCache);
260-
winrt::Windows::Web::Http::HttpClient httpClient(filter);
261-
// TODO: Use currently configured dev server host
262-
winrt::Windows::Foundation::Uri uri(
263-
Microsoft::Common::Unicode::Utf8ToUtf16(facebook::react::DevServerHelper::get_OpenDebuggerUrl(
264-
std::string{DevServerHelper::DefaultPackagerHost},
265-
DevServerHelper::DefaultPackagerPort,
266-
GetDeviceId(GetPackageName(bundleAppId)))));
267-
268-
winrt::Windows::Web::Http::HttpRequestMessage request(winrt::Windows::Web::Http::HttpMethod::Post(), uri);
269-
httpClient.SendRequestAsync(request);
270-
}
271-
272256
void DevSupportManager::EnsureInspectorPackagerConnection(
273257
[[maybe_unused]] const std::string &packagerHost,
274258
[[maybe_unused]] const uint16_t packagerPort,

vnext/Shared/DevSupportManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class DevSupportManager final : public facebook::react::IDevSupportManager {
4545
const uint16_t sourceBundlePort,
4646
std::function<void()> onChangeCallback) override;
4747
virtual void StopPollingLiveReload() override;
48-
virtual void OpenDevTools(const std::string &bundleAppId) override;
4948

5049
virtual void EnsureInspectorPackagerConnection(
5150
const std::string &packagerHost,

vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "HermesRuntimeTargetDelegate.h"
1717
#include <jsinspector-modern/RuntimeTarget.h>
18+
#include <windows.h>
1819
#include <utility>
1920
#include "HermesRuntimeAgentDelegate.h"
2021

@@ -268,7 +269,10 @@ tracing::RuntimeSamplingProfile HermesRuntimeTargetDelegate::collectSamplingProf
268269

269270
// Return the complete profile with samples. Wrap the raw profile since it owns the strings.
270271
return tracing::RuntimeSamplingProfile(
271-
"Hermes", 1234, std::move(readerState.samples), std::make_unique<HermesRawRuntimeProfile>(std::move(profile)));
272+
"Hermes",
273+
GetCurrentProcessId(),
274+
std::move(readerState.samples),
275+
std::make_unique<HermesRawRuntimeProfile>(std::move(profile)));
272276
}
273277

274278
} // namespace Microsoft::ReactNative

0 commit comments

Comments
 (0)