From 9b8ffeee4c54eb05ca74d626b171a958fa6db4d4 Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Wed, 15 Jul 2020 03:45:17 -0700 Subject: [PATCH] Fix the redbox when running Metro with Venice enabled. Summary: 1, Fix the redbox on Pokes route when running Metro with Venice enabled. 2, Fix CrashReactRoute stucking with the loading indicator issue. Changelog: [Internal] Reviewed By: ejanzer Differential Revision: D22477500 fbshipit-source-id: 65e908ac360e031e5f3562a21c09cb0d7ddaf7a0 --- .../devsupport/DevSupportManagerBase.java | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java index 2e118ffa1ac93e..427c7f37a1ac16 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java @@ -70,6 +70,12 @@ public abstract class DevSupportManagerBase implements DevSupportManager, PackagerCommandListener, DevInternalSettings.Listener { + public interface CallbackWithBundleLoader { + void onSuccess(JSBundleLoader bundleLoader); + + void onError(String url, Throwable cause); + } + private static final int JAVA_ERROR_COOKIE = -1; private static final int JSEXCEPTION_ERROR_COOKIE = -1; private static final String JS_BUNDLE_FILE_NAME = "ReactNativeDevBundle.js"; @@ -863,7 +869,29 @@ public void handleReloadJS() { } @Override - public void loadSplitBundleFromServer(String bundlePath, final DevSplitBundleCallback callback) { + public void loadSplitBundleFromServer( + final String bundlePath, final DevSplitBundleCallback callback) { + fetchSplitBundleAndCreateBundleLoader( + bundlePath, + new CallbackWithBundleLoader() { + @Override + public void onSuccess(JSBundleLoader bundleLoader) { + bundleLoader.loadScript(mCurrentContext.getCatalystInstance()); + mCurrentContext + .getJSModule(HMRClient.class) + .registerBundle(mDevServerHelper.getDevServerSplitBundleURL(bundlePath)); + callback.onSuccess(); + } + + @Override + public void onError(String url, Throwable cause) { + callback.onError(url, cause); + } + }); + } + + public void fetchSplitBundleAndCreateBundleLoader( + String bundlePath, final CallbackWithBundleLoader callback) { final String bundleUrl = mDevServerHelper.getDevServerSplitBundleURL(bundlePath); // The bundle path may contain the '/' character, which is not allowed in file names. final File bundleFile = @@ -886,16 +914,16 @@ public void run() { }); @Nullable ReactContext context = mCurrentContext; - if (context == null || !context.hasActiveCatalystInstance()) { + if (context == null + || (!context.isBridgeless() && !context.hasActiveCatalystInstance())) { return; } - JSBundleLoader.createCachedSplitBundleFromNetworkLoader( - bundleUrl, bundleFile.getAbsolutePath()) - .loadScript(context.getCatalystInstance()); - context.getJSModule(HMRClient.class).registerBundle(bundleUrl); + JSBundleLoader bundleLoader = + JSBundleLoader.createCachedSplitBundleFromNetworkLoader( + bundleUrl, bundleFile.getAbsolutePath()); - callback.onSuccess(); + callback.onSuccess(bundleLoader); } @Override