Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.76] Backport use a legacy native module binding that always returns null in bridgeless mode #13976

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Use a legacy native module binding that always returns null in bridgeless mode",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "SampleTurboModule only works as a turbomodule, so do not install it when using web debugger",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
19 changes: 15 additions & 4 deletions vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,12 @@ void ReactInstanceWin::LoadModules(
}
#endif

registerTurboModule(
L"SampleTurboModule",
winrt::Microsoft::ReactNative::MakeTurboModuleProvider<::Microsoft::ReactNative::SampleTurboModule>());
if (!m_options.UseWebDebugger()) {
turboModulesProvider->AddModuleProvider(
L"SampleTurboModule",
winrt::Microsoft::ReactNative::MakeTurboModuleProvider<::Microsoft::ReactNative::SampleTurboModule>(),
false);
}

if (devSettings->useTurboModulesOnly) {
::Microsoft::ReactNative::ExceptionsManager::SetRedBoxHander(
Expand Down Expand Up @@ -680,8 +683,16 @@ void ReactInstanceWin::InitializeBridgeless() noexcept {
return turboModuleManager->getModule(name);
};

// Use a legacy native module binding that always returns null
// This means that calls to NativeModules.XXX will always return null, rather than crashing on access
auto legacyNativeModuleBinding =
[](const std::string & /*name*/) -> std::shared_ptr<facebook::react::TurboModule> { return nullptr; };

facebook::react::TurboModuleBinding::install(
runtime, std::function(binding), nullptr, m_options.TurboModuleProvider->LongLivedObjectCollection());
runtime,
std::function(binding),
std::function(legacyNativeModuleBinding),
m_options.TurboModuleProvider->LongLivedObjectCollection());

auto componentDescriptorRegistry =
Microsoft::ReactNative::WindowsComponentDescriptorRegistry::FromProperties(
Expand Down
Loading