-
Notifications
You must be signed in to change notification settings - Fork 131
feat(db,electric,query): separate cursor expressions for flexible pagination #960
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
Open
samwillis
wants to merge
3
commits into
main
Choose a base branch
from
samwillis/cursor-pagination
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+767
−129
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: cc8fccb 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: |
Contributor
|
Size Change: +231 B (+0.26%) Total Size: 88.4 kB
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.35 kB ℹ️ View Unchanged
|
Closed
6d0a91a to
f1a6d36
Compare
kevin-dp
approved these changes
Dec 4, 2025
7f03f25 to
e5dc9f7
Compare
…e in loadSubset - Add CursorExpressions type with whereFrom, whereCurrent, and lastKey - LoadSubsetOptions.where no longer includes cursor - passed separately via cursor property - Add offset to LoadSubsetOptions for offset-based pagination support - Electric sync layer makes two parallel requestSnapshot calls when cursor present - Query collection serialization includes offset for query key generation This allows sync layers to choose between cursor-based or offset-based pagination, and Electric can efficiently handle tie-breaking with targeted requests. test(react-db): update useLiveInfiniteQuery test mock to handle cursor expressions The test mock's loadSubset handler now handles the new cursor property in LoadSubsetOptions by combining whereCurrent (ties) and whereFrom (next page) data, deduplicating by id, and re-sorting. fix(electric): make cursor requestSnapshot calls sequential Changed parallel requestSnapshot calls to sequential to avoid potential issues with concurrent snapshot requests that may cause timeouts in CI. fix(electric): combine cursor expressions into single requestSnapshot Instead of making two separate requestSnapshot calls (one for whereFrom, one for whereCurrent), combine them using OR into a single request. This avoids potential issues with multiple sequential snapshot requests that were causing timeouts in CI. The combined expression (whereFrom OR whereCurrent) matches the original behavior where cursor was combined with the where clause. wip working? update changeset fix query test
ff54e90 to
091f214
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances
LoadSubsetOptionswith separate cursor expressions and offset support, allowing sync layers to choose between cursor-based or offset-based pagination strategies.API Changes:
CursorExpressionstype withwhereFrom,whereCurrent, and optionallastKeypropertiesLoadSubsetOptions.whereno longer includes cursor expressions - these are now passed separately viacursoroffsettoLoadSubsetOptionsfor offset-based pagination supportrequestSnapshotcalls when cursor is present:whereCurrent(all ties at boundary, no limit)whereFrom(rows after cursor, with limit)offsetfor query key generationtruncateevent to collections, emitted when synced data is truncated (e.g., aftermust-refetch)Bug Fixes:
setWindowpagination: cursor expressions are now correctly built when paging through multi-column orderBy resultsloadNextItemsnow passes the correct window offset to prevent incorrect deduplicationCollectionSubscribernow listens fortruncateevents to reset cursor tracking state, preventing stale cursor data aftermust-refetchBenefits
where) and pagination (cursor/offset)setWindowcorrectly triggers backend loading for subsequent pages in multi-column orderBy queriesStacked PR
This PR is stacked on #926 (
samwillis/order-by-improvments)Test plan
setWindow