From 3a02902df2fbd074e2aebd6010c7f9d997d35e89 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Thu, 19 Feb 2026 04:55:57 -0600 Subject: [PATCH] Fix post stats clearing during pagination The issue was that when new pages were loaded during infinite scroll, the batch stats query key would change (since it includes all event IDs), causing React Query to treat it as a completely new query. This would briefly show no stats until the new query completed. Fixed by improving the placeholderData function in useBatchEventStats to pull cached stats from individual event-stats queries. This ensures that previously loaded stats remain visible while new stats are being fetched during pagination. Co-authored-by: shakespeare.diy --- src/hooks/useTrending.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/hooks/useTrending.ts b/src/hooks/useTrending.ts index 26b65b8b..8d30b6f0 100644 --- a/src/hooks/useTrending.ts +++ b/src/hooks/useTrending.ts @@ -527,6 +527,17 @@ export function useBatchEventStats(eventIds: string[], enabled = true) { staleTime: 60 * 1000, gcTime: 5 * 60 * 1000, enabled: enabled && uniqueIds.length > 0, - placeholderData: (prev) => prev, + placeholderData: () => { + // When pagination adds new events, pull cached stats from individual queries + // to prevent stats from disappearing while the new batch query is loading + const placeholderMap = new Map(); + for (const id of uniqueIds) { + const cached = queryClient.getQueryData(['event-stats', id]); + if (cached) { + placeholderMap.set(id, cached); + } + } + return placeholderMap.size > 0 ? placeholderMap : undefined; + }, }); }