Skip to content

Commit

Permalink
[0.76] Backport use a legacy native module binding that always return…
Browse files Browse the repository at this point in the history
…s null in bridgeless mode (#13976)

* Use a legacy native module binding that always returns null in bridgeless mode (#13905)

* Use a legacy native module binding that always returns null in bridgeless mode

* Change files

* format

* SampleTurboModule only works as a turbomodule, so do not install it when using web debugger (#13911)

* SampleTurboModule only works as a turbomodule, so do not install it when using web debugger

* Change files

* fix
  • Loading branch information
acoates-ms authored Oct 16, 2024
1 parent 1a83ce8 commit e6a4c81
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
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

0 comments on commit e6a4c81

Please sign in to comment.