Skip to content

Commit

Permalink
[0.71] Conditionally register WebSocket Cxx module (#12223)
Browse files Browse the repository at this point in the history
* Conditionally register WebSocket Cxx module (#12218)

* Conditionally register WebSocket Cxx module

* Change files

* Remove change files

* Change files

---------

Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com>
  • Loading branch information
JunielKatarn and acoates-ms committed Oct 11, 2023
1 parent 825459d commit 1ea6771
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Conditionally register WebSocket Cxx module (#12218)",
"packageName": "react-native-windows",
"email": "julio.rocha@microsoft.com",
"dependentChangeType": "patch"
}
3 changes: 3 additions & 0 deletions vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,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<facebook::react::Instance>(strongThis->m_instance.Load()),
Expand Down
3 changes: 3 additions & 0 deletions vnext/Shared/DevSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions vnext/Shared/OInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,18 @@ std::vector<std::unique_ptr<NativeModule>> 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<CxxNativeModule>(
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<CxxNativeModule>(
Expand Down

0 comments on commit 1ea6771

Please sign in to comment.