From d0a101fbeaec0bdace3a680078e0acc8635b5c3e Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Thu, 27 Feb 2025 18:41:41 -0800 Subject: [PATCH] Add guard for custom module provider lookup in TMManager (#49738) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49738 **Context** - D70012142 added TM module provider support - This was causing RN MacOS to silently fail to load any platform modules since it didn't implement the delegate method Changelog: [iOS][Fixed] - Add guard for custom module provider lookup in TMManager Reviewed By: sbuggay Differential Revision: D70357542 fbshipit-source-id: 5b338616655ecb84cdb3c60e243fdb99444af657 --- .../ios/ReactCommon/RCTTurboModuleManager.mm | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 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 290ce617af7..b784ba5942a 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,19 +493,21 @@ typedef struct { - (id)_moduleProviderForName:(const char *)moduleName { - id moduleProvider = [_delegate getModuleProvider:moduleName]; - BOOL isTurboModule = [self _isTurboModule:moduleName]; - if (RCTTurboModuleEnabled() && !isTurboModule && !moduleProvider) { - return nil; - } + if ([_delegate respondsToSelector:@selector(getModuleProvider:)]) { + id moduleProvider = [_delegate getModuleProvider:moduleName]; + BOOL isTurboModule = [self _isTurboModule:moduleName]; + if (RCTTurboModuleEnabled() && !isTurboModule && !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]; + 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; } - // module is Cxx module - return moduleProvider; } // No module provider, the Module is registered without Codegen