Skip to content

Commit

Permalink
Fix crash when removing root nodes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ayc1 authored and facebook-github-bot committed Nov 14, 2018
1 parent 56a416e commit b649fa9
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.View;
import com.facebook.react.common.SingleThreadAsserter;

/**
Expand Down Expand Up @@ -36,6 +37,11 @@ public void addRootNode(ReactShadowNode node) {

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");
Expand Down

0 comments on commit b649fa9

Please sign in to comment.