refetchQueries with throwOnError leaves paused fetch rejection unhandled on client.clear()
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 67/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- backend
调研方向
Start in QueryClient.refetchQueries and trace how query.fetch handles paused queries when throwOnError is true. Use the provided reproduction with @tanstack/query-core and verify the client can be cleared after an awaited offline refetch without an unhandled rejection. The issue does not name a test file, so locate or add coverage for this paused cancellation path.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
With @tanstack/[email protected], refetchQueries with throwOnError: true resolves while a query is paused offline. Clearing the client afterward emits an unhandled CancelledError, even though the caller awaited the returned promise.
Resolving the public refetch promise while offline can be intentional; the unexpected behavior is the later unhandled rejection from the detached fetch promise.
Minimal reproduction
Install @tanstack/[email protected], save this as repro.mjs, and run node repro.mjs:
import { QueryClient, onlineManager } from '@tanstack/query-core';
const errors = [];
process.on('unhandledRejection', (error) => errors.push(error));
const client = new QueryClient();
const queryKey = ['example'];
await client.fetchQuery({ queryKey, queryFn: async () => 'value' });
onlineManager.setOnline(false);
await client.refetchQueries({ queryKey }, { throwOnError: true });
console.log('fetchStatus:', client.getQueryState(queryKey).fetchStatus);
client.clear();
await new Promise((resolve) => setTimeout(resolve, 0));
console.log('unhandled rejections:', errors.map((error) => error.message));
onlineManager.setOnline(true);
Observed on Node.js v26.12.1:
fetchStatus: paused
unhandled rejections: [ 'CancelledError' ]
Expected behavior
Clearing/cancelling a paused refetch should not emit an unhandled rejection when its public promise was awaited. If paused refetches are intentionally detached from the returned aggregate, their later rejection still needs an observer.
Impact and possible cause
Offline cleanup or client replacement can produce an unhandled rejection in otherwise fully awaited code. In QueryClient.refetchQueries, query.fetch(...) is started with throwOnError: true, but the paused branch returns Promise.resolve() instead of retaining or handling that fetch promise. The cancellation is therefore no longer observed by the aggregate.
A consumer can retain the individual fetch promises, but that requires duplicating refetch target selection. Handling the detached promise in the existing paused branch would keep that behavior within the library.
- 主要语言
- TypeScript
- 星标
- 50.5k
- 派生
- 4.2k
- 平均合并
- 5 小时 40 分钟
- 30 天内合并 PR
- 574
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/query 的其他 Issue
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)可能重新可做 @LeonxLJX 于 56 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
TanStack/query#11358 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
[query-core] [performances] `setQueryData` dispatches a `success` event (and triggers broadcast/persist) even when the new data is structurally identical to the cached data可能已有人在做 @praveen-kumary 于 1 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 52/100
维护者通常 1 天内回复
-
useBaseQuery fetches the old query key when an <Activity> tree is revealed可能已有人在做 @lazerg 于 10 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
-
[query-broadcast-client-experimental] broadcastQueryClient: an `added` event overwrites a receiving query that has no data (e.g. in error) with the sender's empty state可能已有人在做 @lazerg 于 10 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 1 天内回复
-
solid-query 6.0.0-rc.5: onCacheEvent throws NotReadyError during a Solid 2 (rc.14+) transition landing可能已有人在做 @UzumakiODZ 于 15 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 28/100
TanStack/query#12031 · 2 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
area:cli bug P4
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
bug from-studio
难度 2/5 1-3 小时 新手友好度 65/100
esengine/DeepSeek-Reasonix#14868 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
linxiv-dev/linXiv#384 · 1 条评论 ·
维护者通常 1 天内回复
-
scope:core type:security
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
mailgun/mailgun.js#544 ·