Problem
The counts collection is seeded from SSR-prefetched entries.count queries in the TRPCProvider useState initializer (src/lib/trpc/provider.tsx:182-196). However, this runs synchronously during component initialization, and the SSR prefetch data may not be in the query cache yet at that point since the prefetches in layout.tsx use void Promise.all([...]) (fire-and-forget).
If the count data arrives after collections are initialized, it never gets seeded into the counts collection, causing "All", "Starred", and "Saved" sidebar items to show no unread counts until a mutation or SSE event triggers a count update.
The uncategorized counts already have a query cache subscription pattern (lines 164-177 of index.ts) that watches for tags.list data updates and syncs them. The same pattern should be applied for the "all", "starred", and "saved" counts.
Current behavior
// provider.tsx:182-196 - runs once in useState initializer
const countQueries = queryClient.getQueriesData<{ total: number; unread: number }>({
queryKey: [["entries", "count"]],
});
for (const [queryKey, data] of countQueries) {
if (!data) continue;
// ... insert into counts collection
}
// If data wasn't in cache yet, counts are never seeded
Fix
Add a query cache subscription (similar to the uncategorized counts pattern) that watches for entries.count query updates and syncs them into the counts collection. This ensures counts are seeded whenever the data arrives, whether from SSR hydration or subsequent fetches.
Related to #580 (tanstack-db branch).
-- Claude
Problem
The counts collection is seeded from SSR-prefetched
entries.countqueries in theTRPCProvideruseStateinitializer (src/lib/trpc/provider.tsx:182-196). However, this runs synchronously during component initialization, and the SSR prefetch data may not be in the query cache yet at that point since the prefetches inlayout.tsxusevoid Promise.all([...])(fire-and-forget).If the count data arrives after collections are initialized, it never gets seeded into the counts collection, causing "All", "Starred", and "Saved" sidebar items to show no unread counts until a mutation or SSE event triggers a count update.
The uncategorized counts already have a query cache subscription pattern (lines 164-177 of
index.ts) that watches for tags.list data updates and syncs them. The same pattern should be applied for the "all", "starred", and "saved" counts.Current behavior
Fix
Add a query cache subscription (similar to the uncategorized counts pattern) that watches for
entries.countquery updates and syncs them into the counts collection. This ensures counts are seeded whenever the data arrives, whether from SSR hydration or subsequent fetches.Related to #580 (tanstack-db branch).
-- Claude