Repository navigation
fix(console): stop the guest /join spinner loop - #14646
Conversation
A guest's account query ends in a 401 with no data. With retryOnMount on, every newly mounted useAuth() refetched it, so the invite screen's account switcher flipped the page back to loading, unmounted, and remounted once the cached 401 replayed.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
The change touches a single TanStack Query options object in the console auth hooks. The
Reviewed commit: e0b6ca6 |
New ConsoleProject ID: Tip Sites support three domain rule types: Active deployment, Git branch, and Redirect |
🟢 Tier S · Ready to mergeDisables retry-on-mount for the shared Console account query, preventing a cached guest 401 from restarting the query when another auth observer mounts. The existing retry and automatic refetch settings are otherwise unchanged.
📂 Walkthrough · 1
Merged |
There was a problem hiding this comment.
This PR adds retryOnMount: false to the console account query options to stop a remount refetch loop for guest 401 responses.
Key findings
- 🟡
retryOnMount: falseblocks recovery from cached account errors — auth.ts:310
| retryOnMount: false, | ||
| refetchOnMount: false, | ||
| refetchOnWindowFocus: false, | ||
| refetchOnReconnect: false, |
There was a problem hiding this comment.
🟡 bug · medium
retryOnMount: false blocks recovery from cached account errors
The new retryOnMount: false in consoleAccountQueryOptions (apps/console/src/lib/react-query/hooks/auth.ts:310) permanently disables the mount-time refetch of an errored account.get query. Combined with gcTime/staleTime of Infinity and all refetchOn* options disabled (auth.ts:305-313), a transient non-401 failure on the first account fetch is cached for the whole session with no retry path for direct useQuery(consoleAccountQueryOptions()) consumers (the /init presence components and init/View.tsx:268); loader-driven routes still recover via ensureConsoleAccountQueryData, which purges or force-fetches errored queries. Affected users stay pinned to guest/unauthenticated account state for the rest of the session even after the network recovers.
📋 Prompt for AI Agents
In apps/console/src/lib/react-query/hooks/auth.ts around lines 300-317, the newly added retryOnMount: false on consoleAccountQueryOptions leaves direct useQuery consumers (init presence components, init/View.tsx) with no recovery after a transient non-401 account.get failure, because gcTime/staleTime are Infinity and every refetch trigger is off. Fix: in the queryFn wrapper (or in fetchConsoleAccount's error handling in src/lib/console-account-get.ts), when the failure is NOT a 401 unauthorized or user_more_factors_required error, remove/reset the query entry for ['account', 'console', revision] in the queryClient so the next mount starts fresh; keep retryOnMount: false so guest 401s still avoid the remount loop the option was added for.
There was a problem hiding this comment.
The mount retry only fired when some consumer happened to mount after the error, and that refetch is the /join loop itself: the switcher mounts once loading ends, its refetch flips the page back to loading, and it unmounts. With a non-401 error the same loop sends real requests to an API that is already failing.
Recovery doesn't depend on it. Non-optional route loaders go through ensureConsoleAccountQueryData, and ensureQueryData refetches an errored query with no data. On query-core 5.90.2, a new observer no longer refetches, but ensureQueryData still does and succeeds. A reload starts clean, since the cache isn't persisted and non-401 errors aren't kept in the account singleton.
On /init, View.tsx counts an account error as ready, which enables the presence hook's account query, and a false → true enabled flip refetches regardless of retryOnMount.
There was a problem hiding this comment.
Thanks for the detailed explanation. Let me work through the three recovery paths you've described:
- Route loaders via
ensureConsoleAccountQueryData— agreed, this path is unaffected and recovers correctly. /initView.tsxcounting an error as ready — if the account query errors,View.tsxtreats it as ready, the presence hook'senabledflipsfalse → true, and that new observer triggers a refetch regardless ofretryOnMount. That's a valid recovery path for that specific consumer.- The remount loop concern with non-401 errors — your point that a non-401 error with
retryOnMount: truewould also loop (sending real requests to an already-failing API) is worth considering, though the loop only continues while the component stays mounted and the error persists, which differs from the 401 case where the error is permanent.
The core concern remains: a direct useQuery(consoleAccountQueryOptions()) consumer outside /init that doesn't go through a loader and doesn't have the enabled flip mechanism has no recovery path after a transient non-401 failure. Whether that consumer exists in practice is the key question — the current PR diff and file list only show the one changed file (auth.ts), so I can't verify whether all direct consumers have the recovery paths you describe. The finding stays open until the consumer coverage can be confirmed.

What does this PR do?
Sets
retryOnMount: falseonconsoleAccountQueryOptions().For a guest, the account query ends in a 401 with no data. The
/joinaccept screen rendersAuthFlowAccountSwitcher, whose ownuseAuth()refetched the failed query on mount. That flippedisLoadingback totrue, the page returned to the spinner, the switcher unmounted, the cached 401 replayed, and the cycle repeated. The query already disables every other automatic refetch.Test Plan
Console dev server against a local stack, guest browser:
/join?teamId=…&membershipId=…&userId=…&secret=…spins forever, oneGET /v1/account401, ~200k DOM mutations in 2 s./sign-in; password sign-in lands on the org.Related PRs and Issues
/joinshows an endless spinner for invited users who are not signed in #14611Checklist