Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/react-db/src/useLiveQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import type {

const DEFAULT_GC_TIME_MS = 1 // Live queries created by useLiveQuery are cleaned up immediately (0 disables GC)

// Module-level constant so React 19 receives a stable object reference for the
// server snapshot. Creating this inside the hook would produce a new reference
// on every render, causing an infinite loop during SSR/hydration.
const SERVER_SNAPSHOT = { collection: null, version: 0 } as const

export type UseLiveQueryStatus = CollectionStatus | `disabled`

/**
Expand Down Expand Up @@ -483,6 +488,7 @@ export function useLiveQuery(
const snapshot = useSyncExternalStore(
subscribeRef.current,
getSnapshotRef.current,
() => SERVER_SNAPSHOT,
)

// Track last snapshot (from useSyncExternalStore) and the returned value separately
Expand Down