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` ) } 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() }, }, }) 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) + }) })