Reset ReactInstanceManager state on failure to allow retries (#32901)

Summary:
This fixes https://github.com/facebook/react-native/issues/32898 by reseting ReactInstanceManager state when `createReactContext` throws. By resetting the state, we allow future attempts at creating the React context.

## Changelog

[Android] [Fixed] - Fixed empty screen after retrying a BundleDownloader failure in dev mode

Pull Request resolved: https://github.com/facebook/react-native/pull/32901

Test Plan: Go through the steps to reproduce listed in https://github.com/facebook/react-native/issues/32898 and see that the React Native application starts.

Reviewed By: cortinico

Differential Revision: D33634178

Pulled By: ShikaSD

fbshipit-source-id: e54d12d5f33c9c7c0ca213113871b88c2f1dc261
This commit is contained in:
Sam Kline
2022-01-19 05:06:18 -08:00
committed by Facebook GitHub Bot
parent 3addafa525
commit c8d823b9bd
@@ -1103,14 +1103,22 @@ public class ReactInstanceManager {
// create
mHasStartedCreatingInitialContext = true;
final ReactApplicationContext reactApplicationContext;
try {
Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
ReactMarker.logMarker(VM_INIT);
final ReactApplicationContext reactApplicationContext =
reactApplicationContext =
createReactContext(
initParams.getJsExecutorFactory().create(),
initParams.getJsBundleLoader());
} catch (Exception e) {
// Reset state and bail out. This lets us try again later.
mHasStartedCreatingInitialContext = false;
mCreateReactContextThread = null;
mDevSupportManager.handleException(e);
return;
}
try {
mCreateReactContextThread = null;
ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_START);
final Runnable maybeRecreateReactContextRunnable =