query-db-collection: a later refetch failure of one on-demand subset never reaches that subset's live query
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- database
調査の方向性
Start with the supplied Vitest reproduction and trace how query-db-collection records refetch failures around query.ts:3265-3280. Then follow how loadSubset:error reaches lastSubsetError in collection-subscriber.ts:108-116, and inspect the related work in #1764. Done when the owning live query exposes a failed refresh, retains its rows, and other subsets remain unaffected.
索引モデルが issue の本文から書いたものです。
説明
- I've validated the bug against the latest version of DB packages
Describe the bug
With syncMode: "on-demand", once a subset has loaded, a later refetch of that subset that fails (e.g. after queryClient.invalidateQueries) is recorded only collection-wide (collection.utils.lastError). The live query that owns the subset stays ready, its utils.lastSubsetError stays undefined, and nothing tells it the data on screen could not be refreshed.
#1764 (fixed by #1756 / #1797) scoped failures of a subset's first load to the requesting subscription. This is the same expectation for a later load of a subset that already succeeded once.
Tested with @tanstack/db 0.15.2, @tanstack/query-db-collection 1.4.8, @tanstack/query-core 5.104.5 (no related commits on main since 0.15.2).
To Reproduce
Drop-in vitest test (no framework adapter):
import { expect, test } from "vitest";
import { createCollection, createLiveQueryCollection, eq } from "@tanstack/db";
import { QueryClient } from "@tanstack/query-core";
import { parseLoadSubsetOptions, queryCollectionOptions } from "@tanstack/query-db-collection";
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
const settle = async () => {
for (let i = 0; i < 30; i++) await tick();
};
test("a later refetch failure is visible on the failed subset's live query, not just collection-wide", async () => {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 60_000 } } });
let failing = null;
const reads = [];
const collection = createCollection(queryCollectionOptions({
id: "gap-1",
queryClient,
queryKey: ["gap-1"],
syncMode: "on-demand",
getKey: (row) => row.key,
queryFn: (ctx) => {
const { filters } = parseLoadSubsetOptions(ctx.meta?.loadSubsetOptions);
const seq = filters.find((filter) => filter.field.join(".") === "seq")?.value;
reads.push(seq);
if (seq === failing) return Promise.reject(new Error("read failed"));
return Promise.resolve([{ key: seq + "-1", seq }, { key: seq + "-2", seq }]);
},
}));
const live = (seq) => createLiveQueryCollection((q) => q.from({ r: collection }).where(({ r }) => eq(r.seq, seq)));
const a = live("a");
const b = live("b");
await Promise.all([a.preload(), b.preload()]);
expect(a.toArray.map((row) => row.seq)).toEqual(["a", "a"]);
failing = "a";
await queryClient.invalidateQueries({ queryKey: ["gap-1"] });
await settle();
expect(reads.filter((seq) => seq === "a")).toHaveLength(2);
expect(a.toArray.map((row) => row.seq)).toEqual(["a", "a"]);
expect(collection.utils.lastError).toBeInstanceOf(Error);
expect(a.status === "error" || a.utils.lastSubsetError instanceof Error).toBe(true);
expect(b.status).toBe("ready");
expect(b.utils.lastSubsetError).toBeUndefined();
});
Result: the last two a assertions fail; collection.utils.lastError is set.
Expected behavior
The failed subset's live query exposes the refetch failure (error status, or at least utils.lastSubsetError), while its rows stay (a failed refresh should not empty the view) and other subsets' live queries are unaffected.
Additional context
- The error is recorded collection-wide at
query-db-collection/src/query.ts:3265-3266, and marks the collection only while it is loading (:3278-3280).lastSubsetErroris fed only byloadSubset:error(db/src/query/live/collection-subscriber.ts:108-116), which an observer refetch failure never emits. - Related: #672 (first-class error tracking), #1764.
- Why it matters: an app showing paged server data (ratings, history) cannot tell a member "couldn't refresh, retry" for one view. We currently read the query cache directly to find a failed subset's error.
- Happy to send a PR (with the oracle coverage CONTRIBUTING asks for) if you'd like to assign it; equally fine if you'd rather fix it in your own flow. The test above is free to adopt as-is.
The repro was written with an AI coding assistant and checked by hand against the installed sources.
- 主要言語
- TypeScript
- スター
- 4k
- フォーク
- 277
- 平均マージ
- 1日 7時間
- マージ済み PR(30日)
- 170
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/db のほかの issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
OfflineExecutor.dispose() never settles pendingTransactionPromises再び着手できるかも @Claire-ovo が 7 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Two @tanstack/db tests time out under CPU load because a cold module import counts against the 5 s default timeout対応中かも @jp-knj が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 12/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
Remove unused dependencies対応中かも @alastair-smith が今日担当しました。 オープンchore other
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
alastair-smith/card-games#384 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
code-yeongyu/senpi#5571 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nexu-io/open-design#9262 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
friction
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
kentcdodds/kody#4753 ·
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
lingdojo/kana-dojo#33508 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信