From 0da02ab1ca8f7ce4212eecd8d9d671f88428f1b6 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 15 Dec 2020 11:16:12 -0800 Subject: [PATCH] Don't lookup TurboModules post-invalidation Summary: During cleanup, RCTNativeAnimatedModule [requires the RCTEventDispatcher](https://fburl.com/diffusion/0bnln893) to remove itself from the dispatcher a dispatch observer. When the bridge is invalidated, if RCTEventDispatcher is has been cleaned up by then, we don't warn when this lookup fails: https://fburl.com/diffusion/rfioe5ay. This diff replicates that behaviour in the TurboModule infra. Notes: - In the legacy NativeModule infra, we can still query NativeModules post invalidation - we just won't create them. In the TurboModule infra, all requests for TurboModules from the TurboModuleManager start returning nil. Therefore, I simply did an early return inside TurboModuleManager moduleForName in the case that we're already invalidated. In addition to not displaying the warning, we just don't request/create the TurboModule in the first place. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D25560228 fbshipit-source-id: 102dcc147bab6121daacdb39890bad48c0e60894 --- .../nativemodule/core/platform/ios/RCTTurboModuleManager.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm b/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm index 14dfc0c96e0..8519045cbff 100644 --- a/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm +++ b/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm @@ -761,6 +761,12 @@ static Class getFallbackClassFromName(const char *name) - (id)moduleForName:(const char *)moduleName warnOnLookupFailure:(BOOL)warnOnLookupFailure { + // When the bridge is invalidating, TurboModules will be nil. + // Therefore, don't (1) do the lookup, and (2) warn on lookup. + if (_invalidating) { + return nil; + } + id module = [self provideRCTTurboModule:moduleName]; if (warnOnLookupFailure && !module) {