Remove duplicate community data prefetching in layout and page components
Problem
Community pages (/trending/hive-123, /hot/hive-123, etc.) make duplicate API calls because both the layout wrapper and page component prefetch the same data with identical query keys.
Root Cause
Layout (features/layouts/community/prefetch-component.tsx:29-42):
if (isCommunity(tag)) {
await queryClient.prefetchQuery({
queryKey: ['community', community],
queryFn: () => getCommunity(community, observer)
});
await queryClient.prefetchQuery({
queryKey: ['subscribers', community],
queryFn: () => getSubscribers(community)
});
await queryClient.prefetchQuery({
queryKey: ['AccountNotification', community],
queryFn: () => getAccountNotifications(community)
});
}
Page (features/community-profile/sort-page.tsx:31-42):
if (isCommunity(tag)) {
await queryClient.prefetchQuery({
queryKey: ['community', community], // DUPLICATE
queryFn: () => getCommunity(community, observer)
});
await queryClient.prefetchQuery({
queryKey: ['subscribers', community], // DUPLICATE
queryFn: () => getSubscribers(community)
});
await queryClient.prefetchQuery({
queryKey: ['AccountNotification', community], // DUPLICATE
queryFn: () => getAccountNotifications(community)
});
}
Impact
-
3 potentially duplicate API calls per community page visit:
bridge.get_communitybridge.list_subscribersbridge.account_notifications
- React Query may deduplicate via query key, but:
- Initial fetch before caching still happens
- Code duplication is confusing and error-prone
-
list_subscribersandaccount_notificationsaren't needed for SSR (sidebar/tab content, not above-the-fold)
Comparison with Condenser
Condenser makes 3-4 SSR calls for community pages:
bridge.get_ranked_postsbridge.get_communitycondenser_api.get_feed_historycondenser_api.get_dynamic_global_properties
Denser makes 5-7 calls (before deduplication), fetching subscriber and notification data that isn't critical for initial render.
Proposed Fix
- Consolidate prefetches to one location - either layout OR page, not both
-
Remove non-critical SSR prefetches:
-
getSubscribers()- sidebar detail, not critical for initial render -
getAccountNotifications()- tab content, not initial view
-
-
Keep only
getCommunity()in SSR - needed for page metadata (title, OG tags)
Recommended Changes
In prefetch-component.tsx:
if (isCommunity(tag)) {
// Only prefetch what's needed for page metadata and initial render
await queryClient.prefetchQuery({
queryKey: ['community', community],
queryFn: () => getCommunity(community, observer)
});
// Remove getSubscribers and getAccountNotifications - let client fetch
}
In sort-page.tsx:
Remove duplicate community prefetches entirely - layout handles it.
Related
- #790 (closed) - Remove unnecessary SSR prefetch for user subscriptions
- #764 - Current API calls are sub-optimal for denser needs
- NOTES/05-api-call-comparison-results.md - Full API comparison analysis