File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11---
2- " @tanstack/svelte-db " : minor
2+ ' @tanstack/svelte-db ' : minor
33---
44
55Add SSR and hydration support for SvelteKit
66
77New APIs for server-side rendering:
8+
89- ` createServerContext() ` - creates context to collect prefetched queries
910- ` prefetchLiveQuery() ` - prefetches data server-side without starting sync
1011- ` dehydrate() ` - serializes context for JSON transport
1112- ` HydrationBoundary ` - component that provides hydration context to children
1213
1314The ` useLiveQuery ` hook now supports hydration:
15+
1416- Pass an ` id ` in the config object to match with server-prefetched data
1517- Hydrated data is returned immediately while the collection syncs in background
1618- ` isReady ` returns ` true ` when using hydrated data
Original file line number Diff line number Diff line change 1- import { getContext , setContext } from " svelte"
2- import type { DehydratedState } from " ./server"
1+ import { getContext , setContext } from ' svelte'
2+ import type { DehydratedState } from ' ./server'
33
44/**
55 * Context key for hydration state
Original file line number Diff line number Diff line change @@ -12,10 +12,7 @@ export {
1212 type PrefetchLiveQueryOptions ,
1313} from './server.js'
1414
15- export {
16- setHydrationContext ,
17- getHydrationContext ,
18- } from './hydration.svelte.js'
15+ export { setHydrationContext , getHydrationContext } from './hydration.svelte.js'
1916
2017export { default as HydrationBoundary } from './HydrationBoundary.svelte'
2118
Original file line number Diff line number Diff line change 1- import { createLiveQueryCollection } from " @tanstack/db"
1+ import { createLiveQueryCollection } from ' @tanstack/db'
22import type {
33 Context ,
44 InitialQueryBuilder ,
55 LiveQueryCollectionConfig ,
66 QueryBuilder ,
7- } from " @tanstack/db"
7+ } from ' @tanstack/db'
88
99/**
1010 * Server context for managing live query prefetching and dehydration
@@ -89,7 +89,7 @@ export function createServerContext(): ServerContext {
8989 */
9090export async function prefetchLiveQuery < TContext extends Context > (
9191 serverContext : ServerContext ,
92- options : PrefetchLiveQueryOptions < TContext >
92+ options : PrefetchLiveQueryOptions < TContext > ,
9393) : Promise < void > {
9494 const { id, query, transform } = options
9595
Original file line number Diff line number Diff line change @@ -485,7 +485,7 @@ export function useLiveQuery(
485485 hydratedData === undefined
486486 ) {
487487 console . warn (
488- `TanStack DB: no hydrated data found for id "${ queryId } " — did you prefetch this query on the server with prefetchLiveQuery()?`
488+ `TanStack DB: no hydrated data found for id "${ queryId } " — did you prefetch this query on the server with prefetchLiveQuery()?` ,
489489 )
490490 }
491491
@@ -508,7 +508,7 @@ export function useLiveQuery(
508508 ? config . getKey ( item )
509509 : index
510510 return [ key , item ]
511- } )
511+ } ) ,
512512 )
513513 }
514514 return state
@@ -558,7 +558,9 @@ export function useLiveQuery(
558558 } ,
559559 get isReady ( ) {
560560 // Consider hydrated data as "ready enough" for UI
561- return status === `ready` || status === `disabled` || shouldUseHydratedData ( )
561+ return (
562+ status === `ready` || status === `disabled` || shouldUseHydratedData ( )
563+ )
562564 } ,
563565 get isIdle ( ) {
564566 return status === `idle`
You can’t perform that action at this time.
0 commit comments