Skip to content

Commit e4acd37

Browse files
committed
Phase 1 (partial): Enable fallback in critical query hooks
Updated the following files to use the fallback infrastructure: - profile.ts: Changed imports, added fallback config to useProfileQuery, updated usePrefetchProfileQuery - post.ts: Changed imports, added fallback config to usePostQuery, updated useGetPost() and useGetPosts() - usePostThread/index.ts: Changed imports, added fallback config to thread query Enables viewing profiles, posts, and threads from AppView-suspended users.
1 parent 2dba354 commit e4acd37

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/state/queries/post.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {useCallback} from 'react'
22
import {type AppBskyActorDefs, type AppBskyFeedDefs, AtUri} from '@atproto/api'
3-
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
3+
import {fetchQueryWithFallback, useMutation, useQuery, useQueryClient} from './useQueryWithFallback'
44

55
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
66
import {type LogEvents, toClout} from '#/lib/statsig/statsig'
@@ -37,6 +37,9 @@ export function usePostQuery(uri: string | undefined) {
3737
throw new Error('No data')
3838
},
3939
enabled: !!uri,
40+
enableFallback: true,
41+
fallbackType: 'post',
42+
fallbackIdentifier: uri,
4043
})
4144
}
4245

@@ -45,9 +48,9 @@ export function useGetPost() {
4548
const agent = useAgent()
4649
return useCallback(
4750
async ({uri}: {uri: string}) => {
48-
return queryClient.fetchQuery({
51+
return fetchQueryWithFallback(queryClient, {
4952
queryKey: RQKEY(uri || ''),
50-
async queryFn() {
53+
queryFn: async () => {
5154
const urip = new AtUri(uri)
5255

5356
if (!urip.host.startsWith('did:')) {
@@ -67,6 +70,9 @@ export function useGetPost() {
6770

6871
throw new Error('useGetPost: post not found')
6972
},
73+
enableFallback: true,
74+
fallbackType: 'post',
75+
fallbackIdentifier: uri,
7076
})
7177
},
7278
[queryClient, agent],
@@ -78,9 +84,9 @@ export function useGetPosts() {
7884
const agent = useAgent()
7985
return useCallback(
8086
async ({uris}: {uris: string[]}) => {
81-
return queryClient.fetchQuery({
87+
return fetchQueryWithFallback(queryClient, {
8288
queryKey: RQKEY(uris.join(',') || ''),
83-
async queryFn() {
89+
queryFn: async () => {
8490
const res = await agent.getPosts({
8591
uris,
8692
})
@@ -91,6 +97,9 @@ export function useGetPosts() {
9197
throw new Error('useGetPosts failed')
9298
}
9399
},
100+
enableFallback: true,
101+
fallbackType: 'post',
102+
fallbackIdentifier: uris[0], // Use first URI as identifier
94103
})
95104
},
96105
[queryClient, agent],

src/state/queries/profile.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import {
1111
} from '@atproto/api'
1212
import {
1313
keepPreviousData,
14+
prefetchQueryWithFallback,
1415
type QueryClient,
1516
useMutation,
1617
useQuery,
1718
useQueryClient,
18-
} from '@tanstack/react-query'
19+
} from './useQueryWithFallback'
1920

2021
import {uploadBlob} from '#/lib/api'
2122
import {until} from '#/lib/async/until'
@@ -83,6 +84,9 @@ export function useProfileQuery({
8384
return getUnstableProfile(did) as AppBskyActorDefs.ProfileViewDetailed
8485
},
8586
enabled: !!did,
87+
enableFallback: true,
88+
fallbackType: 'profile',
89+
fallbackIdentifier: did,
8690
})
8791
}
8892

@@ -110,13 +114,16 @@ export function usePrefetchProfileQuery() {
110114
const queryClient = useQueryClient()
111115
const prefetchProfileQuery = useCallback(
112116
async (did: string) => {
113-
await queryClient.prefetchQuery({
117+
await prefetchQueryWithFallback(queryClient, {
114118
staleTime: STALE.SECONDS.THIRTY,
115119
queryKey: RQKEY(did),
116120
queryFn: async () => {
117121
const res = await agent.getProfile({actor: did || ''})
118122
return res.data
119123
},
124+
enableFallback: true,
125+
fallbackType: 'profile',
126+
fallbackIdentifier: did,
120127
})
121128
},
122129
[queryClient, agent],

src/state/queries/usePostThread/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {useCallback, useMemo, useState} from 'react'
2-
import {useQuery, useQueryClient} from '@tanstack/react-query'
2+
import {useQuery, useQueryClient} from '../useQueryWithFallback'
33

44
import {isWeb} from '#/platform/detection'
55
import {useModerationOpts} from '#/state/preferences/moderation-opts'
@@ -125,6 +125,9 @@ export function usePostThread({anchor}: {anchor?: string}) {
125125
}
126126
return data
127127
},
128+
enableFallback: true,
129+
fallbackType: 'thread',
130+
fallbackIdentifier: anchor,
128131
})
129132

130133
const thread = useMemo(() => query.data?.thread || [], [query.data?.thread])

0 commit comments

Comments
 (0)