Skip to content
Source
Sign inSign up
TanStack/query

fix(query-core): propagate AbortSignal reason in infiniteQueryBehavior fetchPage cancellation #10476

Mergedkuishou68(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/10476/headmerged by TkDodo View on GitHub

Showing 2 changed files with 42 additions and 1 deletion.

x
0 of 2 viewed, 2 left
41 additions and 0 deletionspackages/query-core/src/__tests__/infiniteQueryBehavior.test.tsxModified
View file
@@ -1,6 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { CancelledError, InfiniteQueryObserver, QueryClient } from '..'
+import { infiniteQueryBehavior } from '../infiniteQueryBehavior'
import type { InfiniteData, InfiniteQueryObserverResult, QueryCache } from '..'
​
describe('InfiniteQueryBehavior', () => {
@@ -332,6 +333,46 @@
unsubscribe()
​
+ it('should surface the abort reason when cancellation happens between refetched pages', async () => {
+ const key = queryKey()
+ const abortController = new AbortController()
+ const queryFn = vi.fn().mockImplementation(({ pageParam, signal }) => {
+ void signal.aborted
+​
+ if (pageParam === 1) {
+ abortController.abort()
+ }
+​
+ return pageParam
+ })
+​
+ const behavior = infiniteQueryBehavior<number, Error, number, number>()