From ae05d780c798f8199678aa8a89bdb41c96b136d6 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 2 Feb 2024 13:08:44 -0800 Subject: [PATCH] reload: Add on-focus handler after a delay. (cherry picked from commit 9479eae87f1c1fa77bebb335b91a5fd2cc86494a) --- web/src/reload.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/src/reload.js b/web/src/reload.js index 8d2baf22f0..a253e2cd18 100644 --- a/web/src/reload.js +++ b/web/src/reload.js @@ -175,10 +175,17 @@ function do_reload_app(send_after_reload, save_pointer, save_narrow, save_compos // broken state and cause lots of confusing tracebacks. So, we // set ourselves to try reloading a bit later, both periodically // and when the user focuses the window. - $(window).one("focus", () => { - blueslip.log("Retrying on-focus page reload"); - window.location.reload(true); - }); + setTimeout(() => { + // We add this handler after a bit of delay, because in some + // browsers, processing window.location.reload causes the + // window to gain focus, and duplicate reload attempts result + // in the browser sending duplicate requests to `/`. + $(window).one("focus", () => { + blueslip.log("Retrying on-focus page reload"); + + window.location.reload(true); + }); + }, 5000); function retry_reload() { blueslip.log("Retrying page reload due to 30s timer");