fix: deduplicate SSE events and debounce client reload
Build and Deploy / build-and-deploy (push) Successful in 1m39s
Build and Deploy / build-and-deploy (push) Successful in 1m39s
This commit is contained in:
+13
-2
@@ -344,8 +344,13 @@ sseRecipeJs =
|
||||
, "if (!el) return;"
|
||||
, "var currentRecipe = el.textContent;"
|
||||
, "var es = new EventSource('/events');"
|
||||
, "var lastReload = 0;"
|
||||
, "es.addEventListener('recipe-changed', function(e) {"
|
||||
, " if (e.data === currentRecipe) location.reload();"
|
||||
, " if (e.data !== currentRecipe) return;"
|
||||
, " var now = Date.now();"
|
||||
, " if (now - lastReload < 2000) return;"
|
||||
, " lastReload = now;"
|
||||
, " location.reload();"
|
||||
, "});"
|
||||
, "})();"
|
||||
]
|
||||
@@ -358,7 +363,13 @@ sseIndexJs =
|
||||
, "'use strict';"
|
||||
, "if (!window.EventSource) return;"
|
||||
, "var es = new EventSource('/events');"
|
||||
, "es.addEventListener('recipe-changed', function() { location.reload(); });"
|
||||
, "var lastReload = 0;"
|
||||
, "es.addEventListener('recipe-changed', function() {"
|
||||
, " var now = Date.now();"
|
||||
, " if (now - lastReload < 2000) return;"
|
||||
, " lastReload = now;"
|
||||
, " location.reload();"
|
||||
, "});"
|
||||
, "})();"
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user