Source collection emptied when an ordered window that fell back to a full-source read is replaced by one reading the same subset
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- database
Hướng nghiên cứu
Start with repro.test.ts in the linked reproduction to see the failing subscribe and release sequence, then trace ordered-window fallback and source collection cleanup in the TanStack DB code. Reproduce with npm test; done means switching between overlapping full-source fallback windows keeps the 50-row window populated and the shared source rows intact, regardless of subscribe and release order.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- I've validated the bug against the latest version of DB packages
Describe the bug
One syncMode: "on-demand" query collection, one ordered, limited live query:
q.from({ r: source })
.where(({ r }) => not(eq(r.status, 4)))
.orderBy(({ r }) => r.date, { direction, nulls, stringSort: "lexical" })
.orderBy(({ r }) => r.id, direction)
.limit(50)
When the sort direction changes, the new live query is subscribed, then the old one is released (what a UI binding does when a reactive sort changes). If both windows fell back to a full-source read of the same filter, releasing the old window removes every row from the source collection. The new window stays at 0 rows and never recovers, nor does any other view on that collection.
Two triggers of the documented full-source fallback reproduce it:
- the first page ends on a NULL sort value (
DESC NULLS FIRSTon a nullable column); stringSort: "locale", without any NULL.
Indexes matching the query's compareOptions (no dev warning) don't change the result.
Requests seen by queryFn in the failing case:
DESC limit=50 -> 50 rows
DESC limit=none -> 240 rows (full-source fallback, where: status != 4)
ASC limit=50 -> 50 rows
ASC limit=none -> 240 rows (same subset as above)
-- old DESC window released --
source.size === 0, asc.size === 0
Controls that work:
- No NULL dates: the DESC window only requests its boundary tie (
date = …), so the ASC full read is a different subset. The source keeps 240 rows. - Same NULL data, but the old window is released before the new one subscribes: the source keeps its rows and the ASC window shows 50.
- Two unordered live queries with the same
where, overlapping the same way, keep their rows. So it seems specific to subsets acquired by the ordered loader's full-source fallback.
To Reproduce
Repo: https://github.com/1bod/tanstack-db-ordered-window-empties-source
StackBlitz: https://stackblitz.com/github/1bod/tanstack-db-ordered-window-empties-source
npm installnpm test- See the 2 control tests pass and the 3
BUGtests fail withexpected +0 to be 50(window) andexpected 0 to be greater than 0(source collection size).
repro.test.ts only uses @tanstack/db, @tanstack/query-db-collection and @tanstack/query-core, with a fake backend that honours where (including cursor predicates), orderBy with NULLS FIRST/LAST, offset and limit.
Expected behavior
After the switch, the ASC window shows its 50 rows and the source collection keeps the rows the new window holds, whatever the order of subscribe and release.
Screenshots
N/A
Desktop (please complete the following information):
- OS: Linux
- Browser: N/A (Node 26.13, vitest 4.1.12). First seen in a browser with
@tanstack/vue-db(useLiveQuery/useLiveInfiniteQuery) when toggling the sort of a list sorted by a nullable date. - Version:
@tanstack/db1.0.0-rc.1.3,@tanstack/query-db-collection1.5.1,@tanstack/query-core5.105.3
Smartphone (please complete the following information):
N/A
Additional context
Workaround: split the query into an isNull(date) window and a not(isNull(date)) window with stringSort: "lexical", so no page ends on NULL and the fallback never runs.
Possibly related: #2160 (rows lost across reentrant final-owner cleanup), #2352 (identical subset reuse), #2268 (full-source fallback on NULL page ends).
- Ngôn ngữ chính
- TypeScript
- Star
- 4k
- Fork
- 277
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 162
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/db
-
`Collection.currentStateAsChanges` JSDoc examples don’t match `CurrentStateAsChangesOptions`Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
OfflineExecutor.dispose() never settles pendingTransactionPromisesCó thể làm lại được @Claire-ovo đã nhận 10 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TanStack/db#2254 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Two @tanstack/db tests time out under CPU load because a cold module import counts against the 5 s default timeoutCó thể đã có người làm @jp-knj đã nhận 8 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
appandflow/stim#5258 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/docs framework/hugo help wanted language/markdown
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
lingdojo/kana-dojo#33660 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
drizzle-team/drizzle-orm#6639 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100