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
This commit is contained in:
David Vacca 2018-12-11 03:22:36 -08:00 committed by Facebook Github Bot
parent 2918679479
commit 39b6890346

View File

@ -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: " +