From e0543e712cb10cc9fde66c11a613f6b599f9e7a7 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 2 Apr 2026 16:49:37 +0300 Subject: [PATCH] fix major violations --- src/state/queries/feed.ts | 11 ++++---- src/state/queries/notifications/feed.ts | 23 +++++++++++---- src/state/queries/post-feed.ts | 21 +++++++++++--- src/state/queries/usePostThread/index.ts | 36 ++++++++++++++++-------- 4 files changed, 65 insertions(+), 26 deletions(-) diff --git a/src/state/queries/feed.ts b/src/state/queries/feed.ts index c2b173b5ce..b3ec50c17e 100644 --- a/src/state/queries/feed.ts +++ b/src/state/queries/feed.ts @@ -226,6 +226,7 @@ export function createGetPopularFeedsQueryKey( export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) { const {hasSession} = useSession() const agent = useAgent() + const enabled = options?.enabled const limit = options?.limit || 10 const {data: preferences} = usePreferencesQuery() const queryClient = useQueryClient() @@ -243,8 +244,8 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) { const lastPageCountRef = useRef(0) const query = useInfiniteQuery({ - enabled: Boolean(moderationOpts) && options?.enabled !== false, - queryKey: createGetPopularFeedsQueryKey(options), + enabled: Boolean(moderationOpts) && enabled !== false, + queryKey: createGetPopularFeedsQueryKey({enabled, limit}), queryFn: async ({pageParam}) => { const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({ limit, @@ -298,8 +299,8 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) { ), }) + const {isFetching, hasNextPage, data, fetchNextPage} = query useEffect(() => { - const {isFetching, hasNextPage, data} = query if (isFetching || !hasNextPage) { return } @@ -318,10 +319,10 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) { count += page.feeds.length } if (count < limit && (data?.pages.length || 0) < 6) { - query.fetchNextPage() + void fetchNextPage() lastPageCountRef.current = data?.pages?.length || 0 } - }, [query, limit]) + }, [isFetching, hasNextPage, data, fetchNextPage, limit]) return query } diff --git a/src/state/queries/notifications/feed.ts b/src/state/queries/notifications/feed.ts index 57d83cb5bb..80cddb3ec6 100644 --- a/src/state/queries/notifications/feed.ts +++ b/src/state/queries/notifications/feed.ts @@ -228,9 +228,15 @@ export function useNotificationFeedQuery(opts: { const lastItemCount = useRef(0) const wantedItemCount = useRef(0) const autoPaginationAttemptCount = useRef(0) + const { + data, + isLoading, + isRefetching, + isFetchingNextPage, + hasNextPage, + fetchNextPage, + } = query useEffect(() => { - const {data, isLoading, isRefetching, isFetchingNextPage, hasNextPage} = - query // Count the items that we already have. let itemCount = 0 for (const page of data?.pages || []) { @@ -262,13 +268,20 @@ export function useNotificationFeedQuery(opts: { if (itemCount < wantedItemCount.current) { autoPaginationAttemptCount.current++ if (autoPaginationAttemptCount.current < 50 /* failsafe */) { - query.fetchNextPage() + void fetchNextPage() } } else { autoPaginationAttemptCount.current = 0 } } - }, [query]) + }, [ + data, + isLoading, + isRefetching, + isFetchingNextPage, + hasNextPage, + fetchNextPage, + ]) return query } @@ -298,7 +311,7 @@ export function* findAllPostsInQueryData( if (AppBskyFeedDefs.isPostView(item.subject)) { const quotedPost = getEmbeddedPost(item.subject?.embed) if (quotedPost && didOrHandleUriMatches(atUri, quotedPost)) { - yield embedViewRecordToPostView(quotedPost!) + yield embedViewRecordToPostView(quotedPost) } } } diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 2fbb9e7cbe..0779506892 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -369,9 +369,15 @@ export function usePostFeedQuery( const lastItemCount = useRef(0) const wantedItemCount = useRef(0) const autoPaginationAttemptCount = useRef(0) + const { + data, + isLoading, + isRefetching, + isFetchingNextPage, + hasNextPage, + fetchNextPage, + } = query useEffect(() => { - const {data, isLoading, isRefetching, isFetchingNextPage, hasNextPage} = - query // Count the items that we already have. let itemCount = 0 for (const page of data?.pages || []) { @@ -405,13 +411,20 @@ export function usePostFeedQuery( if (itemCount < wantedItemCount.current) { autoPaginationAttemptCount.current++ if (autoPaginationAttemptCount.current < 50 /* failsafe */) { - query.fetchNextPage() + void fetchNextPage() } } else { autoPaginationAttemptCount.current = 0 } } - }, [query]) + }, [ + data, + isLoading, + isRefetching, + isFetchingNextPage, + hasNextPage, + fetchNextPage, + ]) return query } diff --git a/src/state/queries/usePostThread/index.ts b/src/state/queries/usePostThread/index.ts index ceb87fe47b..6282b78057 100644 --- a/src/state/queries/usePostThread/index.ts +++ b/src/state/queries/usePostThread/index.ts @@ -167,25 +167,30 @@ export function usePostThread({anchor}: {anchor?: string}) { return data }, }) + const { + data: additionalItemsData, + isLoading: additionalItemsIsLoading, + isError: additionalItemsIsError, + } = additionalItemsQuery const serverOtherThreadItems: ThreadItem[] = useMemo(() => { if (!additionalQueryEnabled) return [] - if (additionalItemsQuery.isLoading) { + if (additionalItemsIsLoading) { return Array.from({length: 2}).map((_, i) => views.skeleton({ key: `other-reply-${i}`, item: 'reply', }), ) - } else if (additionalItemsQuery.isError) { + } else if (additionalItemsIsError) { /* * We could insert an special error component in here, but since these * are optional additional replies, it's not critical that they're shown * atm. */ return [] - } else if (additionalItemsQuery.data?.thread) { + } else if (additionalItemsData?.thread) { const {threadItems} = sortAndAnnotateThreadItems( - additionalItemsQuery.data.thread, + additionalItemsData?.thread, { view, skipModerationHandling: true, @@ -202,10 +207,12 @@ export function usePostThread({anchor}: {anchor?: string}) { }, [ view, additionalQueryEnabled, - additionalItemsQuery, mergeThreadgateHiddenReplies, moderationOpts, threadgate?.record, + additionalItemsData, + additionalItemsIsLoading, + additionalItemsIsError, ]) /** @@ -248,6 +255,8 @@ export function usePostThread({anchor}: {anchor?: string}) { view, ]) + const {isFetching, isPlaceholderData, error, refetch} = query + /* * Take all three sets of thread items and combine them into a single thread, * along with any other thread items required for rendering e.g. "Show more @@ -258,7 +267,7 @@ export function usePostThread({anchor}: {anchor?: string}) { threadItems, otherThreadItems, serverOtherThreadItems, - isLoading: query.isPlaceholderData, + isLoading: isPlaceholderData, hasSession, hasOtherThreadItems, otherItemsVisible, @@ -268,7 +277,7 @@ export function usePostThread({anchor}: {anchor?: string}) { threadItems, otherThreadItems, serverOtherThreadItems, - query.isPlaceholderData, + isPlaceholderData, hasSession, hasOtherThreadItems, otherItemsVisible, @@ -286,9 +295,9 @@ export function usePostThread({anchor}: {anchor?: string}) { /* * Copy in any query state that is useful */ - isFetching: query.isFetching, - isPlaceholderData: query.isPlaceholderData, - error: query.error, + isFetching: isFetching, + isPlaceholderData: isPlaceholderData, + error: error, /* * Other state */ @@ -305,7 +314,7 @@ export function usePostThread({anchor}: {anchor?: string}) { * Copy in any query actions that are useful */ insertReplies: mutator.insertReplies, - refetch: query.refetch, + refetch: refetch, /* * Other actions */ @@ -314,7 +323,10 @@ export function usePostThread({anchor}: {anchor?: string}) { }, } }, [ - query, + isFetching, + isPlaceholderData, + error, + refetch, mutator.insertReplies, otherItemsVisible, sort,