electric-db-collection: on-demand + persistence fails after relaunch with "Snapshot requests are not supported in full mode"
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/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ệ
- react-native, sqlite, typescript
- Lĩnh vực
- database
Hướng nghiên cứu
Start with loadSubset in dist/esm/electric.js around line 248, then trace how needsFullSnapshot selects full mode around line 828. Ask the reporter to share their two-launch node:test reproduction, which exercises electricCollectionOptions, persistedCollectionOptions, and createExpoSQLitePersistence. Done means a relaunch with tagged rows no longer requests a snapshot in full mode and the collection becomes ready.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In short
An on-demand Electric collection with persistence works on the first app launch, but breaks on every launch after that. The second launch fails with:
Snapshot requests are not supported in full mode
After that error the collection stays in loading, and every live query on it fails until the local data is deleted.
It happens when the shape's rows have tags, which is the case when the shape's where has a subquery.
Versions
@tanstack/electric-db-collection0.5.4. The same code is in 0.5.5 and onmain.@electric-sql/client(the version 0.5.4 depends on)- Persistence:
persistedCollectionOptions+createExpoSQLitePersistence(React Native / Expo)
Setup
electricCollectionOptions({
syncMode: "on-demand",
shapeOptions: {
// the proxy adds a where with a subquery, for example:
// room_id IN (SELECT ... FROM permission_cache WHERE ...)
},
// ...
})
wrapped in persistedCollectionOptions(...).
Steps
- Launch the app. A live query loads a subset. Rows arrive with tags. The library saves a resume state with
requiresTagState: true. - Close the app, then open it again (a new JS process).
What goes wrong, step by step
Line numbers are from dist/esm/electric.js in 0.5.4.
- On the new launch, the tag state from the first launch is gone (it was in memory), so
retainsTagStateisfalse. The saved resume state saysrequiresTagState: true, soneedsFullSnapshotbecomestrue(~line 828). - Because of that, the stream is created in full mode:
logis not'changes_only', and the offset is-1(~line 872). - The live query then calls
loadSubset, andloadSubsetstill callsstream.requestSnapshot(...)(~line 248). - The Electric client does not allow snapshots in full mode, so it throws
Snapshot requests are not supported in full mode. - The throw comes before the stream starts, so the stream never starts and the collection never becomes ready.
So the library chooses full mode, then asks for something that full mode refuses.
Expected
When the stream is in full mode, loadSubset should not request a snapshot. It should wait until the full sync is ready, because the full log will contain the rows anyway.
Our workaround
We ship a small patch (about 35 lines) in loadSubset. When syncMode === 'on-demand' && needsFullSnapshot, it does not call requestSnapshot. It waits for the first markReady instead (it rejects if the initial sync calls markError, and resolves if the collection is aborted).
With the patch, the second launch works. One cost is left: every launch downloads the full shape again, because the tag state is not saved. Saving the tag state with the resume state may be the better fix. You know the design better than we do.
We are glad to open a PR with the patch, or share our test.
Test
We have a node:test test with two "launches". It uses the real electricCollectionOptions + persistedCollectionOptions + createExpoSQLitePersistence over node:sqlite, and a small fake Electric server that tags rows. It fails on 0.5.4 and passes with the patch. We can post it here.
Related
#811 has the same error text, in progressive mode.
- Ngôn ngữ chính
- TypeScript
- Star
- 3.9k
- Fork
- 268
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 206
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
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Reusable queries: standalone descriptor resolution and nested alias composition limitsCó thể đã có người làm @KyleAMathews đã nhận 2 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/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 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
TanStack/db#1972 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
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 75/100
lingdojo/kana-dojo#32018 · 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 72/100
paperclipai/paperclip#15751 ·
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 72/100
BuilderIO/agent-native#7275 ·
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 74/100
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 65/100
Maintainer thường phản hồi trong vòng 1 ngày