fix: make session-timeout modal survive sleep (absolute deadline + focus re-check) - #67
Merged
Merged
Conversation
The warning modal counted down a setInterval variable, which the browser pauses/throttles during sleep or when the tab is backgrounded. After a long idle the countdown never advanced, so no warning fired and the server session had already expired -- the user just got a silent bounce to login on their next click. Track an absolute expiry timestamp instead and re-evaluate against the real clock on tab focus/visibilitychange, not only on the interval. On return: if already expired, redirect to /logout with a 'Session expired' reason so the login page explains why (reusing the login-error banner); if within the warning window, show the modal immediately with the correct remaining seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The session-timeout warning modal never appeared after a long idle: returning to the tab, the next click just bounced to the login page. Root cause — the modal counted down a
setIntervalvariable, which browsers pause/throttle during sleep or when a tab is backgrounded. The counter froze while the machine slept, so the warning never fired, while the server-side session expired on schedule.Fix
deadline = Date.now() + duration) instead of a decrementing counter, and recompute remaining time from the real clock.focusandvisibilitychange— not just the 1s interval — so returning to a slept tab immediately re-checks against the real clock./logoutwith a "Session expired" reason so the login page explains why (reuses the login-error banner) instead of a silent bounce; if within the warning window, show the modal immediately with the correct remaining seconds.Verification
test_timeout_modal_is_sleep_robustasserts the rendered JS is deadline/Date.now()-based, wiresfocus/visibilitychange, and carries the expired-redirect URL. True sleep-survival is a manual browser check (documented): sleep the machine past the timeout, wake, expect an immediate "Session expired" login redirect. Full suite green (93 passed), ruff clean.Targets
developfor the batched v3.2 release.