Persisted collections: the sync wrapper's loadSubset is always async, so a live query over a loaded on-demand collection is never synchronously ready
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript
- 領域
- database
調査の方向性
Start in packages/db-sqlite-persistence-core/src/persisted.ts at createWrappedSyncConfig and compare its loadSubset behavior with the LoadSubsetFn contract in packages/db/src/types.ts and CollectionSyncManager.loadSubset in packages/db/src/collection/sync.ts. Reproduce with the node and browser examples, then add focused coverage near packages/db-sqlite-persistence-core/tests/persisted.test.ts; done means an already-loaded persisted subset returns synchronously and the Suspense case reaches ready.
索引モデルが issue の本文から書いたものです。
説明
- I've validated the bug against the latest version of DB packages (
@tanstack/[email protected],@tanstack/[email protected],@tanstack/[email protected])
Describe the bug
createWrappedSyncConfig in db-sqlite-persistence-core returns its loadSubset as an async function, so it is always a Promise — even when everything it awaits is already settled and the wrapped sync answered with a synchronous true.
That matters because LoadSubsetFn is declared as a sometimes-synchronous contract in packages/db/src/types.ts:
export type LoadSubsetFn = (options: LoadSubsetOptions) => true | Promise<void>
and CollectionSyncManager.loadSubset branches on it (packages/db/src/collection/sync.ts:853):
if (result instanceof Promise) { this.trackLoadPromise(result); ... }
return true
An async implementation can never reach the true branch. So for any persisted collection, a live query over an already-loaded subset is never synchronously ready.
Under useLiveSuspenseQuery that is fatal rather than merely slow: a component that suspends before it mounts loses its refs, so each retry constructs a fresh live query, which is loading, which throws a fresh promise, which resolves, which retries. The boundary never releases.
To Reproduce
Full runnable repro (node + real-browser): https://gist.github.com/MAST1999/62526dceb542323d009d036e3bb8ed7e
npm install
npm run node # the cause — no React, no browser
npm run browser # the symptom — real Chromium via @vitest/browser
There is no SQLite in the repro. It uses an in-memory PersistenceAdapter of the same shape as this repo's own createRecordingAdapter in packages/db-sqlite-persistence-core/tests/persisted.test.ts, because the defect is in the sync wrapper that persistedCollectionOptions puts in front of any adapter. The only difference between the two cases is whether the options went through persistedCollectionOptions.
The mock sync returns a bare true from loadSubset for a subset it has already loaded, which is exactly what the declared contract is for:
loadSubset: (options) => {
const key = JSON.stringify(options.where ?? null)
if (loaded.has(key)) return true // already here — nothing to await
loaded.add(key)
begin(); for (const row of ROWS) write({ type: `insert`, value: row }); commit()
return true
}
node-repro.mjs:
no persistence : ready (2 rows loaded)
persisted : loading (2 rows loaded)
suspense.test.jsx, in Chromium:
✓ an unpersisted on-demand collection settles under Suspense 54ms
× the same collection with persistence never leaves its fallback
→ the boundary never released; the component re-suspended 13778 times
Expected behavior
A persisted on-demand collection should honour the same true | Promise<void> contract as an unpersisted one: when the wrapped sync answers true and there is nothing left to await, the wrapper should return true too, and the live query should be ready at construction.
Cause
packages/db-sqlite-persistence-core/src/persisted.ts, createWrappedSyncConfig (line 2654 on main @ dffb17f):
loadSubset: async (options: LoadSubsetOptions) => {
const acquisition = { forwarded: false }
acquisitions.set(options, acquisition)
await fullStartPromise
const resolvedSourceResult = await sourceResultPromise
...
return runtime.loadSubset(options, (loadOptions) => { ... })
}
Note also that runtime.loadSubset (line 1043) re-runs hydrateSubsetUnsafe against the store on every call, including a repeat call for a subset already in activeSubsets — so the redundant work is real, not just the lost true.
async syntax structurally cannot express T | Promise<T> (microsoft/TypeScript#33595), so conforming to LoadSubsetFn requires hand-writing the branch.
Prior art in this repo
@tanstack/electric-db-collection writes its raw fetcher as async too, but does not hand it back directly — it wraps it (packages/electric-db-collection/src/electric.ts:860):
return new DeduplicatedLoadSubset({ loadSubset })
and DeduplicatedLoadSubset.loadSubset returns the literal true for an already-completed demand key. grep -rn "DeduplicatedLoadSubset" packages/db-sqlite-persistence-core/src/ returns nothing — the persistence package skips that layer entirely.
Additional context
This is distinct from #1855 (orderBy + limit chaining subset requests), though the two share a symptom. This one needs no orderBy and no limit — just persistence.
Happy to open a PR.
- 主要言語
- TypeScript
- スター
- 3.9k
- フォーク
- 268
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 212
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/db のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
electric-db-collection: on-demand + persistence fails after relaunch with "Snapshot requests are not supported in full mode"対応中かも @KyleAMathews が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
TanStack/db#2056 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
[Bug] The clients language filter cannot select the rows the page labels as unknown対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
apache/rocketmq-dashboard#6103 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
cockpit-project/cockpit-machines#2835 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cloudflare/kumo#866 ·
メンテナーはふだん 1 日以内に返信
-
area:connector bug
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
autoInject recall silently drops memory injection on long / non-Latin prompts (HTTP 400 Query too long)対応中かも @Epsilon006 が今日担当しました。 オープンintegration:coding-agents
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
vectorize-io/hindsight#5476 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信