From 68884ff751f9ff232433ca9580bfac770c7564e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar=20Rocha?= Date: Tue, 10 Oct 2023 15:24:18 -0700 Subject: [PATCH 1/3] Conditionally register WebSocket Cxx module (#12218) * Conditionally register WebSocket Cxx module * Change files --- ...tive-windows-a292054c-e016-4f31-bb25-3808d092176b.json | 7 +++++++ .../Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp | 3 +++ vnext/Shared/DevSettings.h | 3 +++ vnext/Shared/OInstance.cpp | 8 ++++++-- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 change/react-native-windows-a292054c-e016-4f31-bb25-3808d092176b.json diff --git a/change/react-native-windows-a292054c-e016-4f31-bb25-3808d092176b.json b/change/react-native-windows-a292054c-e016-4f31-bb25-3808d092176b.json new file mode 100644 index 00000000000..cdbeb3250de --- /dev/null +++ b/change/react-native-windows-a292054c-e016-4f31-bb25-3808d092176b.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Conditionally register WebSocket Cxx module", + "packageName": "react-native-windows", + "email": "julio.rocha@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp b/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp index a028cb58ced..02af471c1b0 100644 --- a/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +++ b/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp @@ -567,6 +567,9 @@ void ReactInstanceWin::Initialize() noexcept { auto omitNetCxxPropName = ReactPropertyBagHelper::GetName(nullptr, L"OmitNetworkingCxxModules"); auto omitNetCxxPropValue = m_options.Properties.Get(omitNetCxxPropName); devSettings->omitNetworkingCxxModules = winrt::unbox_value_or(omitNetCxxPropValue, false); + auto useWebSocketTurboModulePropName = ReactPropertyBagHelper::GetName(nullptr, L"UseWebSocketTurboModule"); + auto useWebSocketTurboModulePropValue = m_options.Properties.Get(useWebSocketTurboModulePropName); + devSettings->useWebSocketTurboModule = winrt::unbox_value_or(useWebSocketTurboModulePropValue, false); auto bundleRootPath = devSettings->bundleRootPath; auto instanceWrapper = facebook::react::CreateReactInstance( std::shared_ptr(strongThis->m_instance.Load()), diff --git a/vnext/Shared/DevSettings.h b/vnext/Shared/DevSettings.h index 12d3137a913..3e98095ceff 100644 --- a/vnext/Shared/DevSettings.h +++ b/vnext/Shared/DevSettings.h @@ -102,6 +102,9 @@ struct DevSettings { // Transitory. Used to indicate whether or not to load networking types in the default Cxx module registry. bool omitNetworkingCxxModules{false}; + + // OC:8368383 - Memory leak under investigation. + bool useWebSocketTurboModule{false}; }; } // namespace react diff --git a/vnext/Shared/OInstance.cpp b/vnext/Shared/OInstance.cpp index 920fdaef7e1..a5b9a259aa7 100644 --- a/vnext/Shared/OInstance.cpp +++ b/vnext/Shared/OInstance.cpp @@ -556,14 +556,18 @@ std::vector> InstanceImpl::GetDefaultNativeModules // If this code is enabled, we will have unused module instances. // Also, MSRN has a different property bag mechanism incompatible with this method's transitionalProps variable. #if (defined(_MSC_VER) && !defined(WINRT)) - // Applications using the Windows ABI feature should loade the networking TurboModule variants instead. - if (!m_devSettings->omitNetworkingCxxModules) { + + // OC:8368383 - Memory leak under investigation. + if (!m_devSettings->useWebSocketTurboModule) { modules.push_back(std::make_unique( m_innerInstance, Microsoft::React::GetWebSocketModuleName(), [transitionalProps]() { return Microsoft::React::CreateWebSocketModule(transitionalProps); }, nativeQueue)); + } + // Applications using the Windows ABI feature should loade the networking TurboModule variants instead. + if (!m_devSettings->omitNetworkingCxxModules) { // Use in case the host app provides its a non-Blob-compatilbe HTTP module. if (!Microsoft::React::GetRuntimeOptionBool("Blob.DisableModule")) { modules.push_back(std::make_unique( From e0c64408c7e6db4b4565d7ded6d6921533fa859f Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Tue, 10 Oct 2023 18:02:21 -0700 Subject: [PATCH 2/3] Remove change files --- ...ative-windows-a292054c-e016-4f31-bb25-3808d092176b.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 change/react-native-windows-a292054c-e016-4f31-bb25-3808d092176b.json diff --git a/change/react-native-windows-a292054c-e016-4f31-bb25-3808d092176b.json b/change/react-native-windows-a292054c-e016-4f31-bb25-3808d092176b.json deleted file mode 100644 index cdbeb3250de..00000000000 --- a/change/react-native-windows-a292054c-e016-4f31-bb25-3808d092176b.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "prerelease", - "comment": "Conditionally register WebSocket Cxx module", - "packageName": "react-native-windows", - "email": "julio.rocha@microsoft.com", - "dependentChangeType": "patch" -} From e44c38357ef0e205330c6b6c3df6691aa30f7e5d Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Tue, 10 Oct 2023 18:05:06 -0700 Subject: [PATCH 3/3] Change files --- ...ative-windows-19511fcc-25bf-46e4-815a-99c1bcca18f0.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-19511fcc-25bf-46e4-815a-99c1bcca18f0.json diff --git a/change/react-native-windows-19511fcc-25bf-46e4-815a-99c1bcca18f0.json b/change/react-native-windows-19511fcc-25bf-46e4-815a-99c1bcca18f0.json new file mode 100644 index 00000000000..8f1445d61c3 --- /dev/null +++ b/change/react-native-windows-19511fcc-25bf-46e4-815a-99c1bcca18f0.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Conditionally register WebSocket Cxx module (#12218)", + "packageName": "react-native-windows", + "email": "julio.rocha@microsoft.com", + "dependentChangeType": "patch" +}