Skip to content

Commit 6b8fb8f

Browse files
fix(agentex-ui): reset account-scoped queries on switch to avoid stale flash
Switching accounts closes the open task (task_id cleared), which flips PrimaryContent from ChatView to HomeView immediately. HomeView rendered the agents list from the still-cached previous account (invalidateQueries keeps data during the refetch), so the new account briefly flashed the old account's agents before recalibrating. Use resetQueries instead: the previous account's agents/tasks are dropped on switch, so HomeView shows a loading state until the new account's data lands — never stale data. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 5f243a0 commit 6b8fb8f

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

agentex-ui/components/account-picker/account-picker.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ export function AccountPicker({
3737
const profiles = useMemo(() => data?.access_profiles ?? [], [data]);
3838
const selectedId = selectedAccountId ?? undefined;
3939

40-
// Refetch account-scoped data (agents, tasks, …) on an account change — but NOT
41-
// user-info: the account list itself doesn't change when you switch accounts.
42-
const refetchAccountScoped = useCallback(
40+
// Reset (not just invalidate) account-scoped data on a switch. invalidate keeps the
41+
// previous data cached during the refetch, so the new account would briefly render the
42+
// old account's agents (HomeView) before recalibrating; reset clears it so we show a
43+
// loading state instead. user-info is preserved — the account list doesn't change.
44+
const resetAccountScoped = useCallback(
4345
() =>
44-
queryClient.invalidateQueries({
46+
queryClient.resetQueries({
4547
predicate: q => q.queryKey[0] !== userInfoKey[0],
4648
}),
4749
[queryClient]
@@ -50,9 +52,9 @@ export function AccountPicker({
5052
(id: string) => {
5153
if (id === selectedId) return;
5254
setSelectedAccountId(id);
53-
void refetchAccountScoped();
55+
void resetAccountScoped();
5456
},
55-
[selectedId, setSelectedAccountId, refetchAccountScoped]
57+
[selectedId, setSelectedAccountId, resetAccountScoped]
5658
);
5759

5860
// Default to the first account when the URL has no valid account_id (fixes the
@@ -66,8 +68,8 @@ export function AccountPicker({
6668
const first = profiles[0];
6769
if (!first) return;
6870
setSelectedAccountId(first.account.id, true);
69-
void refetchAccountScoped();
70-
}, [profiles, selectedId, setSelectedAccountId, refetchAccountScoped]);
71+
void resetAccountScoped();
72+
}, [profiles, selectedId, setSelectedAccountId, resetAccountScoped]);
7173

7274
if (!accountsEnabled) return null;
7375

0 commit comments

Comments
 (0)