Repository navigation
Load the user once per Cloud Models visit - #3
Merged
Merged
Conversation
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.
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.
Problem
Switching between Cloud Models pages (
/cloud-models/usage↔/cloud-models/history) hung or failed.useAuthhadpathnamein its effect's dependencies, so it refetched/users/meon 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.user) ran again. Opening Usage made about 7 API calls instead of 4:/users/me, thenchat/status,chat/ledgerandmodelstwice./users/mefailed with a server error (as when the API's pooler connections hang),useAuthsent you to/login.Change (
src/app/hooks/useAuth.ts)/users/meinstead of redirecting to/login. No token or a 401 still signs you out (handled inuser.service).The API side of the hang is smartloop-ai/slp-api#162.
Testing
npm run typecheckandnpm run buildpass./users/me.