improve dev mode and HMR interop (#24377)

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: https://github.com/facebook/react-native/pull/24377

Differential Revision: D14890695

Pulled By: cpojer

fbshipit-source-id: 95b6ff4131c6d05a32aadd09a9d5ed11f602122c
This commit is contained in:
Vojtech Novak
2019-04-11 02:41:28 -07:00
committed by Facebook Github Bot
parent 9b63b50ad5
commit 3b1760d1d1
3 changed files with 13 additions and 1 deletions
@@ -88,6 +88,10 @@ public class DevInternalSettings implements
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);
@@ -459,6 +459,10 @@ public class DevSupportManagerImpl implements
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();
}
});
@@ -509,6 +513,10 @@ public class DevSupportManagerImpl implements
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();
}