Skip to content

Commit

Permalink
Default to ignoring cached Metro bundle when offline (#38076)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38076

Changelog: [Android][Breaking] Default to ignoring cached Metro bundle when offline

Currently, on Android, if we can't find a Metro server at startup, we try to run the last cached Metro bundle instead of the prebuilt bundle asset in the APK. This is inconsistent with the iOS behaviour, and breaks bundle features that rely on a runtime Metro connection to work correctly - such as HTTP asset loading and lazy bundling (which is the default as of D43600054).

Here we change the default for `ReactInstanceManager`'s `useFallbackBundle` property to `true`, which has the effect of ignoring the cached Metro bundle.

This is a **breaking change** because some developers' workflows might depend on performing a build while connected to a Metro instance, then using the app standalone without access to Metro. This may be exacerbated by the fact that the RN Gradle plugin [skips including a prebuilt bundle in debug builds](https://github.com/facebook/react-native/blob/eaafc260c14674bfbf7ce3a647404c70d546854f/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt#L54). This means that, out of the box, debug builds of Android RN apps will only start if connected to Metro. (Contrast with iOS where a "fallback" bundle *is* included out of the box.)

We recommend that developers always connect to a Metro server in development, and perform a release build for standalone use. Alternatively, developers can use `ReactInstanceManager.setUseFallbackBundle(false)` to restore the old behaviour.

Reviewed By: javache, luluwu2032

Differential Revision: D47021957

fbshipit-source-id: 43ce8078ec95f5d65790b56f4d3dfa4f6a4e9023
  • Loading branch information
motiz88 authored and facebook-github-bot committed Jun 27, 2023
1 parent 71f715a commit 2d61060
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public interface ReactInstanceEventListener
private final @Nullable JSIModulePackage mJSIModulePackage;
private final @Nullable ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder;
private List<ViewManager> mViewManagers;
private boolean mUseFallbackBundle = false;
private boolean mUseFallbackBundle = true;

private class ReactContextInitParams {
private final JavaScriptExecutorFactory mJsExecutorFactory;
Expand Down

0 comments on commit 2d61060

Please sign in to comment.