Skip to content

Commit a87a6e3

Browse files
ci: apply automated fixes
1 parent a72dc0d commit a87a6e3

5 files changed

Lines changed: 14 additions & 13 deletions

File tree

.changeset/svelte-db-ssr-hydration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
---
2-
"@tanstack/svelte-db": minor
2+
'@tanstack/svelte-db': minor
33
---
44

55
Add SSR and hydration support for SvelteKit
66

77
New 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

1314
The `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

packages/svelte-db/src/hydration.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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

packages/svelte-db/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff 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

2017
export { default as HydrationBoundary } from './HydrationBoundary.svelte'
2118

packages/svelte-db/src/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { createLiveQueryCollection } from "@tanstack/db"
1+
import { createLiveQueryCollection } from '@tanstack/db'
22
import 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
*/
9090
export 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

packages/svelte-db/src/useLiveQuery.svelte.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff 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`

0 commit comments

Comments
 (0)