Skip to content

Commit 4b1ce10

Browse files
authored
[PE-7239] Fix issues due to stale local storage data (#13311)
### Description There have been a few cases lately of stale account local storage causing issues with update profile-photos and is_verified values. For now im turning this feature off until we can think through the various implications of it. As it stands i dont see a performance hit having to wait for account data
1 parent 7a88ddf commit 4b1ce10

File tree

3 files changed

+5
-32
lines changed

3 files changed

+5
-32
lines changed

packages/common/src/api/tan-query/saga-utils/queryAccount.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { queryUser } from './queryUser'
1515
export function* queryCurrentAccount() {
1616
const sdk = yield* getSDK()
1717
const queryClient = yield* getContext('queryClient')
18-
const localStorage = yield* getContext('localStorage')
1918
const walletAddresses = queryClient.getQueryData(
2019
getWalletAddressesQueryKey()
2120
) ?? {
@@ -27,12 +26,7 @@ export function* queryCurrentAccount() {
2726
const queryData = yield* call([queryClient, queryClient.fetchQuery], {
2827
queryKey: getCurrentAccountQueryKey(),
2928
queryFn: async () =>
30-
getCurrentAccountQueryFn(
31-
sdk,
32-
localStorage,
33-
currentUserWallet,
34-
queryClient
35-
),
29+
getCurrentAccountQueryFn(sdk, currentUserWallet, queryClient),
3630
staleTime: Infinity,
3731
gcTime: Infinity
3832
})

packages/common/src/api/tan-query/users/account/useCurrentAccount.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AudiusSdk } from '@audius/sdk'
22
import { QueryClient, useQuery, useQueryClient } from '@tanstack/react-query'
33

44
import { accountFromSDK } from '~/adapters/user'
5-
import { primeUserData, useQueryContext } from '~/api/tan-query/utils'
5+
import { useQueryContext } from '~/api/tan-query/utils'
66
import { useAppContext } from '~/context/appContext'
77
import { Status } from '~/models'
88
import { UserMetadata } from '~/models/User'
@@ -11,7 +11,6 @@ import { AccountState } from '~/store'
1111

1212
import { QUERY_KEYS } from '../../queryKeys'
1313
import { QueryKey, SelectableQueryOptions } from '../../types'
14-
import { getUserQueryKey } from '../useUser'
1514

1615
import { getAccountStatusQueryKey } from './useAccountStatus'
1716
import { useWalletAddresses } from './useWalletAddresses'
@@ -22,20 +21,11 @@ export const getCurrentAccountQueryKey = () =>
2221
QUERY_KEYS.accountUser
2322
] as unknown as QueryKey<AccountState>
2423

25-
const getLocalAccount = (
26-
localStorage: LocalStorage,
27-
queryClient: QueryClient
28-
) => {
24+
const getLocalAccount = (localStorage: LocalStorage) => {
2925
const localAccount = localStorage.getAudiusAccountSync?.()
3026
const localAccountUser =
3127
localStorage.getAudiusAccountUserSync?.() as UserMetadata
3228
if (localAccount && localAccountUser) {
33-
if (
34-
localAccountUser &&
35-
!queryClient.getQueryData(getUserQueryKey(localAccountUser.user_id))
36-
) {
37-
primeUserData({ users: [localAccountUser], queryClient })
38-
}
3929
// feature-tan-query TODO: when removing account sagas,
4030
// need to add wallets and local account user from local storage
4131
return {
@@ -57,15 +47,9 @@ const getLocalAccount = (
5747

5848
export const getCurrentAccountQueryFn = async (
5949
sdk: AudiusSdk,
60-
localStorage: LocalStorage,
6150
currentUserWallet: string | null,
6251
queryClient: QueryClient
6352
): Promise<AccountState | null | undefined> => {
64-
const localAccount = getLocalAccount(localStorage, queryClient)
65-
if (localAccount) {
66-
return localAccount
67-
}
68-
6953
if (!currentUserWallet) {
7054
return null
7155
}
@@ -83,7 +67,6 @@ export const getCurrentAccountQueryFn = async (
8367

8468
if (account) {
8569
queryClient.setQueryData(getAccountStatusQueryKey(), Status.SUCCESS)
86-
primeUserData({ users: [account.user], queryClient })
8770
} else {
8871
queryClient.setQueryData(getAccountStatusQueryKey(), Status.ERROR)
8972
}
@@ -120,11 +103,12 @@ export const useCurrentAccount = <TResult = AccountState | null | undefined>(
120103
queryFn: async () =>
121104
getCurrentAccountQueryFn(
122105
await audiusSdk(),
123-
localStorage,
124106
currentUserWallet!,
125107
queryClient
126108
),
127109
staleTime: Infinity,
110+
// Use function form so localStorage is only accessed once on initial mount
111+
initialData: () => getLocalAccount(localStorage) ?? undefined,
128112
gcTime: Infinity,
129113
enabled: options?.enabled !== false && !!currentUserWallet,
130114
...options

packages/common/src/store/account/sagas.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
queryAccountUser,
1515
getCurrentAccountQueryKey,
1616
queryCurrentUserId,
17-
primeUserData,
1817
getUserQueryKey,
1918
getWalletAccountSaga
2019
} from '~/api'
@@ -358,10 +357,6 @@ function* fetchLocalAccountAsync() {
358357
wallet &&
359358
!cachedAccountUser.is_deactivated
360359
) {
361-
primeUserData({
362-
users: [cachedAccountUser],
363-
queryClient
364-
})
365360
queryClient.setQueryData(getAccountStatusQueryKey(), Status.SUCCESS)
366361
yield* put(fetchAccountSucceeded(cachedAccount))
367362
}

0 commit comments

Comments
 (0)