fix(sidebar): refresh timestamp labels on tab return

Add a dedicated visibilitychange hook for the 60s relative-time refresh poll so skipped hidden-tab ticks repaint immediately when the tab becomes visible, even when no streaming poll is active.
This commit is contained in:
TARS 2026-07-03 20:13:24 +02:00
parent fcf3e23643
commit 3f4ebf18a8
2 changed files with 20 additions and 2 deletions

View file

@ -4595,6 +4595,7 @@ const _activeSessionExternalRefreshMs = 30000;
let _streamingPollTimer = null;
let _sessionTimeRefreshTimer = null;
let _streamingPollVisibilityHandler = null;
let _sessionTimeRefreshVisibilityHandler = null;
let _activeSessionExternalRefreshTimer = null;
let _activeSessionExternalRefreshInFlight = false;
let _deferredActiveSessionExternalRefreshReason = '';
@ -4646,11 +4647,17 @@ function stopStreamingPoll(){
function ensureSessionTimeRefreshPoll(){
if(_sessionTimeRefreshTimer) return;
_sessionTimeRefreshTimer = setInterval(() => {
// Relative-time labels only matter when visible; the tab-shown refresh in
// startStreamingPoll re-renders the list (and its timestamps) on return.
// Relative-time labels only matter when visible; the visibilitychange
// handler below refreshes timestamps immediately when the tab is shown.
if(typeof document !== 'undefined' && document.hidden) return;
renderSessionListFromCache();
}, _sessionTimeRefreshMs);
if(typeof document !== 'undefined' && !_sessionTimeRefreshVisibilityHandler){
_sessionTimeRefreshVisibilityHandler = () => {
if(!document.hidden) renderSessionListFromCache();
};
document.addEventListener('visibilitychange', _sessionTimeRefreshVisibilityHandler);
}
}
function _deferActiveSessionExternalRefresh(reason){

View file

@ -79,6 +79,17 @@ def test_active_session_external_refresh_has_focus_and_visibility_hooks():
assert "ensureActiveSessionExternalRefreshPoll();" in SESSIONS_JS
def test_session_time_refresh_has_own_visibility_hook():
"""Skipped hidden-tab timestamp ticks must refresh immediately on return."""
start = SESSIONS_JS.find("function ensureSessionTimeRefreshPoll()")
assert start != -1
block = SESSIONS_JS[start:start + 900]
assert "_sessionTimeRefreshVisibilityHandler" in SESSIONS_JS
assert "document.addEventListener('visibilitychange', _sessionTimeRefreshVisibilityHandler);" in block
assert "if(!document.hidden) renderSessionListFromCache();" in block
assert "startStreamingPoll re-renders the list" not in block
def test_session_list_external_refresh_uses_sse_invalidation_not_polling():
"""New sessions should refresh the sidebar from server invalidation events."""
assert "async function refreshSessionList(reason='manual', opts={})" in SESSIONS_JS