useLiveQuery({ query }) keeps a cleaned source after same-ID collection instance replacement
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-db0.5.1@tanstack/db0.11.1@tanstack/expo-db-sqlite-persistence0.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
- 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. - Mount a component that calls
useLiveQuery({ query: q => q.from({ settings: currentCollection }) }). InitiallycurrentCollectionis the first collection; render and confirmfalse. - Set
currentCollectionto the second instance and rerender the mounted component without unmounting it. - 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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/db
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
TanStack/db#1992 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
TanStack/db#1972 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
prime-radiant-inc/evener#3726 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
FuRongJun-1999/dsh-memory#56 ·
I maintainer di solito rispondono entro 1 giorno
-
bug via-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
pingdotgg/t3code#15682 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
openwatersio/slackwater.xyz#152 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] 请修改标题为您遇到的问题Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
OpenListTeam/OpenList-Worker#103 ·
I maintainer di solito rispondono entro 1 giorno