fix: refresh all dashboard thumbnails on tab return and add periodic fallback
Two issues caused stale thumbnails on the dashboard: 1. Returning to the dashboard tab only processed the (empty) refresh queue — it never triggered a full refresh. Now, if the dashboard was hidden for more than 3 seconds, all ETags are cleared and refreshAll() is called so every tile fetches a fresh screenshot. 2. If SSE activity events were missed (e.g. during reconnect), tiles would never update until the next terminal activity. Added a 10s periodic fallback that calls refreshAll() when the dashboard is visible, ensuring tiles stay reasonably current even without SSE.
This commit is contained in:
@@ -1486,16 +1486,38 @@ func (s *LocalServer) handleRoot(w http.ResponseWriter, r *http.Request) {
|
||||
return document.visibilityState === 'visible';
|
||||
}
|
||||
|
||||
let dashboardHiddenAt = 0;
|
||||
|
||||
function onDashboardFocusChanged() {
|
||||
if (dashboardCanRequestScreenshots()) {
|
||||
// If the dashboard was hidden for more than a few seconds,
|
||||
// clear ETags and refresh all tiles so the user sees current state.
|
||||
const away = dashboardHiddenAt ? (Date.now() - dashboardHiddenAt) : 0;
|
||||
dashboardHiddenAt = 0;
|
||||
if (away > 3000) {
|
||||
for (const key in etagBySlug) {
|
||||
delete etagBySlug[key];
|
||||
}
|
||||
refreshAll();
|
||||
} else {
|
||||
processRefreshQueue();
|
||||
}
|
||||
} else {
|
||||
dashboardHiddenAt = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('visibilitychange', onDashboardFocusChanged);
|
||||
window.addEventListener('focus', onDashboardFocusChanged);
|
||||
window.addEventListener('blur', onDashboardFocusChanged);
|
||||
|
||||
// Periodic fallback: refresh all tiles every 10s in case SSE events were missed.
|
||||
setInterval(() => {
|
||||
if (dashboardCanRequestScreenshots()) {
|
||||
refreshAll();
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
function processRefreshQueue() {
|
||||
if (refreshQueue.length === 0 || !dashboardCanRequestScreenshots()) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user