fix(db): prevent cross-query data contamination in useLiveInfiniteQuery#1214
fix(db): prevent cross-query data contamination in useLiveInfiniteQuery#1214melvinhagberg wants to merge 1 commit intoTanStack:mainfrom
Conversation
When using useLiveInfiniteQuery with syncMode: 'on-demand', navigating between different queries on the same collection causes the wrong data to appear on the first page. This happens because a new subscription's first snapshot reads from the local index, which may contain data loaded by a different subscription's loadSubset call. The fix tracks whether loadSubset has been called on a collection. When a new subscription's first snapshot runs: - If loadSubset has never been called, local data is from initial sync (valid for all queries) - If loadSubset has been called, local data may be contaminated, so we skip local reads and let loadSubset provide the correct data
🦋 Changeset detectedLatest commit: c2b7c80 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hey @melvinhagberg Just to check the intention of this fix. Am I correct that what you were experiencing was that the page would briefly show valid data for the query, but data that would not be the first page, and appear incorrect? So for example, after changing the orderBy, it would show the data that had already loaded (as its in the on-demand collection) until the "true" first page had loaded from the server? I'm a little hesitant of the coarseness of this change (it's scoped to the source collection, and flicks on after the first loadSubset), and that it defaults to enabled. I think we have a few options:
|
When using useLiveInfiniteQuery with syncMode: 'on-demand', navigating between different queries on the same collection causes the wrong data to appear on the first page.
This happens because a new subscription's first snapshot reads from the local index, which may contain data loaded by a different subscription's loadSubset call.
The fix tracks whether loadSubset has been called on a collection. When a new subscription's first snapshot runs:
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact