A live query whose first on-demand subset load failed stays in error after a later load succeeds
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 54/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
Start with the named failure handling in db/src/query/live/collection-subscriber.ts and collection-config-builder.ts, then trace how a successful source refetch updates live query state. The issue includes a Vitest reproduction; run it to confirm the failure, then verify that after the retry succeeds the live query leaves error and exposes both rows.
由索引模型根据 Issue 内容生成。
描述
- I've validated the bug against the latest version of DB packages
Describe the bug
If a live query's first subset load fails, the live query is put into a fatal error state. A later successful load of the same subset (e.g. collection.utils.refetch(), or an invalidation) fetches the rows into the source collection, but the live query stays error with no rows. The only way back is to recreate the live query.
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:
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 live query whose first load failed shows the rows once a later load of that subset succeeds", async () => {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 60_000 } } });
let failing = true;
const reads = [];
const collection = createCollection(queryCollectionOptions({
id: "gap-2",
queryClient,
queryKey: ["gap-2"],
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 (failing) return Promise.reject(new Error("read failed"));
return Promise.resolve([{ key: seq + "-1", seq }, { key: seq + "-2", seq }]);
},
}));
const live = createLiveQueryCollection((q) => q.from({ r: collection }).where(({ r }) => eq(r.seq, "a")));
await expect(live.preload()).rejects.toThrow("read failed");
await settle();
expect(reads).toEqual(["a"]);
failing = false;
await collection.utils.refetch();
await settle();
expect(reads).toEqual(["a", "a"]);
expect(live.toArray.map((row) => row.seq)).toEqual(["a", "a"]);
});
Result: the second read succeeds (reads is ["a", "a"], the source query is success), but live.toArray is [] and live.status is "error".
Expected behavior
Once a later load of the subset succeeds, the live query leaves the error state and shows the rows, the way a query observer recovers after a successful refetch. (Whether recovery should be automatic or an explicit clearError/retry is your call; today neither path recovers the live query.)
Additional context
- The first-load failure is classified fatal (
db/src/query/live/collection-subscriber.ts:108-116while status isloading), goes throughcollection-config-builder.ts:482-499totransitionToError(:1218-1234), andfatalQueryError/isInErrorStateare only cleared on a new sync run (:748-751), not by a successful source fetch. - Related: the "transitioning out of error state needs more thought" review on #671, #672, #1260.
- Why it matters: Retry after a failed first load does nothing for the user unless the app tears the live query down and rebuilds it; we currently do that by resubscribing.
- Happy to send a PR (with oracle coverage) if you'd like to assign it; equally fine if you'd rather handle it yourselves. The test is free to adopt.
The repro was written with an AI coding assistant and checked by hand against the installed sources.
- 主要语言
- TypeScript
- 星标
- 4k
- 派生
- 277
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 170
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/db 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
OfflineExecutor.dispose() never settles pendingTransactionPromises可能重新可做 @Claire-ovo 于 7 天前认领,目前没有进行中的 PR。 未关闭
难度 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 一周以上 新手友好度 12/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
ready-for-agent
难度 2/5 1-3 小时 新手友好度 72/100
LucasSantana-Dev/Lucky#2951 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
danielmiessler/LifeOS#2567 ·
维护者通常 9 天内回复
-
refactor(react-pi): classify base64 images with core's parseBase64可能已有人在做 @jimmyallinai 今天认领。 未关闭maintenance
难度 2/5 1-3 小时 新手友好度 62/100
assistant-ui/assistant-ui#10293 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
brijeshb42/monaco-vim#175 ·