From b649fa96a088a9e8ccbf3f979ebfa4a5e28a066f Mon Sep 17 00:00:00 2001 From: "Andrew Chen (Eng)" Date: Wed, 14 Nov 2018 10:54:30 -0800 Subject: [PATCH] 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 --- .../com/facebook/react/uimanager/ShadowNodeRegistry.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ShadowNodeRegistry.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ShadowNodeRegistry.java index 74a136cac..4ce41a0bb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ShadowNodeRegistry.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ShadowNodeRegistry.java @@ -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");