From e6b97cdca29fca1ef3c027521d7f22505fe1a175 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Tue, 3 Sep 2024 08:57:34 +0200 Subject: [PATCH] Fix live-reload on Firefox --- .../main/resources/web-bundler/live-reload.js | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/deployment/src/main/resources/web-bundler/live-reload.js b/deployment/src/main/resources/web-bundler/live-reload.js index 05f9275..520b14f 100644 --- a/deployment/src/main/resources/web-bundler/live-reload.js +++ b/deployment/src/main/resources/web-bundler/live-reload.js @@ -1,14 +1,13 @@ -let retry = 0; +let isReco = false; console.log("web-bundler live-reload is enabled"); function connectToChanges() { + console.debug("connecting to web-bundler live-reload: " + isReco) const eventSource = new EventSource(process.env.LIVE_RELOAD_PATH); eventSource.onopen = () => { - if (retry > 0) { - retry = 0; + if (isReco) { // server is back-on, let's reload to get the latest - eventSource.close(); location.reload(); } @@ -42,23 +41,12 @@ function connectToChanges() { } } } - eventSource.close(); location.reload(); }); eventSource.onerror = (e) => { - // Reconnect on error - eventSource.close(); - retry++; - if (retry > 40) { - console.error("web-bundler live-reload connection lost"); - return; - } - if (retry > 10) { // increase the interval after 10 attempts (~5s) - setTimeout(connectToChanges, 1000); - return; - } - setTimeout(connectToChanges, 500); + console.debug("web-bundler live-reload connection lost"); + isReco = true; }; }