Skip to content

Commit 6defe41

Browse files
Remove unused bridge-based RCTTurboModuleManager initializer (#57065)
Summary: ## Changelog: [iOS][Breaking] Remove unused bridge-based RCTTurboModuleManager initializer `RCTTurboModuleManager` declared three initializers, but only the bridgeless (`RCTBridgeProxy`-based) ones are used. The bridge-based `initWithBridge:delegate:jsInvoker:` initializer was the only path that ever set a non-nil bridge, leaving a large amount of bridge-only code permanently dead under the surviving initializers. This removes that initializer along with the now-dead bridge-mode code: the `_bridge` ivar, the `decorateNativeMethodCallInvoker:` decoration, the `RCTModuleData`/`registerModuleForFrameUpdates:` registration, the `performanceLogger` setup markers, and the bridge invalidation notification observers and handlers. `initWithBridgeProxy:bridgeModuleDecorator:delegate:jsInvoker:devMenuConfigurationDecorator:` becomes the designated initializer, and the shorter `RCTBridgeProxy` initializer now forwards to it. The `RCTDidInitializeModuleNotification` post is preserved with a nil bridge, matching the existing runtime behaviour of the bridgeless initializers. Differential Revision: D107409088
1 parent 5f862ea commit 6defe41

5 files changed

Lines changed: 13 additions & 144 deletions

File tree

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,6 @@
6565

6666
@interface RCTTurboModuleManager : NSObject <RCTTurboModuleRegistry>
6767

68-
- (instancetype)initWithBridge:(RCTBridge *)bridge
69-
delegate:(id<RCTTurboModuleManagerDelegate>)delegate
70-
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker;
71-
72-
- (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
73-
bridgeModuleDecorator:(RCTBridgeModuleDecorator *)bridgeModuleDecorator
74-
delegate:(id<RCTTurboModuleManagerDelegate>)delegate
75-
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker;
76-
7768
- (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
7869
bridgeModuleDecorator:(RCTBridgeModuleDecorator *)bridgeModuleDecorator
7970
delegate:(id<RCTTurboModuleManagerDelegate>)delegate

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm

Lines changed: 13 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#import <React/RCTDevMenuConfigurationDecorator.h>
2626
#import <React/RCTInitializing.h>
2727
#import <React/RCTLog.h>
28-
#import <React/RCTModuleData.h>
29-
#import <React/RCTPerformanceLogger.h>
3028
#import <React/RCTUtils.h>
3129
#import <ReactCommon/CxxTurboModuleUtils.h>
3230
#import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
@@ -189,7 +187,6 @@ Class getFallbackClassFromName(const char *name)
189187
@implementation RCTTurboModuleManager {
190188
std::shared_ptr<CallInvoker> _jsInvoker;
191189
__weak id<RCTTurboModuleManagerDelegate> _delegate;
192-
__weak RCTBridge *_bridge;
193190

194191
/**
195192
* TODO(T48018690):
@@ -221,17 +218,15 @@ @implementation RCTTurboModuleManager {
221218
dispatch_queue_t _sharedModuleQueue;
222219
}
223220

224-
- (instancetype)initWithBridge:(RCTBridge *)bridge
225-
bridgeProxy:(RCTBridgeProxy *)bridgeProxy
226-
bridgeModuleDecorator:(RCTBridgeModuleDecorator *)bridgeModuleDecorator
227-
delegate:(id<RCTTurboModuleManagerDelegate>)delegate
228-
jsInvoker:(std::shared_ptr<CallInvoker>)jsInvoker
229-
devMenuConfigurationDecorator:(RCTDevMenuConfigurationDecorator *)devMenuConfigurationDecorator
221+
- (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
222+
bridgeModuleDecorator:(RCTBridgeModuleDecorator *)bridgeModuleDecorator
223+
delegate:(id<RCTTurboModuleManagerDelegate>)delegate
224+
jsInvoker:(std::shared_ptr<CallInvoker>)jsInvoker
225+
devMenuConfigurationDecorator:(RCTDevMenuConfigurationDecorator *)devMenuConfigurationDecorator
230226
{
231227
if (self = [super init]) {
232228
_jsInvoker = std::move(jsInvoker);
233229
_delegate = delegate;
234-
_bridge = bridge;
235230
_bridgeProxy = bridgeProxy;
236231
_bridgeModuleDecorator = bridgeModuleDecorator;
237232
_invalidating = false;
@@ -261,58 +256,10 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
261256
_legacyEagerlyRegisteredModuleClasses = legacyEagerlyRegisteredModuleClasses;
262257
}
263258
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
264-
265-
[[NSNotificationCenter defaultCenter] addObserver:self
266-
selector:@selector(bridgeWillInvalidateModules:)
267-
name:RCTBridgeWillInvalidateModulesNotification
268-
object:nil];
269-
[[NSNotificationCenter defaultCenter] addObserver:self
270-
selector:@selector(bridgeDidInvalidateModules:)
271-
name:RCTBridgeDidInvalidateModulesNotification
272-
object:nil];
273259
}
274260
return self;
275261
}
276262

277-
- (instancetype)initWithBridge:(RCTBridge *)bridge
278-
delegate:(id<RCTTurboModuleManagerDelegate>)delegate
279-
jsInvoker:(std::shared_ptr<CallInvoker>)jsInvoker
280-
{
281-
return [self initWithBridge:bridge
282-
bridgeProxy:nil
283-
bridgeModuleDecorator:[bridge bridgeModuleDecorator]
284-
delegate:delegate
285-
jsInvoker:jsInvoker
286-
devMenuConfigurationDecorator:nil];
287-
}
288-
289-
- (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
290-
bridgeModuleDecorator:(RCTBridgeModuleDecorator *)bridgeModuleDecorator
291-
delegate:(id<RCTTurboModuleManagerDelegate>)delegate
292-
jsInvoker:(std::shared_ptr<CallInvoker>)jsInvoker
293-
{
294-
return [self initWithBridge:nil
295-
bridgeProxy:bridgeProxy
296-
bridgeModuleDecorator:bridgeModuleDecorator
297-
delegate:delegate
298-
jsInvoker:jsInvoker
299-
devMenuConfigurationDecorator:nil];
300-
}
301-
302-
- (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
303-
bridgeModuleDecorator:(RCTBridgeModuleDecorator *)bridgeModuleDecorator
304-
delegate:(id<RCTTurboModuleManagerDelegate>)delegate
305-
jsInvoker:(std::shared_ptr<CallInvoker>)jsInvoker
306-
devMenuConfigurationDecorator:(RCTDevMenuConfigurationDecorator *)devMenuConfigurationDecorator
307-
{
308-
return [self initWithBridge:nil
309-
bridgeProxy:bridgeProxy
310-
bridgeModuleDecorator:bridgeModuleDecorator
311-
delegate:delegate
312-
jsInvoker:jsInvoker
313-
devMenuConfigurationDecorator:devMenuConfigurationDecorator];
314-
}
315-
316263
/**
317264
* Given a name for a TurboModule, return a C++ object which is the instance
318265
* of that TurboModule C++ class. This class wraps the TurboModule's ObjC instance.
@@ -378,14 +325,6 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
378325
* Step 2c: Create and native CallInvoker from the TurboModule's method queue.
379326
*/
380327
nativeMethodCallInvoker = std::make_shared<ModuleNativeMethodCallInvoker>(methodQueue);
381-
382-
/**
383-
* Have RCTCxxBridge decorate native CallInvoker, so that it's aware of TurboModule async method calls.
384-
* This helps the bridge fire onBatchComplete as readily as it should.
385-
*/
386-
if ([_bridge respondsToSelector:@selector(decorateNativeMethodCallInvoker:)]) {
387-
nativeMethodCallInvoker = [_bridge decorateNativeMethodCallInvoker:nativeMethodCallInvoker];
388-
}
389328
}
390329

391330
/**
@@ -681,7 +620,7 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass
681620
* this method exists to know if we can safely set the bridge to the
682621
* NativeModule.
683622
*/
684-
if ([module respondsToSelector:@selector(bridge)] && (_bridge || _bridgeProxy)) {
623+
if ([module respondsToSelector:@selector(bridge)] && _bridgeProxy) {
685624
/**
686625
* Just because a NativeModule has the `bridge` method, it doesn't mean
687626
* that it has synthesized the bridge in its implementation. Therefore,
@@ -698,11 +637,7 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass
698637
* generated, so we have have to rely on the KVC API of ObjC to set
699638
* the bridge property of these NativeModules.
700639
*/
701-
if (_bridge) {
702-
[(id)module setValue:_bridge forKey:@"bridge"];
703-
} else if (_bridgeProxy) {
704-
[(id)module setValue:_bridgeProxy forKey:@"bridge"];
705-
}
640+
[(id)module setValue:_bridgeProxy forKey:@"bridge"];
706641
} @catch (NSException *) {
707642
RCTLogError(
708643
@"%@ has no setter or ivar for its bridge, which is not "
@@ -789,33 +724,15 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass
789724
*/
790725
objc_setAssociatedObject(module, &kAssociatedMethodQueueKey, methodQueue, OBJC_ASSOCIATION_RETAIN);
791726

792-
/**
793-
* NativeModules that implement the RCTFrameUpdateObserver protocol
794-
* require registration with RCTDisplayLink.
795-
*
796-
* TODO(T55504345): Investigate whether we can improve this after TM
797-
* rollout.
798-
*/
799-
if (_bridge) {
800-
RCTModuleData *data = [[RCTModuleData alloc] initWithModuleInstance:(id<RCTBridgeModule>)module
801-
bridge:_bridge
802-
moduleRegistry:_bridge.moduleRegistry
803-
viewRegistry_DEPRECATED:nil
804-
bundleManager:nil
805-
callableJSModules:nil];
806-
[_bridge registerModuleForFrameUpdates:(id<RCTBridgeModule>)module withModuleData:data];
807-
}
808-
809727
/**
810728
* Broadcast that this NativeModule was created.
811729
*
812730
* TODO(T41180176): Investigate whether we can delete this after TM
813731
* rollout.
814732
*/
815-
[[NSNotificationCenter defaultCenter]
816-
postNotificationName:RCTDidInitializeModuleNotification
817-
object:_bridge
818-
userInfo:@{@"module" : module, @"bridge" : RCTNullIfNil([_bridge parentBridge])}];
733+
[[NSNotificationCenter defaultCenter] postNotificationName:RCTDidInitializeModuleNotification
734+
object:nil
735+
userInfo:@{@"module" : module, @"bridge" : [NSNull null]}];
819736

820737
TurboModulePerfLogger::moduleCreateSetUpEnd(moduleName, moduleId);
821738

@@ -932,10 +849,6 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime
932849
auto moduleName = name.c_str();
933850

934851
TurboModulePerfLogger::moduleJSRequireBeginningStart(moduleName);
935-
auto moduleWasNotInitialized = ![self moduleIsInitialized:moduleName];
936-
if (moduleWasNotInitialized) {
937-
[self->_bridge.performanceLogger markStartForTag:RCTPLTurboModuleSetup];
938-
}
939852

940853
/**
941854
* By default, all TurboModules are long-lived.
@@ -944,10 +857,6 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime
944857
*/
945858
auto turboModule = [self provideTurboModule:moduleName runtime:&runtime];
946859

947-
if (moduleWasNotInitialized && [self moduleIsInitialized:moduleName]) {
948-
[self->_bridge.performanceLogger markStopForTag:RCTPLTurboModuleSetup];
949-
}
950-
951860
if (turboModule) {
952861
TurboModulePerfLogger::moduleJSRequireEndingEnd(moduleName);
953862
} else {
@@ -1020,26 +929,6 @@ - (BOOL)moduleIsInitialized:(const char *)moduleName
1020929

1021930
#pragma mark Invalidation logic
1022931

1023-
- (void)bridgeWillInvalidateModules:(NSNotification *)notification
1024-
{
1025-
RCTBridge *bridge = notification.userInfo[@"bridge"];
1026-
if (bridge != _bridge) {
1027-
return;
1028-
}
1029-
1030-
[self _enterInvalidatingState];
1031-
}
1032-
1033-
- (void)bridgeDidInvalidateModules:(NSNotification *)notification
1034-
{
1035-
RCTBridge *bridge = notification.userInfo[@"bridge"];
1036-
if (bridge != _bridge) {
1037-
return;
1038-
}
1039-
1040-
[self _invalidateModules];
1041-
}
1042-
1043932
- (void)invalidate
1044933
{
1045934
[self _enterInvalidatingState];
@@ -1098,15 +987,10 @@ - (void)_invalidateModules
1098987
dispatch_group_leave(moduleInvalidationGroup);
1099988
};
1100989

1101-
if (_bridge) {
1102-
[_bridge dispatchBlock:invalidateModule queue:methodQueue];
990+
if (methodQueue == RCTJSThread) {
991+
invalidateModule();
1103992
} else {
1104-
// Bridgeless mode
1105-
if (methodQueue == RCTJSThread) {
1106-
invalidateModule();
1107-
} else {
1108-
dispatch_async(methodQueue, invalidateModule);
1109-
}
993+
dispatch_async(methodQueue, invalidateModule);
1110994
}
1111995
}
1112996

scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,8 +1999,6 @@ interface RCTTransformAnimatedNode : public RCTAnimatedNode {
19991999
}
20002000

20012001
interface RCTTurboModuleManager : public NSObject <RCTTurboModuleRegistry> {
2002-
public virtual instancetype initWithBridge:delegate:jsInvoker:(RCTBridge* bridge, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
2003-
public virtual instancetype initWithBridgeProxy:bridgeModuleDecorator:delegate:jsInvoker:(RCTBridgeProxy* bridgeProxy, RCTBridgeModuleDecorator* bridgeModuleDecorator, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
20042002
public virtual instancetype initWithBridgeProxy:bridgeModuleDecorator:delegate:jsInvoker:devMenuConfigurationDecorator:(RCTBridgeProxy* bridgeProxy, RCTBridgeModuleDecorator* bridgeModuleDecorator, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker, RCTDevMenuConfigurationDecorator* devMenuConfigurationDecorator);
20052003
public virtual void installJSBindings:(facebook::jsi::Runtime& runtime);
20062004
public virtual void invalidate();

scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,8 +1987,6 @@ interface RCTTransformAnimatedNode : public RCTAnimatedNode {
19871987
}
19881988

19891989
interface RCTTurboModuleManager : public NSObject <RCTTurboModuleRegistry> {
1990-
public virtual instancetype initWithBridge:delegate:jsInvoker:(RCTBridge* bridge, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
1991-
public virtual instancetype initWithBridgeProxy:bridgeModuleDecorator:delegate:jsInvoker:(RCTBridgeProxy* bridgeProxy, RCTBridgeModuleDecorator* bridgeModuleDecorator, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
19921990
public virtual instancetype initWithBridgeProxy:bridgeModuleDecorator:delegate:jsInvoker:devMenuConfigurationDecorator:(RCTBridgeProxy* bridgeProxy, RCTBridgeModuleDecorator* bridgeModuleDecorator, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker, RCTDevMenuConfigurationDecorator* devMenuConfigurationDecorator);
19931991
public virtual void installJSBindings:(facebook::jsi::Runtime& runtime);
19941992
public virtual void invalidate();

scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,8 +1999,6 @@ interface RCTTransformAnimatedNode : public RCTAnimatedNode {
19991999
}
20002000

20012001
interface RCTTurboModuleManager : public NSObject <RCTTurboModuleRegistry> {
2002-
public virtual instancetype initWithBridge:delegate:jsInvoker:(RCTBridge* bridge, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
2003-
public virtual instancetype initWithBridgeProxy:bridgeModuleDecorator:delegate:jsInvoker:(RCTBridgeProxy* bridgeProxy, RCTBridgeModuleDecorator* bridgeModuleDecorator, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
20042002
public virtual instancetype initWithBridgeProxy:bridgeModuleDecorator:delegate:jsInvoker:devMenuConfigurationDecorator:(RCTBridgeProxy* bridgeProxy, RCTBridgeModuleDecorator* bridgeModuleDecorator, id<RCTTurboModuleManagerDelegate> delegate, std::shared_ptr<facebook::react::CallInvoker> jsInvoker, RCTDevMenuConfigurationDecorator* devMenuConfigurationDecorator);
20052003
public virtual void installJSBindings:(facebook::jsi::Runtime& runtime);
20062004
public virtual void invalidate();

0 commit comments

Comments
 (0)