Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#1,991 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
react, sqlite, typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
3.9k
フォーク
268
平均マージ
1日 3時間
マージ済み PR(30日)
148

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/db のほかの issue

TanStack/db の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。