Skip to content
Permalink
Browse files
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
  • Loading branch information
cpojer authored and facebook-github-bot committed Sep 6, 2019
1 parent b1c954b commit 478df155e70a4ce30219adcac6f0801c4e4d10ec
Showing 6 changed files with 1 addition and 149 deletions.
@@ -27,9 +27,6 @@
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);
}
@@ -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,
@@ -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();
}
}

@@ -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) {}

@@ -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();
@@ -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);

0 comments on commit 478df15

Please sign in to comment.