Skip networking Cxx modules if turbo modules are requested (#12083)

* Conditionally register Blob TurboModule

* Skip networking Cxx modules if UseWindowsAbi is set

* Change files

* Also skip FileReader module where appropriate

* Replace UseWindowsAbi with OmitNetworkingCxxModules

* Define DevSettings::omitNetworkingCxxModules

* Also omit the HTTP module if Blob.DisableModule is set
This commit is contained in:
Julio César Rocha 2023-08-31 14:40:50 -07:00 коммит произвёл GitHub
Родитель 33d04be892
Коммит 7f99d6048a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 47 добавлений и 32 удалений

Просмотреть файл

@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Skip networking Cxx modules if UseWindowsAbi is set",
"packageName": "react-native-windows",
"email": "julio.rocha@microsoft.com",
"dependentChangeType": "patch"
}

Просмотреть файл

@ -84,6 +84,7 @@
#include <tuple>
#include "ChakraRuntimeHolder.h"
#include <CppRuntimeOptions.h>
#include <CreateModules.h>
#include <Utils/Helpers.h>
#include "CrashManager.h"
@ -392,15 +393,17 @@ void ReactInstanceWin::LoadModules(
L"Timing", winrt::Microsoft::ReactNative::MakeTurboModuleProvider<::Microsoft::ReactNative::Timing>());
#endif
registerTurboModule(::Microsoft::React::GetBlobTurboModuleName(), ::Microsoft::React::GetBlobModuleProvider());
registerTurboModule(::Microsoft::React::GetHttpTurboModuleName(), ::Microsoft::React::GetHttpModuleProvider());
registerTurboModule(
::Microsoft::React::GetFileReaderTurboModuleName(), ::Microsoft::React::GetFileReaderModuleProvider());
registerTurboModule(
::Microsoft::React::GetWebSocketTurboModuleName(), ::Microsoft::React::GetWebSocketModuleProvider());
if (!Microsoft::React::GetRuntimeOptionBool("Blob.DisableModule")) {
registerTurboModule(::Microsoft::React::GetHttpTurboModuleName(), ::Microsoft::React::GetHttpModuleProvider());
registerTurboModule(::Microsoft::React::GetBlobTurboModuleName(), ::Microsoft::React::GetBlobModuleProvider());
registerTurboModule(
::Microsoft::React::GetFileReaderTurboModuleName(), ::Microsoft::React::GetFileReaderModuleProvider());
}
}
//! Initialize() is called from the native queue.
@ -550,6 +553,9 @@ void ReactInstanceWin::Initialize() noexcept {
// We need to keep the instance wrapper alive as its destruction shuts down the native queue.
m_options.TurboModuleProvider->SetReactContext(
winrt::make<implementation::ReactContext>(Mso::Copy(m_reactContext)));
auto omitNetCxxPropName = ReactPropertyBagHelper::GetName(nullptr, L"OmitNetworkingCxxModules");
auto omitNetCxxPropValue = m_options.Properties.Get(omitNetCxxPropName);
devSettings->omitNetworkingCxxModules = winrt::unbox_value_or(omitNetCxxPropValue, false);
auto bundleRootPath = devSettings->bundleRootPath;
auto instanceWrapper = facebook::react::CreateReactInstance(
std::shared_ptr<facebook::react::Instance>(strongThis->m_instance.Load()),

Просмотреть файл

@ -99,6 +99,9 @@ struct DevSettings {
bool devBundle{true};
bool enableDefaultCrashHandler{false};
// Transitory. Used to indicate whether or not to load networking types in the default Cxx module registry.
bool omitNetworkingCxxModules{false};
};
} // namespace react

Просмотреть файл

@ -538,35 +538,34 @@ 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))
modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetHttpModuleName(),
[nativeQueue, transitionalProps]() -> std::unique_ptr<xplat::module::CxxModule> {
return Microsoft::React::CreateHttpModule(transitionalProps);
},
nativeQueue));
modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetWebSocketModuleName(),
[nativeQueue, transitionalProps]() -> std::unique_ptr<xplat::module::CxxModule> {
return Microsoft::React::CreateWebSocketModule(transitionalProps);
},
nativeQueue));
// Use in case the host app provides its a non-Blob-compatilbe HTTP module.
if (!Microsoft::React::GetRuntimeOptionBool("Blob.DisableModule")) {
// Applications using the Windows ABI feature should loade the networking TurboModule variants instead.
if (!m_devSettings->omitNetworkingCxxModules) {
modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetBlobModuleName(),
[transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); },
Microsoft::React::GetWebSocketModuleName(),
[transitionalProps]() { return Microsoft::React::CreateWebSocketModule(transitionalProps); },
nativeQueue));
modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetFileReaderModuleName(),
[transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); },
nativeQueue));
// 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>(
m_innerInstance,
Microsoft::React::GetHttpModuleName(),
[transitionalProps]() { return Microsoft::React::CreateHttpModule(transitionalProps); },
nativeQueue));
modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetBlobModuleName(),
[transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); },
nativeQueue));
modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetFileReaderModuleName(),
[transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); },
nativeQueue));
}
}
modules.push_back(std::make_unique<CxxNativeModule>(