From c8d823b9bd9619dfa1f5851af003cc24ba2e8830 Mon Sep 17 00:00:00 2001 From: Sam Kline Date: Wed, 19 Jan 2022 05:04:51 -0800 Subject: [PATCH] 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 --- .../com/facebook/react/ReactInstanceManager.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 48b7e4820c0..8a10a9066ff 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -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 =