Skip to content

fix(console): stop the guest /join spinner loop - #14646

Merged
HarshMN2345 merged 2 commits into
mainfrom
fix-console-join-guest-spinner
Oct 19, 2026
Merged

HarshMN2345 merged 2 commits into
mainfrom
fix-console-join-guest-spinner

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

What does this PR do?

Sets retryOnMount: false on consoleAccountQueryOptions().

For a guest, the account query ends in a 401 with no data. The /join accept screen renders AuthFlowAccountSwitcher, whose own useAuth() refetched the failed query on mount. That flipped isLoading back to true, 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:

  • Before: /join?teamId=…&membershipId=…&userId=…&secret=… spins forever, one GET /v1/account 401, ~200k DOM mutations in 2 s.
  • After: the accept screen renders and stays still.
  • Real invite from an org owner, link taken from the mail catcher, opened as a guest: Accept → success screen → org page, signed in as the invitee.
  • Sign-out lands on /sign-in; password sign-in lands on the org.
  • Signed-in user on someone else's invite gets the "different account" screen.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

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.
@luxor-code-review

luxor-code-review Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 retryOnMount: false blocks recovery from cached account errors — auth.ts:310

The change touches a single TanStack Query options object in the console auth hooks. The retryOnMount: false flag stops direct useQuery consumers from re-fetching on remount, which prevents the remount loop observed for guest 401 responses; loader-driven routes are unaffected since ensureQueryData still fetches errored data-less queries.

Files Change
apps/console/src/lib/react-query/hooks/auth.ts Adds retryOnMount: false to consoleAccountQueryOptions so an errored guest 401 account fetch is no longer retried on every remount.

Reviewed commit: e0b6ca6

@appwrite

appwrite Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

New Console

Project ID: new-console

Sites (1)
Site Status Logs Preview QR
 New Console
new-console
Ready Ready View Logs Preview URL QR Code

Tip

Sites support three domain rule types: Active deployment, Git branch, and Redirect

@ghost

ghost commented Oct 19, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Disables 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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 1
File Change
apps/console/src/lib/react-query/hooks/auth.ts Sets retryOnMount to false in the shared console account query options.

Merged main (fd27fcc); no changes to this PR's code since e0b6ca6 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds retryOnMount: false to the console account query options to stop a remount refetch loop for guest 401 responses.

Key findings

  • 🟡 retryOnMount: false blocks recovery from cached account errors — auth.ts:310

Comment on lines +310 to 313
retryOnMount: false,
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation. Let me work through the three recovery paths you've described:

  1. Route loaders via ensureConsoleAccountQueryData — agreed, this path is unaffected and recovers correctly.
  2. /init View.tsx counting an error as ready — if the account query errors, View.tsx treats it as ready, the presence hook's enabled flips false → true, and that new observer triggers a refetch regardless of retryOnMount. That's a valid recovery path for that specific consumer.
  3. The remount loop concern with non-401 errors — your point that a non-401 error with retryOnMount: true would 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.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@HarshMN2345
HarshMN2345 merged commit e12c25a into main Oct 19, 2026
12 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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.

🐛 Bug Report: Console /join shows an endless spinner for invited users who are not signed in

1 participant