Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

refetchQueries with throwOnError leaves paused fetch rejection unhandled on client.clear()

未关闭
#12,441 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@lazerg 已经在做这个了。

开始于 2026年10月28日。

  • #12442 来自 @lazerg —— 未关闭

评估

难度
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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/query 的其他 Issue

查看 TanStack/query 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。