From 5bf00b765ee4b320a302d2d4c4966e5ee30a7e88 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Mon, 13 Nov 2023 15:30:04 -0800 Subject: [PATCH] put PR#41194 behind gating (#41469) Summary: Changelog: [Internal] PR#41194 (https://github.com/facebook/react-native/pull/41194) introduces a new callsite to `RCTUnsafeExecuteOnMainQueueSync` in the module init path, which increases risk for deadlock. let's gate it Differential Revision: D51274859 --- packages/react-native/React/Base/RCTBridge.h | 3 +++ packages/react-native/React/Base/RCTBridge.mm | 11 +++++++++++ packages/react-native/React/Modules/RCTUIManager.m | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/react-native/React/Base/RCTBridge.h b/packages/react-native/React/Base/RCTBridge.h index 846e17fdb1104e..ace401ec56d3fd 100644 --- a/packages/react-native/React/Base/RCTBridge.h +++ b/packages/react-native/React/Base/RCTBridge.h @@ -61,6 +61,9 @@ void RCTEnableTurboModuleSyncVoidMethods(BOOL enabled); BOOL RCTTurboModuleSharedQueueEnabled(void); void RCTEnableTurboModuleSharedQueue(BOOL enabled); +BOOL RCTUIManagerDispatchAccessibilityManagerInitOntoMain(void); +void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled); + typedef enum { kRCTBridgeProxyLoggingLevelNone, kRCTBridgeProxyLoggingLevelWarning, diff --git a/packages/react-native/React/Base/RCTBridge.mm b/packages/react-native/React/Base/RCTBridge.mm index a18b43861cbabd..263231720cffb6 100644 --- a/packages/react-native/React/Base/RCTBridge.mm +++ b/packages/react-native/React/Base/RCTBridge.mm @@ -162,6 +162,17 @@ void RCTEnableTurboModuleSharedQueue(BOOL enabled) gTurboModuleEnableSharedQueue = enabled; } +BOOL kDispatchAccessibilityManagerInitOntoMain = NO; +BOOL RCTUIManagerDispatchAccessibilityManagerInitOntoMain(void) +{ + return kDispatchAccessibilityManagerInitOntoMain; +} + +void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled) +{ + kDispatchAccessibilityManagerInitOntoMain = enabled; +} + @interface RCTBridge () @end diff --git a/packages/react-native/React/Modules/RCTUIManager.m b/packages/react-native/React/Modules/RCTUIManager.m index 4167fb122841f5..a646f95079db04 100644 --- a/packages/react-native/React/Modules/RCTUIManager.m +++ b/packages/react-native/React/Modules/RCTUIManager.m @@ -181,7 +181,10 @@ - (void)setBridge:(RCTBridge *)bridge } // This dispatch_async avoids a deadlock while configuring native modules - dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ + dispatch_queue_t accessibilityManagerInitQueue = RCTUIManagerDispatchAccessibilityManagerInitOntoMain() + ? dispatch_get_main_queue() + : dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0); + dispatch_async(accessibilityManagerInitQueue, ^{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNewContentSizeMultiplier) name:@"RCTAccessibilityManagerDidUpdateMultiplierNotification"