From 2b0e406fef5932e7e1506d844a7ef474795c8f9f Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 5 Mar 2025 03:24:07 -0800 Subject: [PATCH] Fix TMManager moduleProviderForName (#49835) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49835 The implementation of moduleProviderForName is slightly off. This method was supposed to replace the previous ternary expression and to enhance with the module provider call. The ternary expression used to be ``` !RCTTurboModuleInteropEnabled() || [self _isTurboModule:moduleName] ? [self _provideObjCModule:moduleName] : nil ``` However, as you can see from the current implementation, instead of calling `RCTTurboModuleInteropEnabled()` we are calling `RCTTurboModuleEnabled()` which is clearly a mistake. On top of that, I'm also updating the guard around the `getModuleProvider` selector as it was bypassing the other checks, and that's wrong. ## Changelog: [Internal] - Fix moduleProviderForName method Reviewed By: RSNara Differential Revision: D70569552 fbshipit-source-id: ed4055da9ea385ed10323ed8d7a8772010b3a105 --- .../ios/ReactCommon/RCTTurboModuleManager.mm | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm index b784ba5942a..81dd4ef34db 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm @@ -493,21 +493,22 @@ typedef struct { - (id)_moduleProviderForName:(const char *)moduleName { + id moduleProvider = nil; if ([_delegate respondsToSelector:@selector(getModuleProvider:)]) { - id moduleProvider = [_delegate getModuleProvider:moduleName]; - BOOL isTurboModule = [self _isTurboModule:moduleName]; - if (RCTTurboModuleEnabled() && !isTurboModule && !moduleProvider) { - return nil; - } + moduleProvider = [_delegate getModuleProvider:moduleName]; + } - if (moduleProvider) { - if ([moduleProvider conformsToProtocol:@protocol(RCTTurboModule)]) { - // moduleProvider is also a TM, we need to initialize objectiveC properties, like the dispatch queue - return (id)[self _provideObjCModule:moduleName moduleProvider:moduleProvider]; - } - // module is Cxx module - return moduleProvider; + if (RCTTurboModuleInteropEnabled() && ![self _isTurboModule:moduleName] && !moduleProvider) { + return nil; + } + + if (moduleProvider) { + if ([moduleProvider conformsToProtocol:@protocol(RCTTurboModule)]) { + // moduleProvider is also a TM, we need to initialize objectiveC properties, like the dispatch queue + return (id)[self _provideObjCModule:moduleName moduleProvider:moduleProvider]; } + // module is Cxx module + return moduleProvider; } // No module provider, the Module is registered without Codegen