From eda6f4f8ecd78408fd7b535662e3c0bdeed740df Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Mon, 27 Jul 2026 09:32:49 -0700 Subject: [PATCH] Drop RCT_EXPORT_METHOD from RCTWebSocketModule TurboModule (#57687) Summary: Pull Request resolved: https://github.com/react/react-native/pull/57687 Changelog: [Internal] `RCTWebSocketModule` is a TurboModule: it conforms to `NativeWebSocketModuleSpec` and implements `getTurboModule:` returning the codegen'd `...SpecJSI`. For TurboModules, the JS->ObjC dispatch is driven by codegen (the generated spec supplies the `selector` and argument kinds, invoked at runtime via `NSMethodSignature` / `NSInvocation`), not by the `RCT_EXPORT_METHOD` macro's `__rct_export__` metadata. The exported methods here are async-void with concrete parameter types (no generic `id` requiring `RCTConvert` coercion), so the macro is not functionally required. Convert them to plain ObjC method declarations; conformance to the codegen'd `NativeWebSocketModuleSpec` protocol keeps compiler-enforced signature parity. Signature-only refactor with no change to the JS-facing API. Sync methods, methods with `id` params, and `constantsToExport` are intentionally left untouched. Reviewed By: cortinico Differential Revision: D113579874 fbshipit-source-id: 7ffb73d549ab2e81f89a20badbd3a3a1a16de90b --- .../React/CoreModules/RCTWebSocketModule.mm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTWebSocketModule.mm b/packages/react-native/React/CoreModules/RCTWebSocketModule.mm index d170124d40c..c588c616d1b 100644 --- a/packages/react-native/React/CoreModules/RCTWebSocketModule.mm +++ b/packages/react-native/React/CoreModules/RCTWebSocketModule.mm @@ -91,10 +91,12 @@ RCT_EXPORT_MODULE() } } -RCT_EXPORT_METHOD( - connect : (NSURL *)URL protocols : (NSArray *)protocols options : (JS::NativeWebSocketModule::SpecConnectOptions &) - options socketID : (double)socketID) +- (void)connect:(NSString *)urlString + protocols:(NSArray *)protocols + options:(JS::NativeWebSocketModule::SpecConnectOptions &)options + socketID:(double)socketID { + NSURL *URL = [RCTConvert NSURL:urlString]; if (URL == nil || URL.absoluteString.length == 0u) { RCTAssert(NO, @"RCTWebSocketModule: Invalid WebSocket URL passed to connect"); [self sendEventWithName:@"websocketFailed" body:@{@"message" : @"Invalid WebSocket URL", @"id" : @(socketID)}]; @@ -167,14 +169,14 @@ RCT_EXPORT_METHOD( [webSocket open]; } -RCT_EXPORT_METHOD(send : (NSString *)message forSocketID : (double)socketID) +- (void)send:(NSString *)message forSocketID:(double)socketID { SRWebSocket *webSocket = _sockets[@(socketID)]; [RCTInspectorWebSocketReporter reportMessageSent:webSocket.inspectorRequestId message:message]; [webSocket sendString:message error:nil]; } -RCT_EXPORT_METHOD(sendBinary : (NSString *)base64String forSocketID : (double)socketID) +- (void)sendBinary:(NSString *)base64String forSocketID:(double)socketID { [self sendData:[[NSData alloc] initWithBase64EncodedString:base64String options:0] forSocketID:@(socketID)]; } @@ -186,12 +188,12 @@ RCT_EXPORT_METHOD(sendBinary : (NSString *)base64String forSocketID : (double)so [webSocket sendData:data error:nil]; } -RCT_EXPORT_METHOD(ping : (double)socketID) +- (void)ping:(double)socketID { [_sockets[@(socketID)] sendPing:nil error:nil]; } -RCT_EXPORT_METHOD(close : (double)code reason : (NSString *)reason socketID : (double)socketID) +- (void)close:(double)code reason:(NSString *)reason socketID:(double)socketID { [_sockets[@(socketID)] closeWithCode:code reason:reason]; [_sockets removeObjectForKey:@(socketID)];