Skip to content

Commit

Permalink
Fix the redbox when running Metro with Venice enabled.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Jul 15, 2020
1 parent 7485e93 commit 9b8ffee
Showing 1 changed file with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 =
Expand All @@ -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
Expand Down

0 comments on commit 9b8ffee

Please sign in to comment.