@tanstack/query-core 4.7.1 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "4.7.1",
3
+ "version": "4.8.0",
4
4
  "description": "TODO",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -31,4 +31,4 @@
31
31
  "clean": "rm -rf ./build",
32
32
  "test:eslint": "../../node_modules/.bin/eslint --ext .ts,.tsx ./src"
33
33
  }
34
- }
34
+ }
@@ -547,13 +547,16 @@ export class QueryObserver<
547
547
  }
548
548
 
549
549
  const isFetching = fetchStatus === 'fetching'
550
+ const isLoading = status === 'loading'
551
+ const isError = status === 'error'
550
552
 
551
553
  const result: QueryObserverBaseResult<TData, TError> = {
552
554
  status,
553
555
  fetchStatus,
554
- isLoading: status === 'loading',
556
+ isLoading,
555
557
  isSuccess: status === 'success',
556
- isError: status === 'error',
558
+ isError,
559
+ isInitialLoading: isLoading && isFetching,
557
560
  data,
558
561
  dataUpdatedAt,
559
562
  error,
@@ -564,13 +567,13 @@ export class QueryObserver<
564
567
  isFetchedAfterMount:
565
568
  state.dataUpdateCount > queryInitialState.dataUpdateCount ||
566
569
  state.errorUpdateCount > queryInitialState.errorUpdateCount,
567
- isFetching: isFetching,
568
- isRefetching: isFetching && status !== 'loading',
569
- isLoadingError: status === 'error' && state.dataUpdatedAt === 0,
570
+ isFetching,
571
+ isRefetching: isFetching && !isLoading,
572
+ isLoadingError: isError && state.dataUpdatedAt === 0,
570
573
  isPaused: fetchStatus === 'paused',
571
574
  isPlaceholderData,
572
575
  isPreviousData,
573
- isRefetchError: status === 'error' && state.dataUpdatedAt !== 0,
576
+ isRefetchError: isError && state.dataUpdatedAt !== 0,
574
577
  isStale: isStale(query, options),
575
578
  refetch: this.refetch,
576
579
  remove: this.remove,
@@ -201,11 +201,7 @@ describe('query', () => {
201
201
  expect(args).toBeDefined()
202
202
  expect(args.pageParam).toBeUndefined()
203
203
  expect(args.queryKey).toEqual(key)
204
- if (typeof AbortSignal === 'function') {
205
- expect(args.signal).toBeInstanceOf(AbortSignal)
206
- } else {
207
- expect(args.signal).toBeUndefined()
208
- }
204
+ expect(args.signal).toBeInstanceOf(AbortSignal)
209
205
  })
210
206
 
211
207
  test('should continue if cancellation is not supported and signal is not consumed', async () => {
@@ -259,20 +255,11 @@ describe('query', () => {
259
255
 
260
256
  const query = queryCache.find(key)!
261
257
 
262
- if (typeof AbortSignal === 'function') {
263
- expect(query.state).toMatchObject({
264
- data: undefined,
265
- status: 'loading',
266
- fetchStatus: 'idle',
267
- })
268
- } else {
269
- expect(query.state).toMatchObject({
270
- data: 'data',
271
- status: 'success',
272
- fetchStatus: 'idle',
273
- dataUpdateCount: 1,
274
- })
275
- }
258
+ expect(query.state).toMatchObject({
259
+ data: undefined,
260
+ status: 'loading',
261
+ fetchStatus: 'idle',
262
+ })
276
263
  })
277
264
 
278
265
  test('should provide an AbortSignal to the queryFn that provides info about the cancellation state', async () => {
@@ -312,12 +299,8 @@ describe('query', () => {
312
299
 
313
300
  expect(queryFn).toHaveBeenCalledTimes(1)
314
301
 
315
- let signal = queryFn.mock.calls[0]![0].signal
316
-
317
- if (typeof AbortSignal === 'function') {
318
- signal = queryFn.mock.calls[0]![0].signal
319
- expect(signal?.aborted).toBe(false)
320
- }
302
+ const signal = queryFn.mock.calls[0]![0].signal
303
+ expect(signal?.aborted).toBe(false)
321
304
  expect(onAbort).not.toHaveBeenCalled()
322
305
  expect(abortListener).not.toHaveBeenCalled()
323
306
 
@@ -325,11 +308,9 @@ describe('query', () => {
325
308
 
326
309
  await sleep(100)
327
310
 
328
- if (typeof AbortSignal === 'function') {
329
- expect(signal?.aborted).toBe(true)
330
- expect(onAbort).toHaveBeenCalledTimes(1)
331
- expect(abortListener).toHaveBeenCalledTimes(1)
332
- }
311
+ expect(signal?.aborted).toBe(true)
312
+ expect(onAbort).toHaveBeenCalledTimes(1)
313
+ expect(abortListener).toHaveBeenCalledTimes(1)
333
314
  expect(isCancelledError(error)).toBe(true)
334
315
  })
335
316
 
@@ -1176,9 +1176,7 @@ describe('queryClient', () => {
1176
1176
 
1177
1177
  await queryClient.refetchQueries()
1178
1178
  observer.destroy()
1179
- if (typeof AbortSignal === 'function') {
1180
- expect(abortFn).toHaveBeenCalledTimes(1)
1181
- }
1179
+ expect(abortFn).toHaveBeenCalledTimes(1)
1182
1180
  expect(fetchCount).toBe(2)
1183
1181
  })
1184
1182
 
@@ -1203,9 +1201,7 @@ describe('queryClient', () => {
1203
1201
 
1204
1202
  await queryClient.refetchQueries(undefined, { cancelRefetch: false })
1205
1203
  observer.destroy()
1206
- if (typeof AbortSignal === 'function') {
1207
- expect(abortFn).toHaveBeenCalledTimes(0)
1208
- }
1204
+ expect(abortFn).toHaveBeenCalledTimes(0)
1209
1205
  expect(fetchCount).toBe(1)
1210
1206
  })
1211
1207
  })
package/src/types.ts CHANGED
@@ -373,6 +373,7 @@ export interface QueryObserverBaseResult<TData = unknown, TError = unknown> {
373
373
  isFetching: boolean
374
374
  isLoading: boolean
375
375
  isLoadingError: boolean
376
+ isInitialLoading: boolean
376
377
  isPaused: boolean
377
378
  isPlaceholderData: boolean
378
379
  isPreviousData: boolean