From f947f76f4c66f1771734e97bbbfcaa381d91076e Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:37:13 +0530 Subject: [PATCH 01/12] move string_format to Microsoft::React namespace and --- vnext/Desktop.UnitTests/UtilsTest.cpp | 73 +++++++++++++++++++++++++++ vnext/Shared/DevServerHelper.h | 32 +++++------- vnext/Shared/Utils.cpp | 25 +++++++++ vnext/Shared/Utils.h | 3 ++ 4 files changed, 113 insertions(+), 20 deletions(-) diff --git a/vnext/Desktop.UnitTests/UtilsTest.cpp b/vnext/Desktop.UnitTests/UtilsTest.cpp index 2899d0592e7..c8625bf3506 100644 --- a/vnext/Desktop.UnitTests/UtilsTest.cpp +++ b/vnext/Desktop.UnitTests/UtilsTest.cpp @@ -268,6 +268,79 @@ TEST_CLASS(UtilsTest) } #pragma endregion Base64 Tests + +#pragma region string_format Tests + + TEST_METHOD(UtilsTest_StringFormat_Simple) + { + auto result = Microsoft::React::string_format("Hello, %s!", "World"); + Assert::AreEqual("Hello, World!", result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_Integer) + { + auto result = Microsoft::React::string_format("Port: %d", 8081); + Assert::AreEqual("Port: 8081", result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_Multiple) + { + auto result = Microsoft::React::string_format("%s:%d", "localhost", 8081); + Assert::AreEqual("localhost:8081", result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_Complex) + { + auto result = Microsoft::React::string_format( + "http://%s/%s.bundle?platform=%s&dev=%s&hot=%s", + "localhost:8081", + "index", + "windows", + "true", + "false"); + Assert::AreEqual( + "http://localhost:8081/index.bundle?platform=windows&dev=true&hot=false", + result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_EmptyString) + { + auto result = Microsoft::React::string_format(""); + Assert::AreEqual("", result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_NoArgs) + { + auto result = Microsoft::React::string_format("no args here"); + Assert::AreEqual("no args here", result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_LargeString) + { + std::string longString(1000, 'a'); + auto result = Microsoft::React::string_format("%s", longString.c_str()); + Assert::AreEqual(longString.c_str(), result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_MixedTypes) + { + auto result = Microsoft::React::string_format( + "Int: %d, Uint: %u, Hex: %x, String: %s, Float: %.2f", + -42, + 42u, + 255, + "test", + 3.14159); + Assert::AreEqual("Int: -42, Uint: 42, Hex: ff, String: test, Float: 3.14", result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_SpecialChars) + { + auto result = Microsoft::React::string_format("100%% complete"); + Assert::AreEqual("100% complete", result.c_str()); + } + +#pragma endregion string_format Tests }; // clang-format on diff --git a/vnext/Shared/DevServerHelper.h b/vnext/Shared/DevServerHelper.h index 9fc4cbcf4d9..68e21f1fef0 100644 --- a/vnext/Shared/DevServerHelper.h +++ b/vnext/Shared/DevServerHelper.h @@ -4,6 +4,7 @@ #pragma once #include +#include "Utils.h" namespace facebook { namespace react { @@ -13,13 +14,13 @@ class DevServerHelper { DevServerHelper() = default; static std::string get_WebsocketProxyUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return string_format(WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); + return Microsoft::React::string_format(WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_LaunchDevToolsCommandUrl( const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return string_format( + return Microsoft::React::string_format( LaunchDevToolsCommandUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } @@ -36,16 +37,16 @@ class DevServerHelper { std::string hermesBytecodeVersionQuery; if (hermesBytecodeVersion > 0) { static constexpr const char HermesBytecodeVersionQueryFormat[] = "&runtimeBytecodeVersion=%d"; - hermesBytecodeVersionQuery = string_format(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion); + hermesBytecodeVersionQuery = Microsoft::React::string_format(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion); } std::string appIdQuery; if (bundleAppId.size() > 0) { static constexpr const char AppIdQueryFormat[] = "&app=%s"; - appIdQuery = string_format(AppIdQueryFormat, bundleAppId.c_str()); + appIdQuery = Microsoft::React::string_format(AppIdQueryFormat, bundleAppId.c_str()); } - return string_format( + return Microsoft::React::string_format( BundleUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str(), jsbundle.c_str(), @@ -58,17 +59,17 @@ class DevServerHelper { } static std::string get_OnChangeEndpointUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return string_format(OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); + return Microsoft::React::string_format(OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_PackagerConnectionUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return string_format(PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); + return Microsoft::React::string_format(PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_PackagerOpenStackFrameUrl( const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return string_format( + return Microsoft::React::string_format( PackagerOpenStackFrameUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } @@ -78,7 +79,7 @@ class DevServerHelper { const std::string &deviceName, const std::string &packageName, const std::string &deviceId) { - return string_format( + return Microsoft::React::string_format( InspectorDeviceUrlFormat, GetDeviceLocalHost(packagerHost, packagerPort).c_str(), deviceName.c_str(), @@ -88,7 +89,7 @@ class DevServerHelper { static std::string get_OpenDebuggerUrl(const std::string &packagerHost, const uint16_t packagerPort, const std::string &deviceId) { - return string_format( + return Microsoft::React::string_format( OpenDebuggerUrlFormat, GetDeviceLocalHost(packagerHost, packagerPort).c_str(), deviceId.c_str()); } @@ -97,7 +98,7 @@ class DevServerHelper { private: static std::string GetDeviceLocalHost(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return string_format( + return Microsoft::React::string_format( DeviceLocalHostFormat, sourceBundleHost.empty() ? DefaultPackagerHost : sourceBundleHost.c_str(), sourceBundlePort ? sourceBundlePort : DefaultPackagerPort); @@ -118,15 +119,6 @@ class DevServerHelper { static constexpr const char PackagerOkStatus[] = "packager-status:running"; const int LongPollFailureDelayMs = 5000; - - // TODO: [vmoroz] avoid using vaiadic args for the format and move it to a utility class. - template - static std::string string_format(const char *format, Args... args) { - size_t size = snprintf(nullptr, 0, format, args...) + 1; - std::unique_ptr buf(new char[size]); - snprintf(buf.get(), size, format, args...); - return std::string(buf.get(), buf.get() + size - 1); - } }; } // namespace react diff --git a/vnext/Shared/Utils.cpp b/vnext/Shared/Utils.cpp index 79c6f3c2249..98c0c1fbcbd 100644 --- a/vnext/Shared/Utils.cpp +++ b/vnext/Shared/Utils.cpp @@ -12,12 +12,37 @@ #include #include +#include +#include using std::string; using winrt::Windows::Foundation::IAsyncOperation; namespace Microsoft::React { +std::string string_format(const char *format, ...) { + va_list args; + va_start(args, format); + + // Get required size + va_list args_copy; + va_copy(args_copy, args); + int size = vsnprintf(nullptr, 0, format, args_copy); + va_end(args_copy); + + if (size < 0) { + va_end(args); + return ""; + } + + // Allocate buffer and format string + std::unique_ptr buf(new char[size + 1]); + vsnprintf(buf.get(), size + 1, format, args); + va_end(args); + + return std::string(buf.get(), size); +} + namespace { IAsyncOperation getPackagedApplicationDataPath(const wchar_t *childFolder) { auto localFolder = winrt::Windows::Storage::ApplicationData::Current().LocalFolder(); diff --git a/vnext/Shared/Utils.h b/vnext/Shared/Utils.h index b62d7912a10..d7b2098a77c 100644 --- a/vnext/Shared/Utils.h +++ b/vnext/Shared/Utils.h @@ -22,4 +22,7 @@ struct Url { winrt::Windows::Foundation::IAsyncOperation getApplicationDataPath(const wchar_t *childfolder); +//string formatting +std::string string_format(_Printf_format_string_ const char *format, ...); + } // namespace Microsoft::React From 5c8b8655f54ddea212fd8471a618cdad93be9fe8 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:37:33 +0530 Subject: [PATCH 02/12] Provide the real process ID to the RuntimeSamplingProfile constructor --- vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp b/vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp index 4e64a6b3e9f..5529483fc95 100644 --- a/vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp +++ b/vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp @@ -17,6 +17,7 @@ #include #include #include "HermesRuntimeAgentDelegate.h" +#include using namespace facebook::react::jsinspector_modern; @@ -268,7 +269,10 @@ tracing::RuntimeSamplingProfile HermesRuntimeTargetDelegate::collectSamplingProf // Return the complete profile with samples. Wrap the raw profile since it owns the strings. return tracing::RuntimeSamplingProfile( - "Hermes", 1234, std::move(readerState.samples), std::make_unique(std::move(profile))); + "Hermes", + GetCurrentProcessId(), + std::move(readerState.samples), + std::make_unique(std::move(profile))); } } // namespace Microsoft::ReactNative From 7f7a070dfd846fc1c5117de7f547b37e2b8dec2c Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:45:21 +0530 Subject: [PATCH 03/12] remove DevSupportManager::OpenDevTools not needed with modern inspector infra --- vnext/Shared/DevSupportManager.cpp | 16 ---------------- vnext/Shared/DevSupportManager.h | 1 - vnext/Shared/IDevSupportManager.h | 1 - 3 files changed, 18 deletions(-) diff --git a/vnext/Shared/DevSupportManager.cpp b/vnext/Shared/DevSupportManager.cpp index 6a57328a22e..ddb16934bb9 100644 --- a/vnext/Shared/DevSupportManager.cpp +++ b/vnext/Shared/DevSupportManager.cpp @@ -253,22 +253,6 @@ void DevSupportManager::StopPollingLiveReload() { m_cancellation_token = true; } -// TODO: (vmoroz) Use or delete this function -void DevSupportManager::OpenDevTools(const std::string &bundleAppId) { - winrt::Windows::Web::Http::Filters::HttpBaseProtocolFilter filter; - filter.CacheControl().ReadBehavior(winrt::Windows::Web::Http::Filters::HttpCacheReadBehavior::NoCache); - winrt::Windows::Web::Http::HttpClient httpClient(filter); - // TODO: Use currently configured dev server host - winrt::Windows::Foundation::Uri uri( - Microsoft::Common::Unicode::Utf8ToUtf16(facebook::react::DevServerHelper::get_OpenDebuggerUrl( - std::string{DevServerHelper::DefaultPackagerHost}, - DevServerHelper::DefaultPackagerPort, - GetDeviceId(GetPackageName(bundleAppId))))); - - winrt::Windows::Web::Http::HttpRequestMessage request(winrt::Windows::Web::Http::HttpMethod::Post(), uri); - httpClient.SendRequestAsync(request); -} - void DevSupportManager::EnsureInspectorPackagerConnection( [[maybe_unused]] const std::string &packagerHost, [[maybe_unused]] const uint16_t packagerPort, diff --git a/vnext/Shared/DevSupportManager.h b/vnext/Shared/DevSupportManager.h index 860839ab531..216bd6c4932 100644 --- a/vnext/Shared/DevSupportManager.h +++ b/vnext/Shared/DevSupportManager.h @@ -45,7 +45,6 @@ class DevSupportManager final : public facebook::react::IDevSupportManager { const uint16_t sourceBundlePort, std::function onChangeCallback) override; virtual void StopPollingLiveReload() override; - virtual void OpenDevTools(const std::string &bundleAppId) override; virtual void EnsureInspectorPackagerConnection( const std::string &packagerHost, diff --git a/vnext/Shared/IDevSupportManager.h b/vnext/Shared/IDevSupportManager.h index e8ab8cc3d20..c9c2f9c7341 100644 --- a/vnext/Shared/IDevSupportManager.h +++ b/vnext/Shared/IDevSupportManager.h @@ -22,7 +22,6 @@ struct IDevSupportManager { const uint16_t sourceBundlePort, std::function onChangeCallback) = 0; virtual void StopPollingLiveReload() = 0; - virtual void OpenDevTools(const std::string &bundleAppId) = 0; virtual void EnsureInspectorPackagerConnection( const std::string &packagerHost, From 46ce64f14998f6d791cc29a567f58ac16af1a588 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:54:34 +0530 Subject: [PATCH 04/12] yarn lint:format and fix --- vnext/Shared/DevServerHelper.h | 12 ++++++++---- vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp | 2 +- vnext/Shared/Utils.cpp | 10 +++++----- vnext/Shared/Utils.h | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/vnext/Shared/DevServerHelper.h b/vnext/Shared/DevServerHelper.h index 68e21f1fef0..617ea22665e 100644 --- a/vnext/Shared/DevServerHelper.h +++ b/vnext/Shared/DevServerHelper.h @@ -14,7 +14,8 @@ class DevServerHelper { DevServerHelper() = default; static std::string get_WebsocketProxyUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format(WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); + return Microsoft::React::string_format( + WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_LaunchDevToolsCommandUrl( @@ -37,7 +38,8 @@ class DevServerHelper { std::string hermesBytecodeVersionQuery; if (hermesBytecodeVersion > 0) { static constexpr const char HermesBytecodeVersionQueryFormat[] = "&runtimeBytecodeVersion=%d"; - hermesBytecodeVersionQuery = Microsoft::React::string_format(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion); + hermesBytecodeVersionQuery = + Microsoft::React::string_format(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion); } std::string appIdQuery; @@ -59,11 +61,13 @@ class DevServerHelper { } static std::string get_OnChangeEndpointUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format(OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); + return Microsoft::React::string_format( + OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_PackagerConnectionUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format(PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); + return Microsoft::React::string_format( + PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_PackagerOpenStackFrameUrl( diff --git a/vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp b/vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp index 5529483fc95..2b28d08d199 100644 --- a/vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp +++ b/vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp @@ -15,9 +15,9 @@ #include "HermesRuntimeTargetDelegate.h" #include +#include #include #include "HermesRuntimeAgentDelegate.h" -#include using namespace facebook::react::jsinspector_modern; diff --git a/vnext/Shared/Utils.cpp b/vnext/Shared/Utils.cpp index 98c0c1fbcbd..a7beea8c93d 100644 --- a/vnext/Shared/Utils.cpp +++ b/vnext/Shared/Utils.cpp @@ -11,9 +11,9 @@ #include #include -#include #include #include +#include using std::string; using winrt::Windows::Foundation::IAsyncOperation; @@ -23,23 +23,23 @@ namespace Microsoft::React { std::string string_format(const char *format, ...) { va_list args; va_start(args, format); - + // Get required size va_list args_copy; va_copy(args_copy, args); int size = vsnprintf(nullptr, 0, format, args_copy); va_end(args_copy); - + if (size < 0) { va_end(args); return ""; } - + // Allocate buffer and format string std::unique_ptr buf(new char[size + 1]); vsnprintf(buf.get(), size + 1, format, args); va_end(args); - + return std::string(buf.get(), size); } diff --git a/vnext/Shared/Utils.h b/vnext/Shared/Utils.h index d7b2098a77c..9722d4d5899 100644 --- a/vnext/Shared/Utils.h +++ b/vnext/Shared/Utils.h @@ -22,7 +22,7 @@ struct Url { winrt::Windows::Foundation::IAsyncOperation getApplicationDataPath(const wchar_t *childfolder); -//string formatting +// string formatting std::string string_format(_Printf_format_string_ const char *format, ...); } // namespace Microsoft::React From 0659d609b95f3e9c984a170cfcd0817c644b2933 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:55:36 +0530 Subject: [PATCH 05/12] Change files --- ...ative-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json diff --git a/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json b/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json new file mode 100644 index 00000000000..0a0c33e6eba --- /dev/null +++ b/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "remove DevSupportManager::OpenDevTools not needed with modern inspector infra", + "packageName": "react-native-windows", + "email": "74712637+iamAbhi-916@users.noreply.github.com", + "dependentChangeType": "patch" +} From d8b0b38536f16e0e2151df405c1486d40ef72da6 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:03:49 +0530 Subject: [PATCH 06/12] change files --- ...tive-windows-b1744349-270c-4117-a1c6-cc55166627e3.json} | 2 +- ...ative-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) rename change/{react-native-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json => react-native-windows-b1744349-270c-4117-a1c6-cc55166627e3.json} (63%) delete mode 100644 change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json diff --git a/change/react-native-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json b/change/react-native-windows-b1744349-270c-4117-a1c6-cc55166627e3.json similarity index 63% rename from change/react-native-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json rename to change/react-native-windows-b1744349-270c-4117-a1c6-cc55166627e3.json index 7d94a647b6e..d0ac986c0b4 100644 --- a/change/react-native-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json +++ b/change/react-native-windows-b1744349-270c-4117-a1c6-cc55166627e3.json @@ -1,6 +1,6 @@ { "type": "prerelease", - "comment": "Add HostTargetMetadata with app name and device name for inspector page naming", + "comment": "solve modern debugger oustanding issues", "packageName": "react-native-windows", "email": "74712637+iamAbhi-916@users.noreply.github.com", "dependentChangeType": "patch" diff --git a/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json b/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json deleted file mode 100644 index 0a0c33e6eba..00000000000 --- a/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "prerelease", - "comment": "remove DevSupportManager::OpenDevTools not needed with modern inspector infra", - "packageName": "react-native-windows", - "email": "74712637+iamAbhi-916@users.noreply.github.com", - "dependentChangeType": "patch" -} From ea76a5bc4b5d3422315f4087a8a434b758e172a0 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:05:25 +0530 Subject: [PATCH 07/12] Revert "change files" This reverts commit d8b0b38536f16e0e2151df405c1486d40ef72da6. --- ...tive-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json} | 2 +- ...ative-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) rename change/{react-native-windows-b1744349-270c-4117-a1c6-cc55166627e3.json => react-native-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json} (63%) create mode 100644 change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json diff --git a/change/react-native-windows-b1744349-270c-4117-a1c6-cc55166627e3.json b/change/react-native-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json similarity index 63% rename from change/react-native-windows-b1744349-270c-4117-a1c6-cc55166627e3.json rename to change/react-native-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json index d0ac986c0b4..7d94a647b6e 100644 --- a/change/react-native-windows-b1744349-270c-4117-a1c6-cc55166627e3.json +++ b/change/react-native-windows-8863778a-7158-453c-abaf-e5c40ed489bc.json @@ -1,6 +1,6 @@ { "type": "prerelease", - "comment": "solve modern debugger oustanding issues", + "comment": "Add HostTargetMetadata with app name and device name for inspector page naming", "packageName": "react-native-windows", "email": "74712637+iamAbhi-916@users.noreply.github.com", "dependentChangeType": "patch" diff --git a/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json b/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json new file mode 100644 index 00000000000..0a0c33e6eba --- /dev/null +++ b/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "remove DevSupportManager::OpenDevTools not needed with modern inspector infra", + "packageName": "react-native-windows", + "email": "74712637+iamAbhi-916@users.noreply.github.com", + "dependentChangeType": "patch" +} From 9234cb1f08d4bcf4f0fb78760d65534dd97b5852 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:07:46 +0530 Subject: [PATCH 08/12] Change files --- ...act-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json b/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json index 0a0c33e6eba..bb18b2b3b0e 100644 --- a/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json +++ b/change/react-native-windows-f1eeb076-2cad-486c-88ba-7d9f68b8fc3a.json @@ -1,6 +1,6 @@ { "type": "prerelease", - "comment": "remove DevSupportManager::OpenDevTools not needed with modern inspector infra", + "comment": "fix outstanding modern debugger issues", "packageName": "react-native-windows", "email": "74712637+iamAbhi-916@users.noreply.github.com", "dependentChangeType": "patch" From 688119466a18254c6e2b2c2c22aa62eec03ec95e Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Fri, 21 Nov 2025 11:42:58 +0530 Subject: [PATCH 09/12] improve string_format implementation --- vnext/Shared/Utils.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/vnext/Shared/Utils.cpp b/vnext/Shared/Utils.cpp index a7beea8c93d..01c4ef8b615 100644 --- a/vnext/Shared/Utils.cpp +++ b/vnext/Shared/Utils.cpp @@ -12,7 +12,6 @@ #include #include -#include #include using std::string; @@ -35,12 +34,10 @@ std::string string_format(const char *format, ...) { return ""; } - // Allocate buffer and format string - std::unique_ptr buf(new char[size + 1]); - vsnprintf(buf.get(), size + 1, format, args); + std::string result(size, '\0'); + vsnprintf(result.data(), size + 1, format, args); va_end(args); - - return std::string(buf.get(), size); + return result; } namespace { From 002a7d2cf38ce8ef6cf5a2c817e434088fb761fe Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Fri, 21 Nov 2025 16:26:44 +0530 Subject: [PATCH 10/12] remove old sampling profiler --- .../IReactDispatcher.cpp | 4 - .../Microsoft.ReactNative/IReactDispatcher.h | 1 - .../ReactHost/ReactInstanceWin.cpp | 1 - vnext/Microsoft.ReactNative/Views/DevMenu.cpp | 26 ---- .../Shared/Hermes/HermesSamplingProfiler.cpp | 114 ------------------ vnext/Shared/Hermes/HermesSamplingProfiler.h | 26 ---- vnext/Shared/HermesRuntimeHolder.cpp | 31 ----- vnext/Shared/HermesRuntimeHolder.h | 14 --- vnext/Shared/Shared.vcxitems | 2 - vnext/Shared/Shared.vcxitems.filters | 6 - 10 files changed, 225 deletions(-) delete mode 100644 vnext/Shared/Hermes/HermesSamplingProfiler.cpp delete mode 100644 vnext/Shared/Hermes/HermesSamplingProfiler.h diff --git a/vnext/Microsoft.ReactNative/IReactDispatcher.cpp b/vnext/Microsoft.ReactNative/IReactDispatcher.cpp index 5787721515c..e45aa59eb71 100644 --- a/vnext/Microsoft.ReactNative/IReactDispatcher.cpp +++ b/vnext/Microsoft.ReactNative/IReactDispatcher.cpp @@ -124,10 +124,6 @@ void ReactDispatcher::InvokeElsePost(Mso::DispatchTask &&task) const noexcept { return jsThreadDispatcherProperty; } -/*static*/ IReactDispatcher ReactDispatcher::GetJSDispatcher(IReactPropertyBag const &properties) noexcept { - return properties.Get(JSDispatcherProperty()).try_as(); -} - /*static*/ IReactPropertyName ReactDispatcher::JSDispatcherTaskStartingEventName() noexcept { static IReactPropertyName jsThreadDispatcherProperty{ReactPropertyBagHelper::GetName( ReactPropertyBagHelper::GetNamespace(L"ReactNative.Dispatcher"), L"JSDispatcherTaskStartingEventName")}; diff --git a/vnext/Microsoft.ReactNative/IReactDispatcher.h b/vnext/Microsoft.ReactNative/IReactDispatcher.h index 52e749b782b..f13cfb0b4b4 100644 --- a/vnext/Microsoft.ReactNative/IReactDispatcher.h +++ b/vnext/Microsoft.ReactNative/IReactDispatcher.h @@ -38,7 +38,6 @@ struct ReactDispatcher : implementsProperties()), nullptr); if (onDestroyed) { onDestroyed.Get()->Invoke(reactContext); } diff --git a/vnext/Microsoft.ReactNative/Views/DevMenu.cpp b/vnext/Microsoft.ReactNative/Views/DevMenu.cpp index 598a421935f..b90c364b6e1 100644 --- a/vnext/Microsoft.ReactNative/Views/DevMenu.cpp +++ b/vnext/Microsoft.ReactNative/Views/DevMenu.cpp @@ -6,7 +6,6 @@ #include "DevMenu.h" #include -#include "Hermes/HermesSamplingProfiler.h" #include "IReactDispatcher.h" #include "Modules/DevSettingsModule.h" @@ -68,30 +67,11 @@ void ToggleFastRefresh(Mso::CntPtr const &reactContex DevSettings::Reload(React::ReactPropertyBag(reactContext->Properties())); } -winrt::fire_and_forget ToggleHermesProfiler(Mso::CntPtr const &reactContext) noexcept { - if (!Microsoft::ReactNative::HermesSamplingProfiler::IsStarted()) { - Microsoft::ReactNative::HermesSamplingProfiler::Start(reactContext); - } else { - auto traceFilePath = co_await Microsoft::ReactNative::HermesSamplingProfiler::Stop(reactContext); - auto uiDispatcher = React::implementation::ReactDispatcher::GetUIDispatcher(reactContext->Properties()); - uiDispatcher.Post([traceFilePath]() { - DataTransfer::DataPackage data; - data.SetText(winrt::to_hstring(traceFilePath)); - DataTransfer::Clipboard::SetContentWithOptions(data, nullptr); - }); - } -} - const wchar_t *FastRefreshLabel(Mso::CntPtr const &reactContext) noexcept { return Mso::React::ReactOptions::UseFastRefresh(reactContext->Properties()) ? L"Disable Fast Refresh" : L"Enable Fast Refresh"; } -const wchar_t *HermesProfilerLabel(Mso::CntPtr const &reactContext) noexcept { - return !Microsoft::ReactNative::HermesSamplingProfiler::IsStarted() ? L"Start Hermes sampling profiler" - : L"Stop and copy trace path to clipboard"; -} - struct WindowsPopupMenuDevMenu : public IDevMenu, public std::enable_shared_from_this { WindowsPopupMenuDevMenu(Mso::CntPtr const &reactContext) : m_context(reactContext) {} @@ -127,12 +107,6 @@ struct WindowsPopupMenuDevMenu : public IDevMenu, public std::enable_shared_from DevSettings::ToggleElementInspector(*context); })); - if (Mso::React::ReactOptions::JsiEngine(m_context->Properties()) == Mso::React::JSIEngine::Hermes) { - m_menu.Commands().Append(winrt::Windows::UI::Popups::UICommand( - HermesProfilerLabel(m_context), - [context = m_context](winrt::Windows::UI::Popups::IUICommand const &) { ToggleHermesProfiler(context); })); - } - m_menu.ShowAsync({0, 0}); } diff --git a/vnext/Shared/Hermes/HermesSamplingProfiler.cpp b/vnext/Shared/Hermes/HermesSamplingProfiler.cpp deleted file mode 100644 index d2fddb83334..00000000000 --- a/vnext/Shared/Hermes/HermesSamplingProfiler.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#include "pch.h" - -#include -#include -#include - -#include "HermesRuntimeHolder.h" -#include "HermesSamplingProfiler.h" -#include "IReactDispatcher.h" -#include "ReactPropertyBag.h" -#include "Utils.h" - -using namespace facebook::react; -using namespace winrt::Microsoft::ReactNative; -using namespace winrt::Windows::Foundation; - -namespace Microsoft::ReactNative { - -namespace { - -// Implements an awaiter for Mso::DispatchQueue -auto resume_in_dispatcher(const IReactDispatcher &dispatcher) noexcept { - struct awaitable { - awaitable(const IReactDispatcher &dispatcher) noexcept : dispatcher_(dispatcher) {} - - bool await_ready() const noexcept { - return false; - } - - void await_resume() const noexcept {} - - void await_suspend(std::experimental::coroutine_handle<> resume) noexcept { - callback_ = [context = resume.address()]() noexcept { - std::experimental::coroutine_handle<>::from_address(context)(); - }; - dispatcher_.Post(std::move(callback_)); - } - - private: - IReactDispatcher dispatcher_; - ReactDispatcherCallback callback_; - }; - - return awaitable{dispatcher}; -} - -IAsyncOperation getTraceFilePath() noexcept { - winrt::hstring hermesDataPath = co_await Microsoft::React::getApplicationDataPath(L"Hermes"); - std::wostringstream os; - auto now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) - .count(); - - os << hermesDataPath.c_str() << L"\\cpu_" << now << L".cpuprofile"; - co_return winrt::hstring(os.view()); -} - -} // namespace - -std::atomic_bool HermesSamplingProfiler::s_isStarted{false}; -winrt::hstring HermesSamplingProfiler::s_lastTraceFilePath; - -winrt::hstring HermesSamplingProfiler::GetLastTraceFilePath() noexcept { - return s_lastTraceFilePath; -} - -winrt::fire_and_forget HermesSamplingProfiler::Start( - Mso::CntPtr const &reactContext) noexcept { - bool expectedIsStarted = false; - if (s_isStarted.compare_exchange_strong(expectedIsStarted, true)) { - IReactDispatcher jsDispatcher = implementation::ReactDispatcher::GetJSDispatcher(reactContext->Properties()); - ReactPropertyBag propertyBag = ReactPropertyBag(reactContext->Properties()); - - co_await resume_in_dispatcher(jsDispatcher); - std::shared_ptr hermesRuntimeHolder = HermesRuntimeHolder::loadFrom(propertyBag); - hermesRuntimeHolder->addToProfiling(); - - co_await winrt::resume_background(); - HermesRuntimeHolder::enableSamplingProfiler(); - } - - co_return; -} - -IAsyncOperation HermesSamplingProfiler::Stop( - Mso::CntPtr const &reactContext) noexcept { - bool expectedIsStarted = true; - if (s_isStarted.compare_exchange_strong(expectedIsStarted, false)) { - IReactDispatcher jsDispatcher = implementation::ReactDispatcher::GetJSDispatcher(reactContext->Properties()); - ReactPropertyBag propertyBag = ReactPropertyBag(reactContext->Properties()); - - co_await winrt::resume_background(); - HermesRuntimeHolder::disableSamplingProfiler(); - - s_lastTraceFilePath = co_await getTraceFilePath(); - HermesRuntimeHolder::dumpSampledTraceToFile(winrt::to_string(s_lastTraceFilePath)); - - co_await resume_in_dispatcher(jsDispatcher); - std::shared_ptr hermesRuntimeHolder = HermesRuntimeHolder::loadFrom(propertyBag); - hermesRuntimeHolder->removeFromProfiling(); - - co_await winrt::resume_background(); - } - - co_return s_lastTraceFilePath; -} - -bool HermesSamplingProfiler::IsStarted() noexcept { - return s_isStarted.load(); -} - -} // namespace Microsoft::ReactNative diff --git a/vnext/Shared/Hermes/HermesSamplingProfiler.h b/vnext/Shared/Hermes/HermesSamplingProfiler.h deleted file mode 100644 index fa2fcaf529b..00000000000 --- a/vnext/Shared/Hermes/HermesSamplingProfiler.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#include -#include -#include -#include - -namespace Microsoft::ReactNative { - -class HermesSamplingProfiler final { - public: - static winrt::fire_and_forget Start(Mso::CntPtr const &reactContext) noexcept; - static winrt::Windows::Foundation::IAsyncOperation Stop( - Mso::CntPtr const &reactContext) noexcept; - static winrt::hstring GetLastTraceFilePath() noexcept; - static bool IsStarted() noexcept; - - private: - static std::atomic_bool s_isStarted; - static winrt::hstring s_lastTraceFilePath; -}; - -} // namespace Microsoft::ReactNative diff --git a/vnext/Shared/HermesRuntimeHolder.cpp b/vnext/Shared/HermesRuntimeHolder.cpp index 8c0b45790f1..bca82091a19 100644 --- a/vnext/Shared/HermesRuntimeHolder.cpp +++ b/vnext/Shared/HermesRuntimeHolder.cpp @@ -319,37 +319,6 @@ void HermesRuntimeHolder::crashHandler(int fileDescriptor) noexcept { CRASH_ON_ERROR(getHermesApi().hermes_dump_crash_data(m_runtime, fileDescriptor)); } -std::shared_ptr HermesRuntimeHolder::loadFrom( - React::ReactPropertyBag const &propertyBag) noexcept { - return *(propertyBag.Get(HermesRuntimeHolderProperty())); -} - -void HermesRuntimeHolder::storeTo( - React::ReactPropertyBag const &propertyBag, - std::shared_ptr const &holder) noexcept { - propertyBag.Set(HermesRuntimeHolderProperty(), holder); -} - -void HermesRuntimeHolder::addToProfiling() const noexcept { - CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_add(m_runtime)); -} - -void HermesRuntimeHolder::removeFromProfiling() const noexcept { - CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_remove(m_runtime)); -} - -/*static*/ void HermesRuntimeHolder::enableSamplingProfiler() noexcept { - CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_enable()); -} - -/*static*/ void HermesRuntimeHolder::disableSamplingProfiler() noexcept { - CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_disable()); -} - -/*static*/ void HermesRuntimeHolder::dumpSampledTraceToFile(const std::string &fileName) noexcept { - CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_dump_to_file(fileName.c_str())); -} - hermes_runtime HermesRuntimeHolder::getHermesRuntime() noexcept { return reinterpret_cast(m_runtime); } diff --git a/vnext/Shared/HermesRuntimeHolder.h b/vnext/Shared/HermesRuntimeHolder.h index d30f4b8ac23..b7111cfde67 100644 --- a/vnext/Shared/HermesRuntimeHolder.h +++ b/vnext/Shared/HermesRuntimeHolder.h @@ -231,20 +231,6 @@ class HermesRuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit, std::shared_ptr createRuntimeTargetDelegate() override; - static std::shared_ptr loadFrom( - winrt::Microsoft::ReactNative::ReactPropertyBag const &propertyBag) noexcept; - - static void storeTo( - winrt::Microsoft::ReactNative::ReactPropertyBag const &propertyBag, - std::shared_ptr const &holder) noexcept; - - void addToProfiling() const noexcept; - void removeFromProfiling() const noexcept; - - static void enableSamplingProfiler() noexcept; - static void disableSamplingProfiler() noexcept; - static void dumpSampledTraceToFile(const std::string &fileName) noexcept; - hermes_runtime getHermesRuntime() noexcept; private: diff --git a/vnext/Shared/Shared.vcxitems b/vnext/Shared/Shared.vcxitems index 3568b832da0..c10a07a1cdd 100644 --- a/vnext/Shared/Shared.vcxitems +++ b/vnext/Shared/Shared.vcxitems @@ -153,7 +153,6 @@ - @@ -315,7 +314,6 @@ - diff --git a/vnext/Shared/Shared.vcxitems.filters b/vnext/Shared/Shared.vcxitems.filters index ab85279f9c2..97a569d3f85 100644 --- a/vnext/Shared/Shared.vcxitems.filters +++ b/vnext/Shared/Shared.vcxitems.filters @@ -313,9 +313,6 @@ Hermes - - Hermes - Inspector @@ -774,9 +771,6 @@ Hermes - - Hermes - Inspector From 58bd9d586eb53da5234fb22e68453594c0caa0d9 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Tue, 25 Nov 2025 20:15:54 +0530 Subject: [PATCH 11/12] revert IReactDispatcher --- vnext/Microsoft.ReactNative/IReactDispatcher.cpp | 4 ++++ vnext/Microsoft.ReactNative/IReactDispatcher.h | 1 + 2 files changed, 5 insertions(+) diff --git a/vnext/Microsoft.ReactNative/IReactDispatcher.cpp b/vnext/Microsoft.ReactNative/IReactDispatcher.cpp index e45aa59eb71..5787721515c 100644 --- a/vnext/Microsoft.ReactNative/IReactDispatcher.cpp +++ b/vnext/Microsoft.ReactNative/IReactDispatcher.cpp @@ -124,6 +124,10 @@ void ReactDispatcher::InvokeElsePost(Mso::DispatchTask &&task) const noexcept { return jsThreadDispatcherProperty; } +/*static*/ IReactDispatcher ReactDispatcher::GetJSDispatcher(IReactPropertyBag const &properties) noexcept { + return properties.Get(JSDispatcherProperty()).try_as(); +} + /*static*/ IReactPropertyName ReactDispatcher::JSDispatcherTaskStartingEventName() noexcept { static IReactPropertyName jsThreadDispatcherProperty{ReactPropertyBagHelper::GetName( ReactPropertyBagHelper::GetNamespace(L"ReactNative.Dispatcher"), L"JSDispatcherTaskStartingEventName")}; diff --git a/vnext/Microsoft.ReactNative/IReactDispatcher.h b/vnext/Microsoft.ReactNative/IReactDispatcher.h index f13cfb0b4b4..52e749b782b 100644 --- a/vnext/Microsoft.ReactNative/IReactDispatcher.h +++ b/vnext/Microsoft.ReactNative/IReactDispatcher.h @@ -38,6 +38,7 @@ struct ReactDispatcher : implements Date: Tue, 25 Nov 2025 20:29:54 +0530 Subject: [PATCH 12/12] resolve nit comments --- vnext/Desktop.UnitTests/UtilsTest.cpp | 28 ++++++++++++++++----------- vnext/Shared/DevServerHelper.h | 22 ++++++++++----------- vnext/Shared/Utils.cpp | 6 +++++- vnext/Shared/Utils.h | 2 +- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/vnext/Desktop.UnitTests/UtilsTest.cpp b/vnext/Desktop.UnitTests/UtilsTest.cpp index c8625bf3506..76ae83f5098 100644 --- a/vnext/Desktop.UnitTests/UtilsTest.cpp +++ b/vnext/Desktop.UnitTests/UtilsTest.cpp @@ -269,29 +269,29 @@ TEST_CLASS(UtilsTest) #pragma endregion Base64 Tests -#pragma region string_format Tests +#pragma region FormatString Tests TEST_METHOD(UtilsTest_StringFormat_Simple) { - auto result = Microsoft::React::string_format("Hello, %s!", "World"); + std::string result = Microsoft::React::FormatString("Hello, %s!", "World"); Assert::AreEqual("Hello, World!", result.c_str()); } TEST_METHOD(UtilsTest_StringFormat_Integer) { - auto result = Microsoft::React::string_format("Port: %d", 8081); + std::string result = Microsoft::React::FormatString("Port: %d", 8081); Assert::AreEqual("Port: 8081", result.c_str()); } TEST_METHOD(UtilsTest_StringFormat_Multiple) { - auto result = Microsoft::React::string_format("%s:%d", "localhost", 8081); + std::string result = Microsoft::React::FormatString("%s:%d", "localhost", 8081); Assert::AreEqual("localhost:8081", result.c_str()); } TEST_METHOD(UtilsTest_StringFormat_Complex) { - auto result = Microsoft::React::string_format( + std::string result = Microsoft::React::FormatString( "http://%s/%s.bundle?platform=%s&dev=%s&hot=%s", "localhost:8081", "index", @@ -305,26 +305,32 @@ TEST_CLASS(UtilsTest) TEST_METHOD(UtilsTest_StringFormat_EmptyString) { - auto result = Microsoft::React::string_format(""); + std::string result = Microsoft::React::FormatString(""); + Assert::AreEqual("", result.c_str()); + } + + TEST_METHOD(UtilsTest_StringFormat_NullPtr) + { + std::string result = Microsoft::React::FormatString(nullptr); Assert::AreEqual("", result.c_str()); } TEST_METHOD(UtilsTest_StringFormat_NoArgs) { - auto result = Microsoft::React::string_format("no args here"); + std::string result = Microsoft::React::FormatString("no args here"); Assert::AreEqual("no args here", result.c_str()); } TEST_METHOD(UtilsTest_StringFormat_LargeString) { std::string longString(1000, 'a'); - auto result = Microsoft::React::string_format("%s", longString.c_str()); + std::string result = Microsoft::React::FormatString("%s", longString.c_str()); Assert::AreEqual(longString.c_str(), result.c_str()); } TEST_METHOD(UtilsTest_StringFormat_MixedTypes) { - auto result = Microsoft::React::string_format( + std::string result = Microsoft::React::FormatString( "Int: %d, Uint: %u, Hex: %x, String: %s, Float: %.2f", -42, 42u, @@ -336,11 +342,11 @@ TEST_CLASS(UtilsTest) TEST_METHOD(UtilsTest_StringFormat_SpecialChars) { - auto result = Microsoft::React::string_format("100%% complete"); + std::string result = Microsoft::React::FormatString("100%% complete"); Assert::AreEqual("100% complete", result.c_str()); } -#pragma endregion string_format Tests +#pragma endregion FormatString Tests }; // clang-format on diff --git a/vnext/Shared/DevServerHelper.h b/vnext/Shared/DevServerHelper.h index 617ea22665e..e61b0c89452 100644 --- a/vnext/Shared/DevServerHelper.h +++ b/vnext/Shared/DevServerHelper.h @@ -14,14 +14,14 @@ class DevServerHelper { DevServerHelper() = default; static std::string get_WebsocketProxyUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format( + return Microsoft::React::FormatString( WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_LaunchDevToolsCommandUrl( const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format( + return Microsoft::React::FormatString( LaunchDevToolsCommandUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } @@ -39,16 +39,16 @@ class DevServerHelper { if (hermesBytecodeVersion > 0) { static constexpr const char HermesBytecodeVersionQueryFormat[] = "&runtimeBytecodeVersion=%d"; hermesBytecodeVersionQuery = - Microsoft::React::string_format(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion); + Microsoft::React::FormatString(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion); } std::string appIdQuery; if (bundleAppId.size() > 0) { static constexpr const char AppIdQueryFormat[] = "&app=%s"; - appIdQuery = Microsoft::React::string_format(AppIdQueryFormat, bundleAppId.c_str()); + appIdQuery = Microsoft::React::FormatString(AppIdQueryFormat, bundleAppId.c_str()); } - return Microsoft::React::string_format( + return Microsoft::React::FormatString( BundleUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str(), jsbundle.c_str(), @@ -61,19 +61,19 @@ class DevServerHelper { } static std::string get_OnChangeEndpointUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format( + return Microsoft::React::FormatString( OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_PackagerConnectionUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format( + return Microsoft::React::FormatString( PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } static std::string get_PackagerOpenStackFrameUrl( const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format( + return Microsoft::React::FormatString( PackagerOpenStackFrameUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str()); } @@ -83,7 +83,7 @@ class DevServerHelper { const std::string &deviceName, const std::string &packageName, const std::string &deviceId) { - return Microsoft::React::string_format( + return Microsoft::React::FormatString( InspectorDeviceUrlFormat, GetDeviceLocalHost(packagerHost, packagerPort).c_str(), deviceName.c_str(), @@ -93,7 +93,7 @@ class DevServerHelper { static std::string get_OpenDebuggerUrl(const std::string &packagerHost, const uint16_t packagerPort, const std::string &deviceId) { - return Microsoft::React::string_format( + return Microsoft::React::FormatString( OpenDebuggerUrlFormat, GetDeviceLocalHost(packagerHost, packagerPort).c_str(), deviceId.c_str()); } @@ -102,7 +102,7 @@ class DevServerHelper { private: static std::string GetDeviceLocalHost(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) { - return Microsoft::React::string_format( + return Microsoft::React::FormatString( DeviceLocalHostFormat, sourceBundleHost.empty() ? DefaultPackagerHost : sourceBundleHost.c_str(), sourceBundlePort ? sourceBundlePort : DefaultPackagerPort); diff --git a/vnext/Shared/Utils.cpp b/vnext/Shared/Utils.cpp index 01c4ef8b615..93ea7224ede 100644 --- a/vnext/Shared/Utils.cpp +++ b/vnext/Shared/Utils.cpp @@ -19,7 +19,11 @@ using winrt::Windows::Foundation::IAsyncOperation; namespace Microsoft::React { -std::string string_format(const char *format, ...) { +std::string FormatString(const char *format, ...) { + if (format == nullptr) { + return ""; + } + va_list args; va_start(args, format); diff --git a/vnext/Shared/Utils.h b/vnext/Shared/Utils.h index 9722d4d5899..81e4e1d5576 100644 --- a/vnext/Shared/Utils.h +++ b/vnext/Shared/Utils.h @@ -23,6 +23,6 @@ struct Url { winrt::Windows::Foundation::IAsyncOperation getApplicationDataPath(const wchar_t *childfolder); // string formatting -std::string string_format(_Printf_format_string_ const char *format, ...); +std::string FormatString(_Printf_format_string_ const char *format, ...); } // namespace Microsoft::React