From 9e3856fd99ee150e4e51741e9f1d3df970a8d3a1 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 10 May 2019 15:31:00 -0700 Subject: [PATCH] Fabric: Fixed threading issues in RCTSurfacePresenter Summary: RCTComponentViewRegistry is not a thread-safe class and must be accessed only from the main thread. Reviewed By: JoshuaGross Differential Revision: D15296475 fbshipit-source-id: 67192abd6290191f3b8119972efc41cec48a793a --- React/Fabric/RCTSurfacePresenter.mm | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 15a0f40ad8e..1bf3ae3d93a 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -250,8 +250,11 @@ using namespace facebook::react; - (void)_startSurface:(RCTFabricSurface *)surface { - [_mountingManager.componentViewRegistry dequeueComponentViewWithComponentHandle:RootShadowNode::Handle() - tag:surface.rootTag]; + RCTMountingManager *mountingManager = _mountingManager; + RCTExecuteOnMainQueue(^{ + [mountingManager.componentViewRegistry dequeueComponentViewWithComponentHandle:RootShadowNode::Handle() + tag:surface.rootTag]; + }); LayoutContext layoutContext = { .pointScaleFactor = RCTScreenScale() @@ -273,11 +276,14 @@ using namespace facebook::react; { [self._scheduler stopSurfaceWithSurfaceId:surface.rootTag]; - UIView *rootView = - [_mountingManager.componentViewRegistry componentViewByTag:surface.rootTag]; - [_mountingManager.componentViewRegistry enqueueComponentViewWithComponentHandle:RootShadowNode::Handle() - tag:surface.rootTag - componentView:rootView]; + RCTMountingManager *mountingManager = _mountingManager; + RCTExecuteOnMainQueue(^{ + UIView *rootView = + [mountingManager.componentViewRegistry componentViewByTag:surface.rootTag]; + [mountingManager.componentViewRegistry enqueueComponentViewWithComponentHandle:RootShadowNode::Handle() + tag:surface.rootTag + componentView:rootView]; + }); [surface _unsetStage:(RCTSurfaceStagePrepared | RCTSurfaceStageMounted)]; }