Skip to content

Fix logged-out UI flashing on account pages - #15233

Open
SilkePilon wants to merge 1 commit into
gitbutlerapp:masterfrom
SilkePilon:t3code/fix-account-page-auth-flash
Open

Fix logged-out UI flashing on account pages#15233
SilkePilon wants to merge 1 commit into
gitbutlerapp:masterfrom
SilkePilon:t3code/fix-account-page-auth-flash

Conversation

@SilkePilon

Copy link
Copy Markdown
Contributor

The problem

Load or refresh the profile page while signed in and you get "It looks like you're not logged in" for a moment before the real page appears. Same idea in the header, where the Log in / Sign up buttons flash before your avatar shows up.

Why it happens

Web auth is cookie based, so the client has no way of knowing synchronously whether you're signed in. UserService.user starts out as undefined and only fills in once GET /api/user comes back. That means undefined covers two very different states: "still fetching" and "logged out". Everything reading the store treats it as the second one on the first frame.

What I found along the way

The rules page and the reviews page have a nastier version of this. Their redirect effect fires while the fetch is still in flight, so refreshing either page while signed in kicks you back to home. The organization invite page shows "Please log in to continue" for the same reason.

The fix

UserService now exposes a loaded store that flips to true once the initial fetch settles, either way. Pages wait for it before rendering logged-out UI or redirecting.

One thing worth calling out: the conditions read $user before $userLoaded on purpose. Svelte only subscribes to a store when the expression reading it actually runs, so putting $userLoaded first would short circuit, leave $user unsubscribed, and the fetch would never start.

Testing

svelte-check passes clean on 1791 files, eslint is clean on the touched files, and the existing web unit tests still pass. I haven't been able to confirm it in a live browser since that needs a real signed-in session cookie.

Files touched:

  • apps/web/src/lib/user/userService.ts
  • apps/web/src/routes/(app)/profile/+page.svelte
  • apps/web/src/lib/components/HeaderAuthSection.svelte
  • apps/web/src/routes/(app)/organizations/invite/[slug]/[code]/+page.svelte
  • apps/web/src/routes/(app)/[ownerSlug]/rules/+page.svelte
  • apps/web/src/routes/(app)/[ownerSlug]/[projectSlug]/reviews/+page.svelte

🤖 Generated with Claude Code

Web auth is cookie based, so the client can't tell synchronously whether
you're signed in. `UserService.user` starts as `undefined` and only gets
populated once `GET /api/user` comes back, which meant `undefined` stood
for both "still fetching" and "logged out".

Consumers read it as "logged out" on the first frame. The profile page
showed "It looks like you're not logged in" until the fetch resolved, and
the header flashed the Log in / Sign up buttons. The rules and reviews
pages had it worse: they redirected you to home before the fetch had a
chance to finish, so refreshing either page while signed in bounced you
out.

`UserService` now exposes a `loaded` store that flips once the initial
fetch settles, and the pages wait for it before rendering logged-out UI
or redirecting.

Conditions are ordered so `$user` is read before `$userLoaded`. Svelte
only subscribes to a store when the expression reading it actually runs,
so short circuiting on `$userLoaded` first would leave `$user`
unsubscribed, the fetch never started, and the page stuck loading.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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