Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Cerrado
#1,991 1 comentario 0 reacciones 0 asignados Ver en GitHub

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-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.

Lenguaje dominante
TypeScript
Estrellas
3.9k
Forks
268
Merge medio
1 d 2 h
PR fusionados (30 d)
206

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/db

Todos los issues de TanStack/db

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.