Fix stale time deltas after browser sleep/tab suspension - #3149
Conversation
deltaTime and serverDeltaTime are computed once on the first AJAX response and cached for the lifetime of the page. When the browser sleeps or the tab is suspended, the cached values become stale, causing all displayed timestamps to be offset by the sleep duration. Reset both values to 0 on visibilitychange so Ajax_UpdateTime recalculates them from the next fresh response. Co-authored-by: AI (Gemini via Antigravity IDE)
There was a problem hiding this comment.
Pull request overview
This PR addresses incorrect UI timestamps after browser sleep/tab suspension by forcing a recalculation of cached client/server time deltas when the page becomes visible again.
Changes:
- Add a
visibilitychangelistener to resettheWebUI.deltaTimeandtheWebUI.serverDeltaTimewhen the tab becomes visible. - Ensure subsequent AJAX responses recompute time deltas via the existing
Ajax_UpdateTimelogic.
Suppressed comments (1)
js/rtorrent.js:1386
js/rtorrent.jsis loaded beforejs/webui.js(seeindex.htmlpreload order), sovisibilitychangecan fire whiletheWebUIis still undefined (e.g., page opened in a background tab). That would throw aReferenceErrorand potentially break further initialization. Guard access totheWebUI(or usewindow.theWebUI) before resetting the deltas.
if(!document.hidden)
{
theWebUI.deltaTime = 0;
theWebUI.serverDeltaTime = 0;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add tests covering the visibilitychange event handler in rtorrent.js that resets deltaTime and serverDeltaTime when a tab becomes visible after browser sleep or tab suspension. - Verify both deltas are reset to 0 when document becomes visible, ensuring Ajax_UpdateTime will recompute them on the next request - Verify deltas are preserved when the tab is hidden (negative case) Generated with agentic AI (Google Antigravity)
|
One issue: the test leaks its mock.
|
deltaTime and serverDeltaTime are computed once on the first AJAX response and cached for the lifetime of the page. When the browser sleeps or the tab is suspended, the cached values become stale, causing all displayed timestamps to be offset by the sleep duration.
Reset both values to 0 on visibilitychange so Ajax_UpdateTime recalculates them from the next fresh response.
Co-authored-by: AI (Gemini via Antigravity IDE)