From 98bc2c7931b63a7eb0dd292e7636c26501630a54 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Mon, 13 Nov 2023 14:24:20 -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/Modules/RCTUIManager.h | 2 ++ packages/react-native/React/Modules/RCTUIManager.m | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/react-native/React/Modules/RCTUIManager.h b/packages/react-native/React/Modules/RCTUIManager.h index 0979c965f8fdca..661df887db20a6 100644 --- a/packages/react-native/React/Modules/RCTUIManager.h +++ b/packages/react-native/React/Modules/RCTUIManager.h @@ -20,6 +20,8 @@ */ RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification; +RCT_EXTERN void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled); + @class RCTLayoutAnimationGroup; @class RCTUIManagerObserverCoordinator; diff --git a/packages/react-native/React/Modules/RCTUIManager.m b/packages/react-native/React/Modules/RCTUIManager.m index 4167fb122841f5..af094069057579 100644 --- a/packages/react-native/React/Modules/RCTUIManager.m +++ b/packages/react-native/React/Modules/RCTUIManager.m @@ -61,6 +61,12 @@ static void RCTTraverseViewNodes(id view, void (^block)(id *_rootViewTags; @@ -181,7 +187,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 = kDispatchAccessibilityManagerInitOntoMain + ? 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"