[PR #6110] [MERGED] chore: session refetch cooldown for window focus #6452

Closed
opened 2026-03-13 12:59:50 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6110
Author: @ping-maxwell
Created: 11/19/2025
Status: Merged
Merged: 11/21/2025
Merged by: @himself65

Base: canaryHead: chore/session-refetch-cooldown-for-window-refocus


📝 Commits (1)

  • bb51390 chore: session refetch cooldown for window focus

📊 Changes

2 files changed (+364 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/client/session-refresh.test.ts (+340 -1)
📝 packages/better-auth/src/client/session-refresh.ts (+24 -0)

📄 Description

Every time you focus the browser, we make a get-session request. If you alt+tab between the browser frequently, you would hit your server several times (and thus the DB too) within the span of a couple seconds.

It's unnecessary to get the session each browser refocus within the span of a couple seconds.


Summary by cubic

Add a 5-second cooldown for session refetch on window focus to prevent rapid, repeated get-session calls. This reduces server and DB load when users frequently alt‑tab, while still refetching if the session is missing or the cooldown has expired.

  • New Features
    • Rate-limit focus-triggered refetch to 5s; bypass if session is null or undefined.
    • Track lastSessionRequest; update on poll and visibilitychange events.
    • Respect offline state: skip refetch when offline unless refetchWhenOffline is true.
    • Add tests covering cooldown, expiration, null/undefined session, and offline behavior.

Written for commit bb51390a36. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6110 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 11/19/2025 **Status:** ✅ Merged **Merged:** 11/21/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `chore/session-refetch-cooldown-for-window-refocus` --- ### 📝 Commits (1) - [`bb51390`](https://github.com/better-auth/better-auth/commit/bb51390a364c322d6400a52ffb44e8977cc70803) chore: session refetch cooldown for window focus ### 📊 Changes **2 files changed** (+364 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/client/session-refresh.test.ts` (+340 -1) 📝 `packages/better-auth/src/client/session-refresh.ts` (+24 -0) </details> ### 📄 Description Every time you focus the browser, we make a get-session request. If you alt+tab between the browser frequently, you would hit your server several times (and thus the DB too) within the span of a couple seconds. It's unnecessary to get the session each browser refocus within the span of a couple seconds. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add a 5-second cooldown for session refetch on window focus to prevent rapid, repeated get-session calls. This reduces server and DB load when users frequently alt‑tab, while still refetching if the session is missing or the cooldown has expired. - **New Features** - Rate-limit focus-triggered refetch to 5s; bypass if session is null or undefined. - Track lastSessionRequest; update on poll and visibilitychange events. - Respect offline state: skip refetch when offline unless refetchWhenOffline is true. - Add tests covering cooldown, expiration, null/undefined session, and offline behavior. <sup>Written for commit bb51390a364c322d6400a52ffb44e8977cc70803. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:59:50 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6452