Skip to content

perf(studio): keep the session between navigations; show pending after 150 ms - #67

Merged
Madraka merged 1 commit into
mainfrom
perf/studio-navigation
Oct 21, 2026
Merged

Madraka merged 1 commit into
mainfrom
perf/studio-navigation

Conversation

@Madraka

@Madraka Madraka commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Fixes 1 and 2 of the internal performance review (Studio navigation).

Before: every protected route's beforeLoad awaited authClient.getSession() (240–640 ms measured on studio.cloudhal.com, before the next screen's chunk even started; twice in a row on a cold load), and TanStack Router's default pendingMs (1 s) kept the old screen up meanwhile. The URL changed at once and the screen did not.

Now:

  • lib/session-cache.ts: a successful session is kept for 5 minutes and a request in flight is shared. Empty or failed answers are never kept. It is forgotten on any Better Auth call other than get-session (sign-in, sign-out, revoking sessions, password change, through the client's onResponse hook) and on any 401 from lib/api/http.ts, so an expired session still lands on the login at the next navigation.
  • defaultPendingMs: 150, defaultPendingMinMs: 300: a wait shows the pending screen instead of a frozen one.
  • The playground path (no sign-in, 403) keeps working: a caller without its own status asks isPlayground().

Tests: session-cache.test.ts; Studio suite 1136/1136.

🤖 Generated with Claude Code

…r 150 ms

Every protected route awaited `authClient.getSession()` in `beforeLoad`, a
240-640 ms server round trip before the next screen could start, and the
router's default `pendingMs` of 1 s kept the old screen up meanwhile: the URL
changed, the screen did not.

- lib/session-cache.ts keeps a successful session for 5 minutes and shares
  a request in flight; it is forgotten on any auth call but get-session
  (sign-in, sign-out, revoking sessions, a new password) and on any 401
  from the API client.
- `defaultPendingMs: 150`, `defaultPendingMinMs: 300`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Madraka <[email protected]>
@Madraka
Madraka merged commit 02a9c89 into main Oct 21, 2026
4 checks passed
@Madraka
Madraka deleted the perf/studio-navigation branch October 21, 2026 22:27
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