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

QueryClient.isFetching and useIsFetching accept a fetchStatus filter and ignore it

Đang mở Phù hợp với người mới
#11,984 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

@Apu-Emdad đang làm issue này rồi.

Từ ngày 14/10/2026.

  • #11997 của @Apu-Emdad — đã đóng, không merge
  • #12024 của @Apu-Emdad — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/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ệ
react, typescript
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Bắt đầu tại packages/query-core/src/queryClient.ts, nơi issue chỉ ra thao tác spread và việc ghi đè fetchStatus trong isFetching; sau đó theo dõi cách useIsFetching truyền tiếp các bộ lọc. Đọc các bài kiểm thử liên quan đến QueryClient.isFetching và useIsFetching, rồi bổ sung kiểm thử cho các trường hợp paused và idle được báo cáo. Công việc hoàn tất khi API либо tôn trọng bộ lọc, hoặc từ chối bộ lọc đó trong các kiểu, đồng thời hành vi và tài liệu nhất quán.

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

Mô tả

Describe the bug

QueryFilters has a fetchStatus?: FetchStatus field, and FetchStatus is 'fetching' | 'paused' | 'idle', so isFetching({ fetchStatus: 'paused' }) type-checks. It has no effect: QueryClient.isFetching spreads the filters it is given and then writes its own fetchStatus over them, so the argument is discarded for every value, not only 'paused'.

QueryCache.findAll honours the same filter correctly, which makes the difference easy to miss — the filter works through one entry point and is silently dropped through the other.

Minimal reproduction
import { QueryClient } from '@tanstack/query-core'

const client = new QueryClient()
const queryKey = ['session']
const cache = client.getQueryCache()

const query = cache.build(client, { queryKey, queryFn: async () => 'x' })
query.setState({ fetchStatus: 'paused' })

console.log(cache.find({ queryKey })?.state.fetchStatus)                 // 'paused'
console.log(cache.findAll({ queryKey, fetchStatus: 'paused' }).length)   // 1
console.log(client.isFetching({ queryKey, fetchStatus: 'paused' }))      // 0
console.log(client.isFetching({ queryKey, fetchStatus: 'idle' }))        // 0
Expected / actual
call expected actual
findAll({ fetchStatus: 'paused' }).length 1 1
isFetching({ fetchStatus: 'paused' }) 1, or a type error 0
isFetching({ fetchStatus: 'idle' }) 1, or a type error 0

Either outcome would be fine. What is awkward is a public, typed, documented parameter that is accepted and does nothing.

Cause

packages/query-core/src/queryClient.ts:

isFetching(filters) {
  return this.#queryCache.findAll({ ...filters, fetchStatus: 'fetching' }).length
}

useIsFetching forwards its filters to this method, so it behaves the same way.

Why it came up

An app that asks "is this query still waiting on the network" wants paused to count: a lookup held because the browser is offline, or because the window is unfocused and the retry is deferred, has not answered yet. Reading it through useIsFetching({ queryKey, fetchStatus: 'paused' }) compiles and quietly answers 0, so the UI treats a waiting query as a settled one. In our case a page showed a "not found" state to someone whose session lookup was merely paused.

The workaround is to subscribe to the cache and use findAll directly, which works but means reimplementing what useIsFetching exists to provide.

Possible resolutions

In rough order of how little they change:

  1. Type it out — omit fetchStatus from the filters these two accept, so passing it is a compile error, and say in the reference that they count fetching queries only.
  2. Honour it — use the caller's fetchStatus when one is given and default to 'fetching' otherwise. This changes behaviour for anyone currently passing a value and relying on it being ignored, which seems unlikely but is a real semver consideration.
  3. Leave the behaviour and document it — note on useIsFetching and QueryClient.isFetching that fetchStatus is fixed, and point at getQueryCache().findAll for other statuses.

Happy to send a PR for whichever you prefer.

Related
  • Discussion #6756 proposes a built-in queryClient.isPaused / useIsPaused, and its example hook uses the same spread-then-override pattern in user code. If that proposal is the intended answer, this is the part of it that bites today — and option 1 or 3 above would stop the current API misleading people in the meantime.
  • #7559 and #8531 are about isFetching reporting the wrong thing for fetching queries; this is narrower, about a filter argument being inert.
Environment
  • @tanstack/query-core 5.104.1
  • Node 26.11.1, TypeScript 6.0.3
  • Reproduced with query-core alone, so no framework adapter is involved
Ngôn ngữ chính
TypeScript
Star
50.4k
Fork
4.2k
Merge trung bình
9 giờ 3 phút
Pull request đã merge (30 ngày)
426

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.