From b3cb27ee9f1b5e6743face1941b207616a38c957 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 24 Oct 2019 17:43:08 -0700 Subject: [PATCH] Fabric: Removing sync block dispatching from `RCTRuntimeExecutorFromBridge` Summary: The purpose of RCTRuntimeExecutorFromBridge is to create/implement RuntimeExecutor using some JS queue implemented as part of the Bridge. This diff changes the implementation of this method, specifically: Removing dispatching a sync block. This causes a deadlock with TM sometimes and should not be generally required. The implementation does not retain the Bridge anymore. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D17960236 fbshipit-source-id: 0ddea561a6884f066e483d6b0f41ddd1621df73c --- .../RCTSurfacePresenterBridgeAdapter.mm | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/React/Fabric/RCTSurfacePresenterBridgeAdapter.mm b/React/Fabric/RCTSurfacePresenterBridgeAdapter.mm index 73c1ac724a0..ceeb1a3d992 100644 --- a/React/Fabric/RCTSurfacePresenterBridgeAdapter.mm +++ b/React/Fabric/RCTSurfacePresenterBridgeAdapter.mm @@ -42,22 +42,25 @@ static ContextContainer::Shared RCTContextContainerFromBridge(RCTBridge *bridge) static RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge) { - RCTBridge *batchedBridge = [bridge batchedBridge] ?: bridge; + auto bridgeWeakWrapper = wrapManagedObjectWeakly([bridge batchedBridge] ?: bridge); - auto messageQueueThread = batchedBridge.jsMessageThread; - if (messageQueueThread) { - // Make sure initializeBridge completed - messageQueueThread->runOnQueueSync([] {}); - } + RuntimeExecutor runtimeExecutor = [bridgeWeakWrapper]( + std::function &&callback) { + [unwrapManagedObjectWeakly(bridgeWeakWrapper) invokeAsync:[bridgeWeakWrapper, callback = std::move(callback)]() { + RCTCxxBridge *batchedBridge = (RCTCxxBridge *)unwrapManagedObjectWeakly(bridgeWeakWrapper); - auto runtime = (facebook::jsi::Runtime *)((RCTCxxBridge *)batchedBridge).runtime; + if (!batchedBridge) { + return; + } - RuntimeExecutor runtimeExecutor = [batchedBridge, - runtime](std::function &&callback) { - // For now, ask the bridge to queue the callback asynchronously to ensure that - // it's not invoked too early, e.g. before the bridge is fully ready. - // Revisit this after Fabric/TurboModule is fully rolled out. - [((RCTCxxBridge *)batchedBridge) invokeAsync:[runtime, callback = std::move(callback)]() { callback(*runtime); }]; + auto runtime = (facebook::jsi::Runtime *)(batchedBridge.runtime); + + if (!runtime) { + return; + } + + callback(*runtime); + }]; }; return runtimeExecutor;