fix: persist SSE debounce across page reloads via sessionStorage
Build and Deploy / build-and-deploy (push) Successful in 1m20s

The in-memory lastReload variable was lost on location.reload() because
the JavaScript context is destroyed. This caused a reload loop when the
watcher fired multiple SSE events for the same file change — each reload
reset the debounce to 0, so the next event would trigger another reload.

Switch to sessionStorage, which persists across page loads within the
same browser tab session. Also increases the debounce window to 3000ms
to account for page load time.
This commit is contained in:
2026-05-20 15:42:01 -04:00
parent 7b7c522080
commit d77f4eb59f
+6 -6
View File
@@ -351,12 +351,12 @@ sseRecipeJs =
, "if (!el) return;"
, "var currentRecipe = el.textContent;"
, "var es = new EventSource('/events');"
, "var lastReload = 0;"
, "var lastReload = parseInt(sessionStorage.getItem('roux-last-reload') || '0', 10);"
, "es.addEventListener('recipe-changed', function(e) {"
, " if (e.data !== currentRecipe) return;"
, " var now = Date.now();"
, " if (now - lastReload < 2000) return;"
, " lastReload = now;"
, " if (now - lastReload < 3000) return;"
, " sessionStorage.setItem('roux-last-reload', String(now));"
, " location.reload();"
, "});"
, "})();"
@@ -370,11 +370,11 @@ sseIndexJs =
, "'use strict';"
, "if (!window.EventSource) return;"
, "var es = new EventSource('/events');"
, "var lastReload = 0;"
, "var lastReload = parseInt(sessionStorage.getItem('roux-last-reload') || '0', 10);"
, "es.addEventListener('recipe-changed', function() {"
, " var now = Date.now();"
, " if (now - lastReload < 2000) return;"
, " lastReload = now;"
, " if (now - lastReload < 3000) return;"
, " sessionStorage.setItem('roux-last-reload', String(now));"
, " location.reload();"
, "});"
, "})();"