useLiveQuery({ query }) keeps a cleaned source after same-ID collection instance replacement
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- react, sqlite, typescript
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 3.9k
- Forks
- 268
- Merge medio
- 1 d 2 h
- PR fusionados (30 d)
- 206
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/db
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
Los mantenedores suelen responder en 1 día
-
Reusable queries: standalone descriptor resolution and nested alias composition limitsPosiblemente ocupada @KyleAMathews la tomó hace 1 día. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
electric-db-collection: on-demand + persistence fails after relaunch with "Snapshot requests are not supported in full mode"Posiblemente ocupada @KyleAMathews la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
TanStack/db#2056 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
TanStack/db#1972 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/db
Issues similares
-
[Docs] README: FAQ setup command, IDA in the intro, Node badgePosiblemente ocupada @akram1089 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
morluto/rea#1353 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Feature]: [P3] engine-rs: the package source hash should ignore line endings and untracked filesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
maniator/verticopolis#880 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
siyuan-note/siyuan#20353 ·
Los mantenedores suelen responder en 1 día
-
afk-ok area:data-quality importer size:S
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
enorm-labs/event-junkie#3027 ·
Los mantenedores suelen responder en 1 día