diff --git a/.changeset/five-turtles-yell.md b/.changeset/five-turtles-yell.md new file mode 100644 index 000000000..cc8101a05 --- /dev/null +++ b/.changeset/five-turtles-yell.md @@ -0,0 +1,5 @@ +--- +'@tanstack/powersync-db-collection': patch +--- + +Added checks to not flush records when a `diffTrigger` isn't setup yet for `on-demand` mode. This fixes a non-critical error that was logged on startup. diff --git a/packages/powersync-db-collection/src/powersync.ts b/packages/powersync-db-collection/src/powersync.ts index c11c1d269..b3564c403 100644 --- a/packages/powersync-db-collection/src/powersync.ts +++ b/packages/powersync-db-collection/src/powersync.ts @@ -529,11 +529,14 @@ export function powerSyncCollectionOptions< onUnloadSubset = await restConfig.onLoadSubset?.(options) } + // Nothing to flush or dispose if no tracking table has been created yet. if (activeWhereExpressions.length === 0) { - await database.writeLock(async (ctx) => { - await flushDiffRecordsWithContext(ctx) - await disposeTracking?.({ context: ctx }) - }) + if (disposeTracking) { + await database.writeLock(async (ctx) => { + await flushDiffRecordsWithContext(ctx) + await disposeTracking?.({ context: ctx }) + }) + } return } @@ -563,8 +566,12 @@ export function powerSyncCollectionOptions< const viewWhereClause = toInlinedWhereClause(compiledView) await database.writeLock(async (ctx) => { - await flushDiffRecordsWithContext(ctx) - await disposeTracking?.({ context: ctx }) + // On the first loadSubset there is no tracking table yet, so there + // is nothing to flush or dispose. + if (disposeTracking) { + await flushDiffRecordsWithContext(ctx) + await disposeTracking({ context: ctx }) + } disposeTracking = await createDiffTrigger({ setupContext: ctx,