-
Notifications
You must be signed in to change notification settings - Fork 132
Open
Description
- I've validated the bug against the latest version of DB packages
Describe the bug
When using syncMode: "on-demand" with a query collection, calling:
liveQuery.preload()liveQuery.stateWhenReady()
returns immediately with 0 items, even though the fetch has been triggered.
The stateWhenReady() promise resolves before the data actually arrives.
To Reproduce
- Create a query collection with
syncMode: "on-demand" - Create a live query collection from it
- Call
await liveQuery.preload() - Call
await liveQuery.stateWhenReady() - Check
state.size— it's 0 even thoughqueryFnwas called
Minimal reproduction:
const postsCollection = createCollection(
queryCollectionOptions({
queryKey: ["posts"],
queryFn: async () => {
const res = await fetch("https://jsonplaceholder.typicode.com/posts");
return res.json();
},
syncMode: "on-demand",
queryClient,
getKey: (item) => item.id,
})
);
const posts = createLiveQueryCollection({
query: (q) =>
q
.from({ post: postsCollection })
.where(({ post }) => eq(post.userId, 1))
.orderBy(({ post }) => post.id, "asc")
.limit(10),
});
await posts.preload();
const state = await posts.stateWhenReady();
console.log(state.size); // ❌ 0 (expected: 10)
await sleep(2000);
const state2 = await posts.stateWhenReady();
console.log(state2.size); // ✅ 10 (data arrived after waiting)Metadata
Metadata
Assignees
Labels
No labels