From e2892a88c1252e1ccf6030f5c887ba07342569b3 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 13 Feb 2020 12:34:54 -0800 Subject: [PATCH] channel: Discard all HTTP responses while reloading. We used to have a block of code doing this just in the presence endpoint because that's where we'd had error-handling problems with it not being present, but it seems more correct for it to run unconditionally on all HTTP requests. This requires adding a dependency of channel on reload_state, which we record in the webpack configuration for now. --- frontend_tests/node_tests/channel.js | 1 + static/js/activity.js | 5 ----- static/js/channel.js | 9 +++++++++ tools/test-js-with-node | 2 ++ tools/webpack.assets.json | 2 ++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend_tests/node_tests/channel.js b/frontend_tests/node_tests/channel.js index 3da976f31f..4e66bde9fc 100644 --- a/frontend_tests/node_tests/channel.js +++ b/frontend_tests/node_tests/channel.js @@ -2,6 +2,7 @@ set_global('blueslip', global.make_zblueslip()); set_global('$', {}); set_global('reload', {}); +zrequire('reload_state'); zrequire('channel'); diff --git a/static/js/activity.js b/static/js/activity.js index df2cd831ee..0ccc423785 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -323,11 +323,6 @@ function send_presence_to_server(want_redraw) { }, idempotent: true, success: function (data) { - if (reload_state.is_in_progress()) { - blueslip.log("Ignoring presence response because reload in progress"); - return; - } - // Update Zephyr mirror activity warning if (data.zephyr_mirror_active === false) { $('#zephyr-mirror-error').addClass("show"); diff --git a/static/js/channel.js b/static/js/channel.js index 60bed8f69f..8a0fa2450f 100644 --- a/static/js/channel.js +++ b/static/js/channel.js @@ -49,6 +49,15 @@ function call(args, idempotent) { args.success = function wrapped_success(data, textStatus, jqXHR) { remove_pending_request(jqXHR); + if (reload_state.is_in_progress()) { + // If we're in the process of reloading the browser, + // there's no point in running the success handler, + // because all of our state is about to be discarded + // anyway. + blueslip.log(`Ignoring ${args.type} ${args.url} response while reloading`); + return; + } + if (!data && idempotent) { // If idempotent, retry blueslip.log("Retrying idempotent" + args); diff --git a/tools/test-js-with-node b/tools/test-js-with-node index da966f9ebb..aaaaf29883 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -37,6 +37,8 @@ EXEMPT_FILES = { 'static/js/billing/helpers.js', 'static/js/blueslip.js', 'static/js/blueslip_stacktrace.ts', + # Removed temporarily. + 'static/js/channel.js', 'static/js/click_handlers.js', 'static/js/compose_actions.js', 'static/js/composebox_typeahead.js', diff --git a/tools/webpack.assets.json b/tools/webpack.assets.json index 7b7d481140..844895b5e3 100644 --- a/tools/webpack.assets.json +++ b/tools/webpack.assets.json @@ -104,11 +104,13 @@ "./static/js/bundles/portico.js", "./static/js/portico/integrations_dev_panel.js", "./static/styles/portico/integrations_dev_panel.css", + "./static/js/reload_state.js", "./static/js/channel.js" ], "email-log": [ "./static/js/bundles/common.js", "./static/js/portico/email_log.js", + "./static/js/reload_state.js", "./static/js/channel.js" ], "stats": [