Patch Changes
-
Enhanced LoadSubsetOptions with separate cursor expressions and offset for flexible pagination. (#960)
⚠️ Breaking Change for Custom Sync Layers / Query Collections:
LoadSubsetOptions.whereno longer includes cursor expressions for pagination. If you have a custom sync layer or query collection that implementsloadSubset, you must now handle pagination separately:- Cursor-based pagination: Use the new
cursorproperty (cursor.whereFromandcursor.whereCurrent) and combine them withwhereyourself - Offset-based pagination: Use the new
offsetproperty
Previously, cursor expressions were baked into the
whereclause. Now they are passed separately so sync layers can choose their preferred pagination strategy.Changes:
- Added
CursorExpressionstype withwhereFrom,whereCurrent, and optionallastKeyproperties - Added
cursortoLoadSubsetOptionsfor cursor-based pagination (separate fromwhere) - Added
offsettoLoadSubsetOptionsfor offset-based pagination support - Electric sync layer now makes two parallel
requestSnapshotcalls when cursor is present:- One for
whereCurrent(all ties at boundary, no limit) - One for
whereFrom(rows after cursor, with limit)
- One for
- Query collection serialization now includes
offsetfor query key generation - Added
truncateevent to collections, emitted when synced data is truncated (e.g., aftermust-refetch) - Fixed
setWindowpagination: cursor expressions are now correctly built when paging through results - Fixed offset tracking:
loadNextItemsnow passes the correct window offset to prevent incorrect deduplication CollectionSubscribernow listens fortruncateevents to reset cursor tracking state
Benefits:
- Sync layers can choose between cursor-based or offset-based pagination strategies
- Electric can efficiently handle tie-breaking with two targeted requests
- Better separation of concerns between filtering (
where) and pagination (cursor/offset) setWindowcorrectly triggers backend loading for subsequent pages in multi-column orderBy queries- Cursor state is properly reset after truncation, preventing stale cursor data from being used
- Cursor-based pagination: Use the new
-
Updated dependencies [
b3b1940,09da081,86ad40c]:- @tanstack/db@0.5.12