Skip to content

fix: make session-timeout modal survive sleep (absolute deadline + focus re-check) - #67

Merged
Chris Ball (ball42) merged 1 commit into
developfrom
fix/modal-timestamp
Jul 10, 2026
Merged

fix: make session-timeout modal survive sleep (absolute deadline + focus re-check)#67
Chris Ball (ball42) merged 1 commit into
developfrom
fix/modal-timestamp

Conversation

@ball42

Copy link
Copy Markdown
Collaborator

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 setInterval variable, 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

  • Track an absolute expiry timestamp (deadline = Date.now() + duration) instead of a decrementing counter, and recompute remaining time from the real clock.
  • Re-evaluate on focus and visibilitychange — not just the 1s interval — so returning to a slept tab immediately re-checks against the real clock.
  • On return: if the session is already expired, redirect to /logout with 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.
  • "Stay Signed In" resets the deadline and pings the server (unchanged behavior).

Verification

test_timeout_modal_is_sleep_robust asserts the rendered JS is deadline/Date.now()-based, wires focus/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 develop for the batched v3.2 release.

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.
@ball42
Chris Ball (ball42) merged commit dabb394 into develop Jul 10, 2026
2 checks passed
@ball42
Chris Ball (ball42) deleted the fix/modal-timestamp branch July 10, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant