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" +} 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(