diff --git a/.changeset/poor-vans-design.md b/.changeset/poor-vans-design.md new file mode 100644 index 000000000..f1d960970 --- /dev/null +++ b/.changeset/poor-vans-design.md @@ -0,0 +1,5 @@ +--- +"@tanstack/react-db": patch +--- + +Fixed a bug where a race condition could cause initial results not to be rendered when using `useLiveQuery`. diff --git a/packages/react-db/src/useLiveQuery.ts b/packages/react-db/src/useLiveQuery.ts index a345d2de2..f2dcd4a5c 100644 --- a/packages/react-db/src/useLiveQuery.ts +++ b/packages/react-db/src/useLiveQuery.ts @@ -252,6 +252,11 @@ export function useLiveQuery( versionRef.current += 1 onStoreChange() }) + // Collection may be ready and will not receive initial `subscribeChanges()` + if (collectionRef.current!.status === `ready`) { + versionRef.current += 1 + onStoreChange() + } return () => { unsubscribe() }