Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#1,991 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
react, sqlite, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
3.9k
Fork
268
Merge medio
1g 3h
PR unite (30g)
148

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/db

Tutte le issue di TanStack/db

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.