-
Notifications
You must be signed in to change notification settings - Fork 132
fix(react-db): useLiveInfiniteQuery deletion not working with descending order on partial page #970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…query Add tests for deleting items from a page with fewer rows than pageSize in useLiveInfiniteQuery. Tests both ascending and descending order to verify the behavior difference.
🦋 Changeset detectedLatest commit: 7890567 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 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 |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +69 B (+0.08%) Total Size: 87.2 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.35 kB ℹ️ View Unchanged
|
The `biggestObservedValue` variable was incorrectly set to the full row object instead of the indexed value (e.g., salary). This caused the BTree comparison in `index.take()` to fail, resulting in the same data being loaded multiple times. Each item would be inserted with a multiplicity > 1, and when deleted, the multiplicity would decrement but not reach 0, so the item would remain visible in the TopK. This fix creates a value extractor from the orderBy expression and uses it to extract the actual indexed value from each row before tracking it as the "biggest observed value".
KyleAMathews
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Summary
Fixes #872
This PR fixes a bug in
useLiveInfiniteQuerywhere deleting an item from a partial page (fewer items thanpageSize) with descending order would not update the live result.Reproduction of bug: https://stackblitz.com/edit/vitejs-vite-shmvuoh8?file=src%2Fapp.tsx
With the fix: https://stackblitz.com/edit/vitejs-vite-sqrhrspk?file=src%2Fapp.tsx
Root Cause
The bug was in
requestLimitedSnapshotinsubscription.ts. ThebiggestObservedValuevariable was incorrectly set to the full row object instead of the indexed value.This caused the BTree comparison in
index.take()to fail because comparing a row object with indexed values produces NaN, causing the same data to be loaded multiple times.The Fix
Create a value extractor from the orderBy expression to extract the actual indexed value from each row.
Test Failure (Before Fix)
https://github.com/TanStack/db/actions/runs/19940582123/job/57176990721
Test plan