From 478df155e70a4ce30219adcac6f0801c4e4d10ec Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Fri, 6 Sep 2019 03:46:45 -0700 Subject: [PATCH] Remove "Reload on JS change" from RN Android Summary: This feature is not necessary any longer with Fast Refresh enabled by default. Reviewed By: gaearon Differential Revision: D17156607 fbshipit-source-id: 2396a86d192c6b5d90cbed9cefbf13367dd6b699 --- .../react/devsupport/DevInternalSettings.java | 12 --- .../react/devsupport/DevServerHelper.java | 96 ------------------- .../devsupport/DevSupportManagerImpl.java | 32 +------ .../devsupport/DisabledDevSupportManager.java | 3 - .../interfaces/DevSupportManager.java | 2 - .../modules/debug/DevSettingsModule.java | 5 - 6 files changed, 1 insertion(+), 149 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java index 4465e8a6e9d75d..872ecb812e0b30 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java @@ -27,9 +27,6 @@ public class DevInternalSettings private static final String PREFS_JS_DEV_MODE_DEBUG_KEY = "js_dev_mode_debug"; private static final String PREFS_JS_MINIFY_DEBUG_KEY = "js_minify_debug"; private static final String PREFS_ANIMATIONS_DEBUG_KEY = "animations_debug"; - // This option is no longer exposed in the dev menu UI. - // It was renamed in D15958697 so it doesn't get stuck with no way to turn it off: - private static final String PREFS_RELOAD_ON_JS_CHANGE_KEY = "reload_on_js_change_LEGACY"; private static final String PREFS_INSPECTOR_DEBUG_KEY = "inspector_debug"; private static final String PREFS_HOT_MODULE_REPLACEMENT_KEY = "hot_module_replacement"; private static final String PREFS_REMOTE_JS_DEBUG_KEY = "remote_js_debug"; @@ -82,7 +79,6 @@ public boolean isJSMinifyEnabled() { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (mListener != null) { if (PREFS_FPS_DEBUG_KEY.equals(key) - || PREFS_RELOAD_ON_JS_CHANGE_KEY.equals(key) || PREFS_JS_DEV_MODE_DEBUG_KEY.equals(key) || PREFS_START_SAMPLING_PROFILER_ON_INIT.equals(key) || PREFS_JS_MINIFY_DEBUG_KEY.equals(key)) { @@ -99,14 +95,6 @@ public void setHotModuleReplacementEnabled(boolean enabled) { mPreferences.edit().putBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, enabled).apply(); } - public boolean isReloadOnJSChangeEnabled() { - return mPreferences.getBoolean(PREFS_RELOAD_ON_JS_CHANGE_KEY, false); - } - - public void setReloadOnJSChangeEnabled(boolean enabled) { - mPreferences.edit().putBoolean(PREFS_RELOAD_ON_JS_CHANGE_KEY, enabled).apply(); - } - public boolean isElementInspectorEnabled() { return mPreferences.getBoolean(PREFS_INSPECTOR_DEBUG_KEY, false); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java index 52c6477761108b..6cfdde1f427b70 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java @@ -8,16 +8,12 @@ import android.content.Context; import android.os.AsyncTask; -import android.os.Handler; -import android.os.Looper; import android.widget.Toast; import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; import com.facebook.react.R; -import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.common.ReactConstants; -import com.facebook.react.common.network.OkHttpCallUtil; import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener; import com.facebook.react.devsupport.interfaces.PackagerStatusCallback; import com.facebook.react.devsupport.interfaces.StackFrame; @@ -38,7 +34,6 @@ import java.util.concurrent.TimeUnit; import okhttp3.Call; import okhttp3.Callback; -import okhttp3.ConnectionPool; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -68,8 +63,6 @@ public class DevServerHelper { private static final String PACKAGER_OK_STATUS = "packager-status:running"; - private static final int LONG_POLL_KEEP_ALIVE_DURATION_MS = 2 * 60 * 1000; // 2 mins - private static final int LONG_POLL_FAILURE_DELAY_MS = 5000; private static final int HTTP_CONNECT_TIMEOUT_MS = 5000; private static final String DEBUGGER_MSG_DISABLE = "{ \"id\":1,\"method\":\"Debugger.disable\" }"; @@ -117,15 +110,11 @@ public String typeID() { private final DevInternalSettings mSettings; private final OkHttpClient mClient; - private final Handler mRestartOnChangePollingHandler; private final BundleDownloader mBundleDownloader; private final String mPackageName; - private boolean mOnChangePollingEnabled; private @Nullable JSPackagerClient mPackagerClient; private @Nullable InspectorPackagerConnection mInspectorPackagerConnection; - private @Nullable OkHttpClient mOnChangePollingClient; - private @Nullable OnServerContentChangeListener mOnServerContentChangeListener; private InspectorPackagerConnection.BundleStatusProvider mBundlerStatusProvider; public DevServerHelper( @@ -142,7 +131,6 @@ public DevServerHelper( .build(); mBundleDownloader = new BundleDownloader(mClient); - mRestartOnChangePollingHandler = new Handler(Looper.getMainLooper()); mPackageName = packageName; } @@ -524,90 +512,6 @@ private static String createPackagerStatusURL(String host) { return String.format(Locale.US, "http://%s/status", host); } - public void stopPollingOnChangeEndpoint() { - mOnChangePollingEnabled = false; - mRestartOnChangePollingHandler.removeCallbacksAndMessages(null); - if (mOnChangePollingClient != null) { - OkHttpCallUtil.cancelTag(mOnChangePollingClient, this); - mOnChangePollingClient = null; - } - mOnServerContentChangeListener = null; - } - - public void startPollingOnChangeEndpoint( - OnServerContentChangeListener onServerContentChangeListener) { - if (mOnChangePollingEnabled) { - // polling already enabled - return; - } - mOnChangePollingEnabled = true; - mOnServerContentChangeListener = onServerContentChangeListener; - mOnChangePollingClient = - new OkHttpClient.Builder() - .connectionPool( - new ConnectionPool(1, LONG_POLL_KEEP_ALIVE_DURATION_MS, TimeUnit.MILLISECONDS)) - .connectTimeout(HTTP_CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS) - .build(); - enqueueOnChangeEndpointLongPolling(); - } - - private void handleOnChangePollingResponse(boolean didServerContentChanged) { - if (mOnChangePollingEnabled) { - if (didServerContentChanged) { - UiThreadUtil.runOnUiThread( - new Runnable() { - @Override - public void run() { - if (mOnServerContentChangeListener != null) { - mOnServerContentChangeListener.onServerContentChanged(); - } - } - }); - } - enqueueOnChangeEndpointLongPolling(); - } - } - - private void enqueueOnChangeEndpointLongPolling() { - Request request = new Request.Builder().url(createOnChangeEndpointUrl()).tag(this).build(); - Assertions.assertNotNull(mOnChangePollingClient) - .newCall(request) - .enqueue( - new Callback() { - @Override - public void onFailure(Call call, IOException e) { - if (mOnChangePollingEnabled) { - // this runnable is used by onchange endpoint poller to delay subsequent requests - // in case - // of a failure, so that we don't flood network queue with frequent requests in - // case when - // dev server is down - FLog.d(ReactConstants.TAG, "Error while requesting /onchange endpoint", e); - mRestartOnChangePollingHandler.postDelayed( - new Runnable() { - @Override - public void run() { - handleOnChangePollingResponse(false); - } - }, - LONG_POLL_FAILURE_DELAY_MS); - } - } - - @Override - public void onResponse(Call call, Response response) throws IOException { - handleOnChangePollingResponse(response.code() == 205); - } - }); - } - - private String createOnChangeEndpointUrl() { - return String.format( - Locale.US, - "http://%s/onchange", - mSettings.getPackagerConnectionSettings().getDebugServerHost()); - } - private String createLaunchJSDevtoolsCommandUrl() { return String.format( Locale.US, diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index 163e27e4ef6637..208f786da260c3 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -517,9 +517,7 @@ public void onOptionSelected() { mReactInstanceManagerHelper.toggleElementInspector(); } }); - // "Live reload" which refreshes on every edit was removed in favor of "Fast Refresh". - // While native code for "Live reload" is still there, please don't add the option back. - // See D15958697 for more context. + options.put( mDevSettings.isHotModuleReplacementEnabled() ? mApplicationContext.getString(R.string.catalyst_hot_reloading_stop) @@ -1132,22 +1130,6 @@ public void run() { }); } - @Override - public void setReloadOnJSChangeEnabled(final boolean isReloadOnJSChangeEnabled) { - if (!mIsDevSupportEnabled) { - return; - } - - UiThreadUtil.runOnUiThread( - new Runnable() { - @Override - public void run() { - mDevSettings.setReloadOnJSChangeEnabled(isReloadOnJSChangeEnabled); - handleReloadJS(); - } - }); - } - @Override public void setFpsDebugEnabled(final boolean isFpsDebugEnabled) { if (!mIsDevSupportEnabled) { @@ -1210,17 +1192,6 @@ private void reload() { } mDevServerHelper.openPackagerConnection(this.getClass().getSimpleName(), this); - if (mDevSettings.isReloadOnJSChangeEnabled()) { - mDevServerHelper.startPollingOnChangeEndpoint( - new DevServerHelper.OnServerContentChangeListener() { - @Override - public void onServerContentChanged() { - handleReloadJS(); - } - }); - } else { - mDevServerHelper.stopPollingOnChangeEndpoint(); - } } else { // hide FPS debug overlay if (mDebugOverlayController != null) { @@ -1248,7 +1219,6 @@ public void onServerContentChanged() { // hide loading view mDevLoadingViewController.hide(); mDevServerHelper.closePackagerConnection(); - mDevServerHelper.stopPollingOnChangeEndpoint(); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DisabledDevSupportManager.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DisabledDevSupportManager.java index 09de892ecdf8f5..559882023010de 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DisabledDevSupportManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DisabledDevSupportManager.java @@ -63,9 +63,6 @@ public void setHotModuleReplacementEnabled(boolean isHotModuleReplacementEnabled @Override public void setRemoteJSDebugEnabled(boolean isRemoteJSDebugEnabled) {} - @Override - public void setReloadOnJSChangeEnabled(boolean isReloadOnJSChangeEnabled) {} - @Override public void setFpsDebugEnabled(boolean isFpsDebugEnabled) {} diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java index 360b76c04e7e01..40d5e5a5882cde 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java @@ -68,8 +68,6 @@ public interface DevSupportManager extends NativeModuleCallExceptionHandler { void setRemoteJSDebugEnabled(final boolean isRemoteJSDebugEnabled); - void setReloadOnJSChangeEnabled(final boolean isReloadOnJSChangeEnabled); - void setFpsDebugEnabled(final boolean isFpsDebugEnabled); void toggleElementInspector(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DevSettingsModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DevSettingsModule.java index af47025d789129..817084d8691d11 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DevSettingsModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DevSettingsModule.java @@ -54,11 +54,6 @@ public void setIsDebuggingRemotely(boolean isDebugginRemotelyEnabled) { mDevSupportManager.setRemoteJSDebugEnabled(isDebugginRemotelyEnabled); } - @ReactMethod - public void setLiveReloadEnabled(boolean isLiveReloadEnabled) { - mDevSupportManager.setReloadOnJSChangeEnabled(isLiveReloadEnabled); - } - @ReactMethod public void setProfilingEnabled(boolean isProfilingEnabled) { mDevSupportManager.setFpsDebugEnabled(isProfilingEnabled);