From ec3efc644c0d3afe7209b4be9e3abcb6e9a60f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=BChl?= Date: Wed, 6 Aug 2025 18:55:43 +0200 Subject: [PATCH 1/3] test: add unit test to ensure markReady is not called when source collection sync does not trigger it --- .../tests/query/live-query-collection.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/db/tests/query/live-query-collection.test.ts b/packages/db/tests/query/live-query-collection.test.ts index 0ebcf4d4..8b469f17 100644 --- a/packages/db/tests/query/live-query-collection.test.ts +++ b/packages/db/tests/query/live-query-collection.test.ts @@ -170,4 +170,23 @@ describe(`createLiveQueryCollection`, () => { expect(liveQuery.status).toBe(`ready`) expect(liveQuery.size).toBe(0) }) + + it(`shouldn't call markReady when source collection sync doesn't call markReady`, async () => { + const collection = createCollection<{ id: string }>({ + sync: { + sync({ begin, commit }) { + begin() + commit() + }, + }, + getKey: (item) => item.id, + startSync: true, + }) + + const liveQuery = createLiveQueryCollection({ + query: (q) => q.from({ collection }), + startSync: true, + }) + expect(liveQuery.isReady()).toBe(false) + }) }) From 7f7a81cb7f51dd8b4bb5ebee5a37d83646e76b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=BChl?= Date: Wed, 6 Aug 2025 18:56:26 +0200 Subject: [PATCH 2/3] fix(db): simplify allCollectionsReady check to only require 'ready' status --- packages/db/src/query/live-query-collection.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/db/src/query/live-query-collection.ts b/packages/db/src/query/live-query-collection.ts index 9d7877f5..d823d88a 100644 --- a/packages/db/src/query/live-query-collection.ts +++ b/packages/db/src/query/live-query-collection.ts @@ -164,8 +164,7 @@ export function liveQueryCollectionOptions< const allCollectionsReady = () => { return Object.values(collections).every( - (collection) => - collection.status === `ready` || collection.status === `initialCommit` + (collection) => collection.status === `ready` ) } From f1b24c23712cce118ad2588399b4403b0db897bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=BChl?= Date: Wed, 6 Aug 2025 18:59:36 +0200 Subject: [PATCH 3/3] test(db): add markReady calls --- packages/db/tests/query/indexes.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/db/tests/query/indexes.test.ts b/packages/db/tests/query/indexes.test.ts index 5dfad097..06dab016 100644 --- a/packages/db/tests/query/indexes.test.ts +++ b/packages/db/tests/query/indexes.test.ts @@ -237,7 +237,7 @@ describe(`Query Index Optimization`, () => { getKey: (item) => item.id, startSync: true, sync: { - sync: ({ begin, write, commit }) => { + sync: ({ begin, write, commit, markReady }) => { // Provide initial data through sync begin() for (const item of testData) { @@ -247,6 +247,7 @@ describe(`Query Index Optimization`, () => { }) } commit() + markReady() // Listen for mutations and sync them back (only register once) if (!emitter.all.has(`sync`)) { @@ -534,7 +535,7 @@ describe(`Query Index Optimization`, () => { getKey: (item) => item.id, startSync: true, sync: { - sync: ({ begin, write, commit }) => { + sync: ({ begin, write, commit, markReady }) => { begin() write({ type: `insert`, @@ -547,6 +548,7 @@ describe(`Query Index Optimization`, () => { }, }) commit() + markReady() }, }, }) @@ -622,7 +624,7 @@ describe(`Query Index Optimization`, () => { getKey: (item) => item.id, startSync: true, sync: { - sync: ({ begin, write, commit }) => { + sync: ({ begin, write, commit, markReady }) => { begin() write({ type: `insert`, @@ -645,6 +647,7 @@ describe(`Query Index Optimization`, () => { }, }) commit() + markReady() }, }, })