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 <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy
2026-02-19 04:55:57 -06:00
parent e7277c6fee
commit 3a02902df2
+12 -1
View File
@@ -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<string, EventStats>();
for (const id of uniqueIds) {
const cached = queryClient.getQueryData<EventStats>(['event-stats', id]);
if (cached) {
placeholderMap.set(id, cached);
}
}
return placeholderMap.size > 0 ? placeholderMap : undefined;
},
});
}