From 8a9d963e66ace6e4cda1a9e7d146f562bf4feb3d Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Fri, 14 Jun 2024 17:47:36 +0100 Subject: [PATCH] :bug: Fix bug where socket would try to reconnect far too many times. --- priv/server/live-reload.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/priv/server/live-reload.js b/priv/server/live-reload.js index d35b9ec..89f9f15 100644 --- a/priv/server/live-reload.js +++ b/priv/server/live-reload.js @@ -21,12 +21,16 @@ function connect() { // refresh. socket.onclose = () => { socket = null; - if (!timeout) timeout = setTimeout(() => connect(), 5000); + + if (timeout) clearTimeout(timeout); + if (!socket) timeout = setTimeout(() => connect(), 5000); }; socket.onerror = () => { socket = null; - if (!timeout) timeout = setTimeout(() => connect(), 5000); + + if (timeout) clearTimeout(timeout); + if (!socket) timeout = setTimeout(() => connect(), 5000); }; }