Skip to content

Commit 37beffc

Browse files
Reject non-TurboModule exported modules when both interops are removed (#60531)
Summary: With both legacy interop layers removed, `RCTTurboModuleManager` only creates classes that conform to `RCTTurboModule`. A module exported with `RCT_EXPORT_MODULE` that does not conform compiles but resolves to nil at runtime, so lookups such as URL request handlers and image loaders silently fall back. Make `RCT_EXPORT_MODULE` fail the build for such classes instead. Changelog: [iOS][Changed] - `RCT_EXPORT_MODULE` fails to compile for classes that do not conform to `RCTTurboModule` when both `RCT_REMOVE_LEGACY_MODULE_INTEROP` and `RCT_REMOVE_LEGACY_COMPONENT_INTEROP` are set Signed-off-by: Christoph Purrer <chpurrer@meta.com> Reviewed By: shwanton Differential Revision: D136017712 Pull Request resolved: #60531
1 parent 06a4eb3 commit 37beffc

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎packages/react-native/React/Base/RCTBridgeModule.h‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,25 @@ RCT_EXTERN_C_END
7676

7777
// With both legacy interop layers removed, RCTRegisterModule is compiled out, so
7878
// static module registration is a no-op: only the JS module name is emitted.
79-
#define RCT_EXPORT_MODULE(js_name) \
80-
+(NSString *)moduleName \
81-
{ \
82-
return @ #js_name; \
79+
#ifdef __cplusplus
80+
#define _RCT_ASSERT_EXPORTED_MODULE_IS_TURBO_MODULE() \
81+
static_assert( \
82+
__is_convertible_to(__typeof__([self alloc]), id<RCTTurboModule>), \
83+
"Without the legacy module interop, only RCTTurboModule classes are created: conform this module " \
84+
"to RCTTurboModule (or its codegen spec) and implement getTurboModule:")
85+
#else
86+
#define _RCT_ASSERT_EXPORTED_MODULE_IS_TURBO_MODULE() \
87+
_Static_assert( \
88+
0, \
89+
"Without the legacy module interop, only RCTTurboModule classes are created, which needs Objective-C++: " \
90+
"rename this file to .mm and conform the module to RCTTurboModule")
91+
#endif
92+
93+
#define RCT_EXPORT_MODULE(js_name) \
94+
+(NSString *)moduleName \
95+
{ \
96+
_RCT_ASSERT_EXPORTED_MODULE_IS_TURBO_MODULE(); \
97+
return @ #js_name; \
8398
}
8499

85100
#else

‎packages/react-native/React/CoreModules/RCTActionSheetManager.mm‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ - (void)showShareActionSheetWithOptions:
317317
318318
using namespace facebook::react;
319319
320+
@interface RCTActionSheetManager () <RCTTurboModule>
321+
@end
322+
320323
@implementation RCTActionSheetManager
321324
322325
RCT_EXPORT_MODULE()

0 commit comments

Comments
 (0)