Don't call FabricUIManager.stopSurface from ReactRootView with invalid ID

Summary:
There are cases under investigation where unmountReactApplication is called before the ReactRootView gets an ID; in some or all of those cases, UIManagerBinding.stopSurface cannot get the ReactFabric JSI module and crashes there.

It's still unclear why `unmountReactApplication` is being called in these circumstances - maybe another crash causing React Native teardown?

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D24214712

fbshipit-source-id: 796594653f4ff6d87088c4841b89f06cc873b46f
This commit is contained in:
Joshua Gross
2020-10-09 03:13:26 -07:00
committed by Facebook GitHub Bot
parent b581bcaae0
commit 0d02c60bae
@@ -35,6 +35,7 @@ import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableMap;
@@ -490,7 +491,14 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
UIManagerHelper.getUIManager(reactApplicationContext, getUIManagerType());
if (uiManager != null) {
FLog.e(TAG, "stopSurface for surfaceId: " + this.getId());
uiManager.stopSurface(this.getId());
if (getId() == NO_ID) {
ReactSoftException.logSoftException(
TAG,
new RuntimeException(
"unmountReactApplication called on ReactRootView with invalid id"));
} else {
uiManager.stopSurface(this.getId());
}
}
}
}