Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#12,441 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@lazerg đang làm issue này rồi.

Từ ngày 28/10/2026.

  • #12442 của @lazerg — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
67/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
50.5k
Fork
4.2k
Merge trung bình
5 giờ 40 phút
Pull request đã merge (30 ngày)
574

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/query

Tất cả issue của TanStack/query

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.