From 19b483c003d8c4fb4156bef9c1087007edc7ee64 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 5 Mar 2025 01:53:35 -0800 Subject: [PATCH] Fix TMManager moduleProviderForName Summary: 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 --- .../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 b784ba5942ae51..81dd4ef34db390 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 @@ - (BOOL)_isLegacyModuleClass:(Class)moduleClass - (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