Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

ssr.md

834 lines24.3 KB

1---
2title: SSR and Hydration
3id: ssr
4---
5​
6TanStack DB SSR transports the smallest useful snapshot for the work the server
7performed:
8​
9- Explicitly preloaded collections dehydrate as normalized collection rows.
10- Preloaded or render-discovered live queries dehydrate as ordered query-result
11 snapshots, without serializing all of their source collections.
12​
13The browser renders either snapshot immediately, starts its normal collection
14sync and live-query pipeline, then atomically replaces a live-query snapshot
15when the browser result becomes authoritative.
16​
17## High-level Summary
18​
19The SSR-friendly API adds six concepts:
20​
21- `DbClient` owns materialized collection instances for one request, browser app,
22 test, or script.
23- `collectionOptions(...)` creates a stable collection descriptor. Reusable
24 descriptors create fresh adapter config for each `DbClient`.
25- `dbClient.dehydrate()`, `dbClient.hydrate(state)`, and
26 `dbClient.applyCollectionChunk(chunk)` move explicit collection state across
27 the server/client boundary.
28- `dbClient.preloadLiveQuery(options)` captures only the ordered result of a
29 live query for hydration or streaming.
30- React and Svelte apps use `DbProvider` so hooks can resolve collection
31 descriptors against the current client.
32- `@tanstack/react-router-with-db` streams live queries discovered by Suspense
33 during a TanStack Start server render.
34​
35Existing apps continue to work. `createCollection(...)` and direct collection
36instances still exist. The migration is required when you want SSR-safe request
37isolation, hydration, incremental chunks, Suspense streaming, or the 1.0-ready
38React hook shape.
39​
40The old dependency-array form now warns:
41​
42```tsx
43useLiveQuery((q) => q.from({ todos }).where(...), [status])
44```
45​
46It still works, but warns in development and will be removed in 1.0. Prefer:
47​
48```tsx
49useLiveQuery({
50 query: (q) => q.from({ todos: todoCollection }).where(...),
51})
52```
53​
54React derives live query identity from structured query IR by default. Add
55`queryKey` only for opaque functional query logic or for a hot render path where
56you want to skip derived identity work.
57​
58If the old dependency array tracked a Collection object that you replace while
59the hook stays mounted, give the replacement a distinct ID. A different source
60object with the same ID now throws in the derived-identity form. To reuse the
61ID, unmount the old hook, clean up its source and client scope, then mount the
62replacement.
63​
64## Cheat Sheet
65​
66| Task | Before | SSR-friendly |
67| --- | --- | --- |
68| Define a collection | `createCollection(options)` | `collectionOptions(id, factory)` |
69| Materialize a collection | module-level singleton | `dbClient.collection(todoCollection)` |
70| Scope collection state | module lifetime | `new DbClient()` per request/browser/test |
71| Provide React context | none | `<DbProvider client={dbClient}>` |
72| Query from React | direct collection instance | descriptor in `from`, resolved by `DbProvider` |
73| Mutate from React | import singleton collection | `useDbClient().collection(todoCollection)` |
74| Server preload | ad hoc collection preload | `collection.preload()` or `dbClient.preloadLiveQuery(...)` |
75| Serialize SSR state | none | `const state = dbClient.dehydrate()` |
76| Hydrate in browser | none | `dbClient.hydrate(state)` before hooks read it |
77| Apply rows incrementally | custom app state | `dbClient.applyCollectionChunk(chunk)` |
78| Stream render-time results | none | `routerWithDbClient(router, dbClient)` |
79| React query identity | dependency array | derived IR, or `queryKey` when needed |
80​
81### Minimal React Pattern
82​
83```tsx
84import {
85 DbClient,
86 DbProvider,
87 collectionOptions,
88 eq,
89 useDbClient,
90 useLiveQuery,
91} from '@tanstack/react-db'
92​
93const todoCollection = collectionOptions('todos', () => ({
94 id: 'todos',
95 getKey: (todo: Todo) => todo.id,
96 sync: {
97 sync: ({ markReady }) => {
98 markReady()
99 },
100 },
101}))
102​
103function useTodoCollection() {
104 return useDbClient().collection(todoCollection)
106​
107function Todos({ status }: { status: string }) {
108 const todos = useTodoCollection()
109​
110 const { data } = useLiveQuery({
111 query: (q) =>
112 q
113 .from({ todo: todoCollection })
114 .where(({ todo }) => eq(todo.status, status)),
115 })
116​
117 return (
118 <ul>
119 {data.map((todo) => (
120 <li
121 key={todo.id}
122 onClick={() => todos.update(todo.id, (draft) => {
123 draft.done = true
124 })}
125 >
126 {todo.title}
127 </li>
128 ))}
129 </ul>
130 )
132​
133const dbClient = new DbClient()
134​
135root.render(
136 <DbProvider client={dbClient}>
137 <Todos status="open" />
138 </DbProvider>
140```
141​
142The factory matters when config contains mutable adapter state or closures.
143Every `DbClient` gets a fresh config and collection instance. First-party
144adapter option creators already attach an equivalent factory, so this is also
145safe:
146​
147```tsx
148const todoCollection = collectionOptions(
149 localOnlyCollectionOptions<Todo>({
150 id: 'todos',
151 getKey: (todo) => todo.id,
152 })
154```
155​
156Within one `DbClient`, descriptors with the same `id` resolve to the same
157collection. Only the first descriptor is materialized. Include every dynamic
158parameter that changes the collection in its `id`.
159​
160A descriptor created from an arbitrary concrete config can be materialized by
161one `DbClient` only. Use the explicit factory form for custom adapters and
162request-scoped dependencies.
163​
164## SSR Flow
165​
166The server and browser use the same descriptors, but different `DbClient`
167instances.
168​
169```txt
170server request
171 -> new DbClient()
172 -> preload an explicit collection or live-query result
173 -> dbClient.dehydrate()
174 -> send state through framework loader
175​
176browser
177 -> new DbClient()
178 -> dbClient.hydrate(loaderState)
179 -> <DbProvider client={dbClient}>
180 -> useLiveQuery({ query })
181 -> start source sync
182 -> atomically replace any query snapshot with the live result
183```
184​
185During React hydration, descriptor-backed queries read either hydrated
186collection rows or their matching query-result snapshot for the first browser
187render. Adapter sync and queued on-demand loads start when React commits the
188external-store subscription, so the initial markup still matches the server.
189The snapshot remains visible while the source is loading. Once the browser live
190query is ready, DB publishes one handoff from the snapshot to the live result.
191​
192### Server
193​
194Create a fresh `DbClient` for each request. Materialize descriptors through that
195client, preload the data needed for the route, and dehydrate the client.
196​
197```tsx
198import { DbClient, collectionOptions, eq } from '@tanstack/db'
199​
200export const todoCollection = collectionOptions('todos', () => ({
201 id: 'todos',
202 getKey: (todo: Todo) => todo.id,
203 syncMode: 'on-demand',
204 sync: {
205 sync: ({ markReady, begin, write, commit }) => {
206 markReady()
207​
208 return {
209 loadSubset: async () => {
210 const todos = await api.todos.list()
211 begin()
212 for (const todo of todos) {
213 write({ type: 'insert', value: todo })
214 }
215 commit()
216 return true
217 },
218 }
219 },
220 },
221}))
222​
223export async function loadTodosForSsr() {
224 const dbClient = new DbClient()
225 const todos = dbClient.collection(todoCollection)
226 await todos.preload()
227​
228 return dbClient.dehydrate()
230```
231​
232This explicit collection preload dehydrates normalized source rows. Use it when
233multiple browser queries need the same source data.
234​
235If the source is much larger than the rendered result, preload the query instead:
236​
237```tsx
238const dbClient = new DbClient()
239​
240await dbClient.preloadLiveQuery({
241 query: (q) =>
242 q
243 .from({ todo: todoCollection })
244 .where(({ todo }) => eq(todo.status, 'open'))
245 .select(({ todo }) => ({ id: todo.id, title: todo.title })),
246})
247​
248const state = dbClient.dehydrate()
249```
250​
251This payload contains the projected query result and no source collection rows
252unless that collection was also materialized explicitly.
253​
254### Browser
255​
256Hydrate the browser client before rendering components that read from DB.
257​
258```tsx
259import {
260 DbClient,
261 DbProvider,
262 HydrationBoundary,
263} from '@tanstack/react-db'
264​
265function App({ dehydratedDbState }: { dehydratedDbState: DehydratedDbState }) {
266 const [dbClient] = React.useState(() => new DbClient())
267​
268 return (
269 <DbProvider client={dbClient}>
270 <HydrationBoundary state={dehydratedDbState}>
271 <Routes />
272 </HydrationBoundary>
273 </DbProvider>
274 )
276```
277​
278Frameworks differ in how loader data reaches the client, but the DB handoff is
279the same: `DbClient` on the server, `dehydrate()`, then `hydrate()` into the
280browser client.
281​
282### Svelte
283​
284Svelte resolves descriptors from its own `DbProvider` and reads hydrated query
285snapshots synchronously during server rendering:
286​
287```svelte
288<script lang="ts">
289 import { DbClient, DbProvider } from '@tanstack/svelte-db'
290 import Todos from './Todos.svelte'
291​
292 const client = new DbClient()
293 client.hydrate(dehydratedDbState)
294</script>
295​
296<DbProvider {client}>
297 <Todos />
298</DbProvider>
299```
300​
301Inside `Todos.svelte`, `useLiveQuery({ query })` can use collection descriptors
302directly. The browser subscription starts source sync and performs the same
303snapshot-to-live-result handoff as React.
304​
305Live demo: https://tanstack-db-ssr-demo.netlify.app/ssr-db
306​
307## Suspense Streaming with TanStack Start
308​
309`@tanstack/react-router-with-db` follows the same integration pattern as
310`@tanstack/react-router-with-query`:
311​
312```tsx
313import { DbClient } from '@tanstack/react-db'
314import { createRouter } from '@tanstack/react-router'
315import { routerWithDbClient } from '@tanstack/react-router-with-db'
316​
317export type RouterContext = {
318 dbClient: DbClient
320​
321export function getRouter() {
322 const dbClient = new DbClient()
323 const router = createRouter({
324 routeTree,
325 context: { dbClient },
326 })
327​
328 return routerWithDbClient(router, dbClient)
330```
331​
332The adapter adds `dbClient` to router context, wraps the app in `DbProvider`,
333dehydrates critical state, and opens a stream for query results discovered later
334during rendering.
335​
336```tsx
337function RouteComponent() {
338 return (
339 <Suspense fallback={<p>Loading todos</p>}>
340 <TodoList />
341 </Suspense>
342 )
344​
345function TodoList() {
346 const { data } = useLiveSuspenseQuery({
347 query: (q) =>
348 q
349 .from({ todo: todoCollection })
350 .where(({ todo }) => eq(todo.status, 'open')),
351 })
352​
353 return data.map((todo) => <Todo key={todo.id} todo={todo} />)
355```
356​
357When `TodoList` suspends on the server, the adapter streams the pending query
358promise. That promise resolves to the ordered live-query result snapshot inside
359the streamed `DehydratedDbState`. The source collections and D2 graph do not
360cross the wire. The browser shows the snapshot, starts the source collections
361and live query normally, then replaces the snapshot when the browser result is
362ready.
363​
364The server and browser must derive the same live-query identity. Structured
365queries do this automatically. An opaque query must provide a serializable
366`queryKey`; render-time streaming throws if it cannot derive an identity.
367​
368## Suspense Streaming with Next.js
369​
370Next.js App Router can transport the same pending query promise through React
371Server Components. Start the preload without awaiting it, dehydrate the pending
372result, and pass that state to a client hydration boundary:
373​
374```tsx
375export default function Page() {
376 const dbClient = new DbClient()
377 void dbClient.preloadLiveQuery(openTodosQuery)
378​
379 const state = dbClient.dehydrate({
380 shouldDehydrateCollection: () => false,
381 shouldDehydrateLiveQuery: () => true,
382 })
383​
384 return (
385 <DbHydration state={state}>
386 <Suspense fallback={<p>Loading todos</p>}>
387 <TodoList />
388 </Suspense>
389 </DbHydration>
390 )
392```
393​
394`DbHydration` is a client component that creates one browser `DbClient`, wraps
395children in `DbProvider`, and passes `state` to `HydrationBoundary`. React streams
396the promise result into that boundary. The full working integration is in
397`examples/react/next-ssr-e2e`.
398​
399## Incremental Collection Hydration
400​
401Applications can also apply collection rows received through their own stream.
402Incremental hydration uses the same collection chunk shape as holistic
403dehydration:
404​
405```ts
406dbClient.applyCollectionChunk({
407 collectionId: 'todos',
408 rows: [
409 {
410 key: 'todo-1',
411 value: {
412 id: 'todo-1',
413 title: 'Streamed row',
414 status: 'open',
415 },
416 metadata: { source: 'stream' },
417 },
418 ],
419 syncMeta: { version: 1, cursor: 'abc' },
420})
421```
422​
423If the target collection is already materialized, the rows apply immediately and
424existing live queries react from collection state. If the collection is not
425materialized yet, the chunk is stored and applied when that `collectionId`
426materializes.
427​
428## What Gets Serialized
429​
430`dbClient.dehydrate()` can emit two independent snapshot types.
431​
432Serialized:
433​
434- explicit collection snapshots: collection id, synced row keys and values, row
435 metadata, and adapter sync metadata from `exportSyncMeta`
436- live-query snapshots: query hash and ordered result rows; completed explicit
437 preloads are included by default, while framework integrations opt pending
438 promises into streaming
439​
440Not serialized:
441​
442- mutation handlers
443- pending optimistic mutations
444- pending subscriptions
445- D2 graphs or compiled pipelines
446- transaction stacks
447- module-level runtime state
448- source collection rows for a query-result snapshot, unless that collection was
449 also explicitly materialized for dehydration
450​
451Choose the payload unit according to what the browser needs. Explicit collection
452preloading preserves normalized rows for reuse across queries. Live-query
453preloading avoids shipping a 50-100x larger source when the rendered projection
454is small. Neither mode serializes executable query state.
455​
456## Sync Metadata
457​
458Adapters can participate in resumable sync with three optional hooks:
459​
460```ts
461type SyncConfig = {
462 exportSyncMeta?: () => unknown
463 importSyncMeta?: (meta: unknown) => void
464 mergeSyncMeta?: (current: unknown, incoming: unknown) => unknown
466```
467​
468The metadata shape is adapter-owned. Version it inside the adapter payload. If an
469adapter cannot understand incoming metadata, it should ignore it and restart
470sync from a safe point.
471​
472During hydration, DB imports `syncMeta` into the materialized collection. If the
473collection already has current metadata, DB calls `mergeSyncMeta(current,
474incoming)` when provided and imports the merged result.
475​
476If an adapter does not implement sync metadata hooks, row snapshots still hydrate
477and the adapter can restart sync normally.
478​
479## Initial Data
480​
481`initialData` is a startup seed, not a sync-ready signal.
482​
483Before adapter sync starts, current `DbClient` precedence from lowest to highest
484is:
485​
4861. per-materialization `initialData`
4872. persisted rows
4883. hydrated rows
489​
490Fresh adapter sync is authoritative over all three. Hydrated and initial rows
491are provisional base state, so the adapter's first insert for the same key is
492reconciled as an update instead of raising a duplicate-key error.
493​
494Hydrated rows and `initialData` never mark adapter sync as ready by themselves.
495The adapter still owns readiness through its sync lifecycle.
496​
497## React Query Identity
498​
499React hooks derive live query identity from structured query IR by default:
500​
501```tsx
502function Todos({ status }: { status: string }) {
503 return useLiveQuery({
504 query: (q) =>
505 q
506 .from({ todo: todoCollection })
507 .where(({ todo }) => eq(todo.status, status)),
508 })
510```
511​
512The captured `status` value is represented in the structured IR, so no
513dependency array or `queryKey` is required.
514​
515Use `queryKey` when the query contains opaque runtime logic that DB cannot
516stably represent:
517​
518```tsx
519function SearchTodos({ search }: { search: string }) {
520 return useLiveQuery({
521 queryKey: [todoCollection.id, 'search', search],
522 query: (q) =>
523 q
524 .from({ todo: todoCollection })
525 .fn.where(({ todo }) =>
526 todo.title.toLowerCase().includes(search.toLowerCase())
527 ),
528 })
530```
531​
532Common reasons to add `queryKey`:
533​
534- `.fn.where(...)`
535- `.fn.select(...)`
536- `.fn.having(...)`
537- function values, symbols, class instances, or circular objects captured inside
538 the structured query
539- a render path where derived identity becomes measurably expensive
540​
541Before 1.0, DB warns when structured IR cannot be hashed and preserves the
542legacy mount-stable identity. The query still works, but captured values inside
543opaque logic are not reactive unless they are represented in `queryKey`. In 1.0,
544an unhashable query without `queryKey` will throw.
545​
546DB also warns once in development if deriving identity becomes expensive enough
547that an explicit `queryKey` would be better.
548​
549Dependency arrays are accepted for backwards compatibility:
550​
551```tsx
552useLiveQuery((q) => q.from({ todo: todoCollection }), [status])
553```
554​
555They warn in development and will be removed in 1.0. Migrate to the config
556object form:
557​
558```tsx
559useLiveQuery({
560 query: (q) => q.from({ todo: todoCollection }),
561})
562```
563​
564Add `queryKey` only if the query uses opaque logic or trips the performance
565warning.
566​
567## Migration Guide
568​
569### 1. Create descriptors instead of SSR singletons
570​
571For collections that need SSR, replace module-level `createCollection(...)`
572with a reusable `collectionOptions(...)` descriptor.
573​
574```tsx
575// Before
576export const todoCollection = createCollection({
577 id: 'todos',
578 getKey: (todo) => todo.id,
579 sync: todoSync,
580})
581​
582// After
583export const todoCollection = collectionOptions('todos', () => ({
584 id: 'todos',
585 getKey: (todo: Todo) => todo.id,
586 sync: createTodoSync(),
587}))
588```
589​
590Put mutable state and closures inside the factory. First-party adapter option
591creators can also be passed directly because they provide a fresh config
592factory. Collections that never participate in SSR can keep using
593`createCollection`.
594​
595### 2. Add a `DbClient`
596​
597Use a new client for every server request and a stable client for each browser
598app instance.
599​
600```tsx
601const dbClient = new DbClient()
602```
603​
604In tests, create a new client per test unless the test is explicitly covering
605shared state.
606​
607### 3. Wrap React with `DbProvider`
608​
609```tsx
610root.render(
611 <DbProvider client={dbClient}>
612 <App />
613 </DbProvider>
615```
616​
617Hooks that resolve collection descriptors need this provider. Without it, DB
618throws instead of falling back to hidden global state.
619​
620### 4. Use collection hooks for imperative operations
621​
622Use descriptors directly in live query sources, and materialize only when you
623need collection methods:
624​
625```tsx
626function useTodoCollection() {
627 return useDbClient().collection(todoCollection)
629​
630function TodoActions({ id }: { id: string }) {
631 const todos = useTodoCollection()
632​
633 return (
634 <button onClick={() => todos.delete(id)}>
635 Delete
636 </button>
637 )
639```
640​
641This keeps request/client scoping in one place and avoids reintroducing
642module-level collections.
643​
644### 5. Replace dependency arrays
645​
646Most queries can drop the dependency array entirely:
647​
648```tsx
649// Before
650useLiveQuery(
651 (q) =>
652 q
653 .from({ todo: todoCollection })
654 .where(({ todo }) => eq(todo.status, status)),
655 [status],
657​
658// After
659useLiveQuery({
660 query: (q) =>
661 q
662 .from({ todo: todoCollection })
663 .where(({ todo }) => eq(todo.status, status)),
664})
665```
666​
667If the query uses opaque functional variants, add `queryKey`:
668​
669```tsx
670useLiveQuery({
671 queryKey: [todoCollection.id, 'status-fn', status],
672 query: (q) =>
673 q
674 .from({ todo: todoCollection })
675 .fn.where(({ todo }) => todo.status === status),
676})
677```
678​
679### 6. Preload and dehydrate on the server
680​
681Preload a collection when the browser should receive normalized source rows:
682​
683```tsx
684const dbClient = new DbClient()
685const todos = dbClient.collection(todoCollection)
686await todos.preload()
687​
688return {
689 dbState: dbClient.dehydrate(),
691```
692​
693Preload a live query when the browser only needs the rendered result:
694​
695```tsx
696const dbClient = new DbClient()
697await dbClient.preloadLiveQuery(openTodosQuery)
698​
699return {
700 dbState: dbClient.dehydrate(),
702```
703​
704### 7. Hydrate before client hooks read DB
705​
706```tsx
707<DbProvider client={client}>
708 <HydrationBoundary state={loaderData.dbState}>
709 <App />
710 </HydrationBoundary>
711</DbProvider>
712```
713​
714Imperative integrations can call `client.hydrate(loaderData.dbState)` before
715rendering instead.
716​
717## Compatibility
718​
719No existing public API is removed by this change.
720​
721Still supported:
722​
723- `createCollection(...)`
724- passing collection instances to `useLiveQuery(...)`
725- `useLiveQuery(queryFn, deps)`
726- `useLiveSuspenseQuery(queryFn, deps)`
727- mutation APIs such as `insert`, `update`, `delete`, `subscribe`, and
728 optimistic mutation helpers
729​
730Warnings:
731​
732- React dependency arrays warn in development and will be removed in 1.0.
733- Opaque query IR without `queryKey` warns in development and keeps legacy
734 mount-stable identity until 1.0. In 1.0 it will throw.
735- Expensive derived identity warns in development and suggests `queryKey`.
736​
737Required for SSR:
738​
739- stable explicit collection ids
740- request-scoped server `DbClient`
741- browser-scoped client `DbClient`
742- `DbProvider` for descriptor resolution in React
743- `dehydrate()` on the server and `hydrate()` in the browser
744​
745Required for render-time Suspense streaming:
746​
747- `routerWithDbClient(router, dbClient)`
748- `useLiveSuspenseQuery(...)` inside a Suspense boundary
749- a stable derived query identity or explicit serializable `queryKey`
750​
751## Detailed Changelog
752​
753### Added
754​
755- `DbClient`
756- `collectionOptions(...)`
757- `CollectionOptions` descriptor type
758- `CollectionMaterializeOptions`
759- `DehydratedDbState`
760- `DehydratedCollectionChunk`
761- `DehydratedCollectionRow`
762- `dbClient.collection(descriptor, options?)`
763- `dbClient.dehydrate()`
764- `dbClient.hydrate(state)`
765- `dbClient.applyCollectionChunk(chunk)`
766- `dbClient.subscribe(listener)`
767- `dbClient.createTransaction(config)`
768- `dbClient.cleanup()`
769- React `DbProvider`
770- React `useDbClient()`
771- React `useOptionalDbClient()`
772- React `HydrationBoundary`
773- React descriptor resolution inside live query builders
774- React derived structured query identity
775- React `queryKey` escape hatch for opaque or hot-path queries
776- React per-query `client` override
777- SSR-capable `useSyncExternalStore` server snapshot support
778- `dbClient.preloadLiveQuery(...)`
779- Svelte `DbProvider`, `useDbClient()`, descriptor resolution, and synchronous
780 server snapshot support
781- TanStack Start and Next.js Playwright SSR E2E coverage
782- `@tanstack/react-router-with-db`
783- render-time `useLiveSuspenseQuery` promise streaming
784​
785### Changed
786​
787- React `useLiveQuery({ query })` can use collection descriptors directly in
788 `from`, `join`, `leftJoin`, and `unionAll` sources when a `DbProvider` is
789 present.
790- React live query identity is derived from normalized structured IR when no
791 explicit `queryKey` or legacy dependency array is supplied.
792- Explicit collection preloading serializes normalized collection rows.
793- Live-query preloading and render-time discovery serialize ordered result
794 snapshots without implicitly serializing source collections.
795- Browser observers keep the hydrated result visible while normal source sync
796 starts, then publish one authoritative handoff.
797- Hydration applies rows as committed synced state without invoking mutation
798 handlers or creating optimistic state.
799- Hydration and adapter sync begin in a deterministic order: pending rows and
800 sync metadata are imported before sync starts.
801- `DbClient` owns collection instances and ambient transaction scope; cleanup
802 releases both.
803- Incremental chunks use the same collection payload shape as full dehydration.
804- Streamed live-query promises resolve to live-query result snapshots.
805​
806### Deprecated
807​
808- React dependency arrays for `useLiveQuery` and wrappers that delegate to it.
809 They still work and warn in development. They are planned for removal in 1.0.
810​
811### Not Changed
812​
813- `createCollection(...)` remains available.
814- Direct collection runtime APIs remain available.
815- Vue, Solid, and Angular keep their existing dependency/reactivity model until
816 they get their own SSR/client-provider work. Svelte is covered by this change.
817- Query collection `queryKey` is still TanStack Query's cache key. It is
818 separate from React live query identity.
819​
820## Validation
821​
822The SSR strategy is covered by:
823​
824- core `DbClient` tests for hydration, streaming chunks, sync metadata,
825 initial data precedence, explicit ids, and no optimistic serialization
826- React tests for `DbProvider`, descriptor resolution, derived query identity,
827 `queryKey`, deprecation warnings, SSR result snapshots, and atomic handoff
828- Svelte tests for provider ownership, server snapshot rendering, and browser
829 handoff
830- query adapter tests to ensure Query cache behavior still holds
831- persistence core tests to ensure persisted row behavior remains intact
832- TanStack Start and Next.js Playwright E2Es that verify a Suspense fallback,
833 streamed query result, omitted source-only data, clean hydration, and atomic
834 replacement by browser sync