Skip to content

Commit

Permalink
fix: switch account during comment loading indicator not shown (#1861)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Feb 23, 2025
1 parent 674df3d commit 694ad71
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/features/auth/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ListEditorProvider,
} from "#/features/shared/ListEditor";
import { moveItem } from "#/helpers/array";
import { isPromiseResolvedByPaint } from "#/helpers/promise";
import { useAppDispatch, useAppSelector } from "#/store";

import Account from "./Account";
Expand All @@ -29,7 +30,7 @@ import { setAccounts } from "./authSlice";

type AccountSwitcherProps = {
onDismiss: (data?: string, role?: string) => void;
onSelectAccount: (account: string) => Promise<void> | void;
onSelectAccount: (account: string) => Promise<void>;
showGuest?: boolean;
activeHandle?: string;
} & (
Expand Down Expand Up @@ -131,7 +132,8 @@ function AccountSwitcherContents({

const selectionChangePromise = onSelectAccount(e.target.value);

if (!selectionChangePromise) {
// Bail on rendering the loading indicator
if (await isPromiseResolvedByPaint(selectionChangePromise)) {
onDismiss();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function TemporarySelectedAccountProvider({
onDismiss: (data?: string, role?: string) =>
onDismissAccountSwitcher(data, role),
onSelectAccount: async (account: string) => {
onSelectAccount(account);
await onSelectAccount(account);

setSelectedAccountHandle(account);
},
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/promise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function isPromiseResolvedByPaint(
promise: Promise<unknown>,
): Promise<boolean> {
return Promise.race([
promise.then(() => true),
new Promise<false>((resolve) => {
requestAnimationFrame(() => {
resolve(false);
});
}),
]);
}

0 comments on commit 694ad71

Please sign in to comment.