Skip to content

Commit 40a28b0

Browse files
Danny-Devsclaude
andcommitted
fix(vue-db): force startSync after user spread, guard stale onFirstReady
1. Config-object path: move `startSync: true` after the user spread so it cannot be accidentally overridden to false. `gcTime` stays before the spread so users CAN customize it — this matches React's adapter pattern. 2. onFirstReady callback: capture collection identity at registration time and skip the status update if the collection has changed by the time the callback fires. Prevents stale callbacks from overwriting the current collection's status ref. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9482e0e commit 40a28b0

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

packages/vue-db/src/useLiveQuery.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ export function useLiveQuery(
320320
})
321321
} else {
322322
return createLiveQueryCollection({
323-
startSync: true,
324323
gcTime: DEFAULT_GC_TIME_MS,
325324
...unwrappedParam,
325+
startSync: true,
326326
})
327327
}
328328
})
@@ -398,9 +398,14 @@ export function useLiveQuery(
398398
syncDataFromCollection(currentCollection)
399399

400400
// Listen for the first ready event to catch status transitions
401-
// that might not trigger change events (fixes async status transition bug)
401+
// that might not trigger change events (fixes async status transition bug).
402+
// Guard: if the collection has changed by the time the callback fires,
403+
// skip the update — the new collection's own callback will handle it.
404+
const collectionAtRegistration = currentCollection
402405
currentCollection.onFirstReady(() => {
403-
status.value = currentCollection.status
406+
if (collection.value === collectionAtRegistration) {
407+
status.value = currentCollection.status
408+
}
404409
})
405410

406411
// Subscribe to collection changes with granular updates

0 commit comments

Comments
 (0)