From c84f35644d277bac327a9628f29c80cb0ab622dd Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 18 Aug 2022 17:46:59 -0700 Subject: [PATCH] channel: Stop monkey-patching password change counts into XHR objects. Signed-off-by: Anders Kaseorg --- static/js/channel.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/static/js/channel.js b/static/js/channel.js index eb2d6a172b..46403b80da 100644 --- a/static/js/channel.js +++ b/static/js/channel.js @@ -14,7 +14,6 @@ export function set_password_change_in_progress(value) { password_changes += 1; } } -export const xhr_password_changes = new WeakMap(); const pending_requests = []; @@ -47,6 +46,12 @@ function call(args) { return undefined; } + // Remember the number of completed password changes when the + // request was initiated. This allows us to detect race + // situations where a password change occurred before we got a + // response that failed due to the ongoing password change. + const orig_password_changes = password_changes; + // Wrap the error handlers to reload the page if we get a CSRF error // (What probably happened is that the user logged out in another tab). let orig_error = args.error; @@ -66,7 +71,7 @@ function call(args) { } if (xhr.status === 401) { - if (password_change_in_progress || xhr.password_changes !== password_changes) { + if (password_change_in_progress || orig_password_changes !== password_changes) { // The backend for handling password change API requests // will replace the user's session; this results in a // brief race where any API request will fail with a 401 @@ -134,12 +139,6 @@ function call(args) { const jqXHR = $.ajax(args); add_pending_request(jqXHR); - // Remember the number of completed password changes when the - // request was initiated. This allows us to detect race - // situations where a password change occurred before we got a - // response that failed due to the ongoing password change. - jqXHR.password_changes = password_changes; - return jqXHR; }