Skip to content

Commit

Permalink
improve dev mode and HMR interop (facebook#24377)
Browse files Browse the repository at this point in the history
Summary:
Motivation is following - I'm sure many people encountered this because it has been like this for a long time.

1 . you're developing something on android, HMR and dev mode is enabled
2 . you go to dev settings, you disable dev mode because you want to see how something behaves
3 . you reload the app because that's what is required for the change to take effect
4 . you wait for the bundle to be compiled and served, and when that is done, you get an error message about HMR not being a registered callable module - because HMR is not available when `__DEV__ === false` (todo screenshot)

this fixes the described case by checking if HMR is enabled and dev mode disabled when reloading (step 3) and disables HMR in that case.

this also fixes the case when dev mode is disabled and without knowing it, you try to enable HRM (will enable both dev hmr and dev mode).

[Android] [Changed] - improve developer experience around Dev mode and HMR interop
Pull Request resolved: facebook#24377

Differential Revision: D14890695

Pulled By: cpojer

fbshipit-source-id: 95b6ff4131c6d05a32aadd09a9d5ed11f602122c
  • Loading branch information
vonovak authored and dsyang committed Apr 12, 2019
1 parent 2d025cc commit 0e9c943
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public boolean isJSDevModeEnabled() {
return mPreferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true);
}

public void setJSDevModeEnabled(boolean value) {
mPreferences.edit().putBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, value).apply();
}

@Override
public boolean isJSMinifyEnabled() {
return mPreferences.getBoolean(PREFS_JS_MINIFY_DEBUG_KEY, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ public void showDevOptionsDialog() {
new DevOptionHandler() {
@Override
public void onOptionSelected() {
if (!mDevSettings.isJSDevModeEnabled() && mDevSettings.isHotModuleReplacementEnabled()) {
Toast.makeText(mApplicationContext, "HMR cannot be enabled when Dev mode is off. Disabling HMR...", Toast.LENGTH_LONG).show();
mDevSettings.setHotModuleReplacementEnabled(false);
}
handleReloadJS();
}
});
Expand Down Expand Up @@ -509,6 +513,10 @@ public void onOptionSelected() {
new DevOptionHandler() {
@Override
public void onOptionSelected() {
if (!mDevSettings.isHotModuleReplacementEnabled() && !mDevSettings.isJSDevModeEnabled()) {
Toast.makeText(mApplicationContext, "You're trying to enable HMR while Dev mode is off. Turning both HMR and the Dev mode on...", Toast.LENGTH_LONG).show();
mDevSettings.setJSDevModeEnabled(true);
}
mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled());
handleReloadJS();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<CheckBoxPreference
android:key="js_dev_mode_debug"
android:title="JS Dev Mode"
android:summary="Load JavaScript bundle with __DEV__ = true for easier debugging. Disable for performance testing. Reload for the change to take effect."
android:summary="Load JavaScript bundle with __DEV__ = true for easier debugging. Disable for performance testing. Reload for the change to take effect."
android:defaultValue="true"
/>
<CheckBoxPreference
Expand Down

0 comments on commit 0e9c943

Please sign in to comment.