Fix crash when removing root nodes

Summary: If a root node is being removed and has an id of NO_ID, it was likely already removed 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: mdvacca

Differential Revision: D13055140

fbshipit-source-id: ec10f4c79f2ba21614f52f57557f6b3d734c9461
This commit is contained in:
Andrew Chen (Eng)
2018-11-14 10:54:30 -08:00
committed by Facebook Github Bot
parent 56a416e3be
commit b649fa96a0

View File

@@ -9,6 +9,7 @@ package com.facebook.react.uimanager;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.View;
import com.facebook.react.common.SingleThreadAsserter;
/**
@@ -36,6 +37,11 @@ public class ShadowNodeRegistry {
public void removeRootNode(int tag) {
mThreadAsserter.assertNow();
if (tag == View.NO_ID) {
// This root node has already been removed (likely due to a threading issue caused by async js
// execution). Ignore this root removal.
return;
}
if (!mRootTags.get(tag)) {
throw new IllegalViewOperationException(
"View with tag " + tag + " is not registered as a root view");