Skip to content

Load the user once per Cloud Models visit - #3

Merged
mehfuzh merged 1 commit into
mainfrom
load-user-once-per-section
Nov 5, 2026
Merged

mehfuzh merged 1 commit into
mainfrom
load-user-once-per-section

Conversation

@mehfuzh

@mehfuzh mehfuzh commented Nov 5, 2026

Copy link
Copy Markdown
Member

Problem

Switching between Cloud Models pages (/cloud-models/usage ↔ /cloud-models/history) hung or failed.

  • useAuth had pathname in its effect's dependencies, so it refetched /users/me on every route change. The Cloud Models layout stays mounted between its pages, so each switch fetched the user again, even though the layout's comment says it shouldn't.
  • Each fetch returned a new user object, so every section's loads (keyed on user) ran again. Opening Usage made about 7 API calls instead of 4: /users/me, then chat/status, chat/ledger and models twice.
  • If /users/me failed with a server error (as when the API's pooler connections hang), useAuth sent you to /login.

Change (src/app/hooks/useAuth.ts)

  • Load the user once when the hook mounts. Pages without a layout remount on navigation, so they behave as before.
  • On a server or network error, keep the user saved by the last successful /users/me instead of redirecting to /login. No token or a 401 still signs you out (handled in user.service).

The API side of the hang is smartloop-ai/slp-api#162.

Testing

  • npm run typecheck and npm run build pass.
  • Not tested in a browser with a signed-in account. Worth checking the Network tab while switching between Usage and Session History: each switch should load only that page's data, with no /users/me.

useAuth refetched /users/me on every route change because pathname was
in its effect's dependencies. The Cloud Models layout stays mounted
between Usage and Session History, so each switch fetched the user
again, and the new user object made every section load its data a
second time: about 7 requests for opening Usage instead of 4.

useAuth now loads the user once when it mounts. A server or network
error from /users/me no longer sends you to /login; the page keeps the
user saved by the last successful load. No token or a 401 still signs
you out.
@mehfuzh
mehfuzh merged commit b7d55a0 into main Nov 5, 2026
1 check passed
@mehfuzh
mehfuzh deleted the load-user-once-per-section branch November 5, 2026 19:28
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