Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

useLiveQuery({ query }) keeps a cleaned source after same-ID collection instance replacement

Đang mở
#1,991 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react, sqlite, typescript
Lĩnh vực
database, frontend, testing

Hướng nghiên cứu

Start with the useLiveQuery({ query }) migration path and the React test-renderer integration test using two same-ID persisted SQLite collections. Reproduce the replacement and cleanup sequence, then compare it with the explicit primitive queryKey case. Done means the replacement instance is followed without a stale value or cleanup error, or the migration warning/docs and tests clearly require the instance token.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Versions
  • @tanstack/react-db 0.5.1
  • @tanstack/db 0.11.1
  • @tanstack/expo-db-sqlite-persistence 0.2.26
Problem

The recommended migration from useLiveQuery(query, [collection]) to useLiveQuery({ query }) loses collection instance identity. Structured IR identity uses collection.id. When a mounted hook is given a replacement collection with the same ID (for example, a newly initialized collection for the same account), the hook keeps its live query bound to the old instance.

We observed a stale value and, when the old instance is cleaned up, the exact runtime error:

[Live Query Error] Source collection 'wearable.settings.same-user' was manually cleaned up while live query 'live-query-1' depends on it.
Deterministic reproduction
  1. Create two local persisted collections with the same id: 'wearable.settings.same-user', each over its own SQLite database. Put { id: 'settings', automaticSync: false } in the first and { id: 'settings', automaticSync: true } in the second.
  2. Mount a component that calls useLiveQuery({ query: q => q.from({ settings: currentCollection }) }). Initially currentCollection is the first collection; render and confirm false.
  3. Set currentCollection to the second instance and rerender the mounted component without unmounting it.
  4. The hook still returns false. Clean up the first collection and the live-query error above appears.

We have a React test-renderer integration test with real persisted collections and SQLite. It fails this way without an explicit key and passes with queryKey: [instanceToken(currentCollection)], where instanceToken comes from a WeakMap assigning a primitive number per object instance. The old dependency-array form also tracked the instance.

Expected

A structured live query should follow a replaced collection instance even when its ID is reused. At minimum, the migration warning/docs should explain that an explicit primitive instance token is needed for this lifecycle; currently they suggest queryKey mainly for opaque queries or render performance. Passing the collection object directly in queryKey is not possible because stable hashing rejects non-plain objects.

Ngôn ngữ chính
TypeScript
Star
3.9k
Fork
268
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
148

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/db

Tất cả issue của TanStack/db

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.