From d748ace5db626471293bc8ffc676d0f9de741b2b Mon Sep 17 00:00:00 2001 From: Evert Eti Date: Mon, 25 Mar 2024 20:42:32 +0100 Subject: [PATCH] Fix possible deadlock in dispatchViewUpdates --- .../com/facebook/react/uimanager/UIImplementation.java | 8 +------- .../com/facebook/react/uimanager/UIManagerModule.java | 7 ++++++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java index 0dbe9352b779e8..6b3ac1afd410de 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java @@ -177,7 +177,7 @@ public void removeRootView(int rootViewTag) { * * @return The num of root view */ - private int getRootViewNum() { + public int getRootViewNum() { return mOperationsQueue.getNativeViewHierarchyManager().getRootViewNum(); } @@ -589,12 +589,6 @@ public void measureLayoutRelativeToParent( /** Invoked at the end of the transaction to commit any updates to the node hierarchy. */ public void dispatchViewUpdates(int batchId) { - if (getRootViewNum() <= 0) { - // If there are no RootViews registered, there will be no View updates to dispatch. - // This is a hack to prevent this from being called when Fabric is used everywhere. - // This should no longer be necessary in Bridgeless Mode. - return; - } SystraceMessage.beginSection( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "UIImplementation.dispatchViewUpdates") .arg("batchId", batchId) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index 15a1b42542989d..dca4fcf5b13098 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -707,7 +707,12 @@ public void onBatchComplete() { listener.willDispatchViewUpdates(this); } try { - mUIImplementation.dispatchViewUpdates(batchId); + // If there are no RootViews registered, there will be no View updates to dispatch. + // This is a hack to prevent this from being called when Fabric is used everywhere. + // This should no longer be necessary in Bridgeless Mode. + if (mUIImplementation.getRootViewNum() > 0) { + mUIImplementation.dispatchViewUpdates(batchId); + } } finally { Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); }