From 39b68903463062f69c9120fab7e79fa2735b0b07 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 11 Dec 2018 03:22:36 -0800 Subject: [PATCH] Fix crash when removing root nodes Summary: If a children of a root node is being removed and the Root Node is empty, it was likely already removed and cleaned previously, likely due to a race condition caused by RN's async nature. In those cases, let's avoid crashing the app and instead silently ignore the root view removal. Reviewed By: fkgozali Differential Revision: D13405817 fbshipit-source-id: 0179d10a88a2d19f1db5ea35b48cb83d9d7429a6 --- .../facebook/react/uimanager/NativeViewHierarchyManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java index df3e443f96c..b9064170ac7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java @@ -382,6 +382,11 @@ public class NativeViewHierarchyManager { tagsToDelete)); } if (indexToRemove >= viewManager.getChildCount(viewToManage)) { + if (mRootTags.get(tag) && viewManager.getChildCount(viewToManage) == 0) { + // This root node has already been removed (likely due to a threading issue caused by + // async js execution). Ignore this root removal. + return; + } throw new IllegalViewOperationException( "Trying to remove a view index above child " + "count " + indexToRemove + " view tag: " + tag + "\n detail: " +