From 3fa5d835eddd26089642f998139d65e2a0184072 Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Fri, 4 Dec 2026 22:22:34 -0800 Subject: [PATCH] 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 Reviewed By: shwanton Differential Revision: D136017712 --- .../react-native/React/Base/RCTBridgeModule.h | 23 +++++++++++++++---- .../CoreModules/RCTActionSheetManager.mm | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/react-native/React/Base/RCTBridgeModule.h b/packages/react-native/React/Base/RCTBridgeModule.h index e2cac1687abb..a9eaf3c3ca75 100644 --- a/packages/react-native/React/Base/RCTBridgeModule.h +++ b/packages/react-native/React/Base/RCTBridgeModule.h @@ -76,10 +76,25 @@ RCT_EXTERN_C_END // With both legacy interop layers removed, RCTRegisterModule is compiled out, so // static module registration is a no-op: only the JS module name is emitted. -#define RCT_EXPORT_MODULE(js_name) \ - +(NSString *)moduleName \ - { \ - return @ #js_name; \ +#ifdef __cplusplus +#define _RCT_ASSERT_EXPORTED_MODULE_IS_TURBO_MODULE() \ + static_assert( \ + __is_convertible_to(__typeof__([self alloc]), id), \ + "Without the legacy module interop, only RCTTurboModule classes are created: conform this module " \ + "to RCTTurboModule (or its codegen spec) and implement getTurboModule:") +#else +#define _RCT_ASSERT_EXPORTED_MODULE_IS_TURBO_MODULE() \ + _Static_assert( \ + 0, \ + "Without the legacy module interop, only RCTTurboModule classes are created, which needs Objective-C++: " \ + "rename this file to .mm and conform the module to RCTTurboModule") +#endif + +#define RCT_EXPORT_MODULE(js_name) \ + +(NSString *)moduleName \ + { \ + _RCT_ASSERT_EXPORTED_MODULE_IS_TURBO_MODULE(); \ + return @ #js_name; \ } #else diff --git a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm index d615eca6e8a3..8a58c410ad82 100644 --- a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm +++ b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm @@ -317,6 +317,9 @@ - (void)showShareActionSheetWithOptions: using namespace facebook::react; +@interface RCTActionSheetManager () +@end + @implementation RCTActionSheetManager RCT_EXPORT_MODULE()