A live query whose first on-demand subset load failed stays in error after a later load succeeds
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 54/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- typescript
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
- 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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 4k
- Forks
- 277
- Ø Merge
- 1 T. 7 Std.
- Gemergte PRs (30 T.)
- 172
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/db
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
OfflineExecutor.dispose() never settles pendingTransactionPromisesEvtl. wieder frei @Claire-ovo hat das vor 7 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
TanStack/db#2254 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Two @tanstack/db tests time out under CPU load because a cold module import counts against the 5 s default timeoutEvtl. vergeben @jp-knj hat das vor 5 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
setWindow publishes the new page before its include demand settles (on-demand materialize / toArray)Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Remove unused dependenciesEvtl. vergeben @alastair-smith hat das heute übernommen. Offenchore other
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
alastair-smith/card-games#384 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
code-yeongyu/senpi#5571 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
nexu-io/open-design#9262 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
friction
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
kentcdodds/kody#4753 ·
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 62/100
lingdojo/kana-dojo#33508 · 1 Kommentar · 5 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag