Summary
Replace TanStack Query with TanStack DB across all plugins to leverage live queries and optimistic mutations. Currently blocked on TanStack DB supporting prefetching at the Hydration Boundary (required for SSR).
Motivation
TanStack DB provides:
- Live queries - Reactive updates when data changes without manual invalidation
- Optimistic mutations - Instant UI updates with automatic rollback on failure
- Client-first store - Query data however components need it, reducing custom endpoint logic
- Simplified cache management - No more manual
invalidateQueries calls
Blocker
⏳ Waiting on: TanStack DB support for prefetching at the Hydration Boundary TanStack/db#709
Currently, our SSR loaders use queryClient.prefetchQuery() to populate the cache server-side before hydration. TanStack DB needs equivalent functionality for createCollection to work with SSR frameworks (Next.js, React Router, TanStack Start).
Affected Plugins
blog - posts, tags, drafts
cms - dynamic collections, entries
ai-chat - conversations, messages
form-builder - forms, submissions
route-docs - documentation pages
Migration Scope
| Current (TanStack Query) |
New (TanStack DB) |
createQueryKeys() factories |
createCollection() with queryCollectionOptions |
useSuspenseQuery() / useQuery() |
useLiveQuery() |
useMutation() + invalidateQueries() |
collection.insert() / update() / delete() |
queryClient.prefetchQuery() in loaders |
Pending SSR hydration support |
Example Migration
Before (blog posts):
const { data } = useSuspenseQuery(queries.posts.list());
After:
const postsCollection = createCollection(queryCollectionOptions({
queryKey: ['posts'],
queryFn: () => fetch('/api/posts').then(r => r.json()),
getKey: (post) => post.id,
onUpdate: async ({ transaction }) => { /* sync to server */ },
}));
const { data } = useLiveQuery((q) =>
q.from({ post: postsCollection })
.where(({ post }) => eq(post.published, true))
.orderBy(({ post }) => post.createdAt, 'desc')
);
Tasks
Resources
Summary
Replace TanStack Query with TanStack DB across all plugins to leverage live queries and optimistic mutations. Currently blocked on TanStack DB supporting prefetching at the Hydration Boundary (required for SSR).
Motivation
TanStack DB provides:
invalidateQueriescallsBlocker
⏳ Waiting on: TanStack DB support for prefetching at the Hydration Boundary TanStack/db#709
Currently, our SSR loaders use
queryClient.prefetchQuery()to populate the cache server-side before hydration. TanStack DB needs equivalent functionality forcreateCollectionto work with SSR frameworks (Next.js, React Router, TanStack Start).Affected Plugins
blog- posts, tags, draftscms- dynamic collections, entriesai-chat- conversations, messagesform-builder- forms, submissionsroute-docs- documentation pagesMigration Scope
createQueryKeys()factoriescreateCollection()withqueryCollectionOptionsuseSuspenseQuery()/useQuery()useLiveQuery()useMutation()+invalidateQueries()collection.insert()/update()/delete()queryClient.prefetchQuery()in loadersExample Migration
Before (blog posts):
After:
Tasks
AGENTS.mdwith TanStack DB patternsblogplugin (simplest, good first candidate)cmsplugin (complex relations)ai-chatplugin (streaming considerations)form-builderpluginResources