@tanstack/query-core 5.28.2 → 5.28.6

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.
Files changed (102) hide show
  1. package/build/legacy/hydration.d.cts +1 -1
  2. package/build/legacy/hydration.d.ts +1 -1
  3. package/build/legacy/index.d.cts +1 -1
  4. package/build/legacy/index.d.ts +1 -1
  5. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  6. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  7. package/build/legacy/infiniteQueryObserver.d.cts +1 -1
  8. package/build/legacy/infiniteQueryObserver.d.ts +1 -1
  9. package/build/legacy/mutation.d.cts +1 -1
  10. package/build/legacy/mutation.d.ts +1 -1
  11. package/build/legacy/mutationCache.d.cts +1 -1
  12. package/build/legacy/mutationCache.d.ts +1 -1
  13. package/build/legacy/mutationObserver.d.cts +1 -1
  14. package/build/legacy/mutationObserver.d.ts +1 -1
  15. package/build/legacy/queriesObserver.d.cts +1 -1
  16. package/build/legacy/queriesObserver.d.ts +1 -1
  17. package/build/legacy/query.cjs +17 -10
  18. package/build/legacy/query.cjs.map +1 -1
  19. package/build/legacy/query.d.cts +1 -1
  20. package/build/legacy/query.d.ts +1 -1
  21. package/build/legacy/query.js +15 -9
  22. package/build/legacy/query.js.map +1 -1
  23. package/build/legacy/queryCache.d.cts +1 -1
  24. package/build/legacy/queryCache.d.ts +1 -1
  25. package/build/legacy/{queryClient-UWB6EkqM.d.ts → queryClient-6vLRMq5C.d.ts} +8 -1
  26. package/build/legacy/{queryClient-WxLAyIG_.d.cts → queryClient-C_S9rQE6.d.cts} +8 -1
  27. package/build/legacy/queryClient.d.cts +1 -1
  28. package/build/legacy/queryClient.d.ts +1 -1
  29. package/build/legacy/queryObserver.cjs +22 -21
  30. package/build/legacy/queryObserver.cjs.map +1 -1
  31. package/build/legacy/queryObserver.d.cts +1 -1
  32. package/build/legacy/queryObserver.d.ts +1 -1
  33. package/build/legacy/queryObserver.js +22 -21
  34. package/build/legacy/queryObserver.js.map +1 -1
  35. package/build/legacy/retryer.d.cts +1 -1
  36. package/build/legacy/retryer.d.ts +1 -1
  37. package/build/legacy/types.d.cts +1 -1
  38. package/build/legacy/types.d.ts +1 -1
  39. package/build/legacy/utils.d.cts +1 -1
  40. package/build/legacy/utils.d.ts +1 -1
  41. package/build/modern/hydration.d.cts +1 -1
  42. package/build/modern/hydration.d.ts +1 -1
  43. package/build/modern/index.d.cts +1 -1
  44. package/build/modern/index.d.ts +1 -1
  45. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  46. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  47. package/build/modern/infiniteQueryObserver.d.cts +1 -1
  48. package/build/modern/infiniteQueryObserver.d.ts +1 -1
  49. package/build/modern/mutation.d.cts +1 -1
  50. package/build/modern/mutation.d.ts +1 -1
  51. package/build/modern/mutationCache.d.cts +1 -1
  52. package/build/modern/mutationCache.d.ts +1 -1
  53. package/build/modern/mutationObserver.d.cts +1 -1
  54. package/build/modern/mutationObserver.d.ts +1 -1
  55. package/build/modern/queriesObserver.d.cts +1 -1
  56. package/build/modern/queriesObserver.d.ts +1 -1
  57. package/build/modern/query.cjs +17 -10
  58. package/build/modern/query.cjs.map +1 -1
  59. package/build/modern/query.d.cts +1 -1
  60. package/build/modern/query.d.ts +1 -1
  61. package/build/modern/query.js +15 -9
  62. package/build/modern/query.js.map +1 -1
  63. package/build/modern/queryCache.d.cts +1 -1
  64. package/build/modern/queryCache.d.ts +1 -1
  65. package/build/modern/{queryClient-UWB6EkqM.d.ts → queryClient-6vLRMq5C.d.ts} +8 -1
  66. package/build/modern/{queryClient-WxLAyIG_.d.cts → queryClient-C_S9rQE6.d.cts} +8 -1
  67. package/build/modern/queryClient.d.cts +1 -1
  68. package/build/modern/queryClient.d.ts +1 -1
  69. package/build/modern/queryObserver.cjs +22 -21
  70. package/build/modern/queryObserver.cjs.map +1 -1
  71. package/build/modern/queryObserver.d.cts +1 -1
  72. package/build/modern/queryObserver.d.ts +1 -1
  73. package/build/modern/queryObserver.js +22 -21
  74. package/build/modern/queryObserver.js.map +1 -1
  75. package/build/modern/retryer.d.cts +1 -1
  76. package/build/modern/retryer.d.ts +1 -1
  77. package/build/modern/types.d.cts +1 -1
  78. package/build/modern/types.d.ts +1 -1
  79. package/build/modern/utils.d.cts +1 -1
  80. package/build/modern/utils.d.ts +1 -1
  81. package/package.json +2 -1
  82. package/src/query.ts +22 -9
  83. package/src/queryObserver.ts +24 -24
  84. /package/src/{tests → __tests__}/focusManager.test.tsx +0 -0
  85. /package/src/{tests → __tests__}/hydration.test.tsx +0 -0
  86. /package/src/{tests → __tests__}/infiniteQueryBehavior.test.tsx +0 -0
  87. /package/src/{tests → __tests__}/infiniteQueryObserver.test-d.tsx +0 -0
  88. /package/src/{tests → __tests__}/infiniteQueryObserver.test.tsx +0 -0
  89. /package/src/{tests → __tests__}/mutationCache.test.tsx +0 -0
  90. /package/src/{tests → __tests__}/mutationObserver.test.tsx +0 -0
  91. /package/src/{tests → __tests__}/mutations.test.tsx +0 -0
  92. /package/src/{tests → __tests__}/notifyManager.test.tsx +0 -0
  93. /package/src/{tests → __tests__}/onlineManager.test.tsx +0 -0
  94. /package/src/{tests → __tests__}/queriesObserver.test.tsx +0 -0
  95. /package/src/{tests → __tests__}/query.test.tsx +0 -0
  96. /package/src/{tests → __tests__}/queryCache.test.tsx +0 -0
  97. /package/src/{tests → __tests__}/queryClient.test-d.tsx +0 -0
  98. /package/src/{tests → __tests__}/queryClient.test.tsx +0 -0
  99. /package/src/{tests → __tests__}/queryObserver.test-d.tsx +0 -0
  100. /package/src/{tests → __tests__}/queryObserver.test.tsx +0 -0
  101. /package/src/{tests → __tests__}/utils.test.tsx +0 -0
  102. /package/src/{tests → __tests__}/utils.ts +0 -0
package/src/query.ts CHANGED
@@ -552,16 +552,8 @@ export class Query<
552
552
  case 'fetch':
553
553
  return {
554
554
  ...state,
555
- fetchFailureCount: 0,
556
- fetchFailureReason: null,
555
+ ...fetchState(state.data, this.options),
557
556
  fetchMeta: action.meta ?? null,
558
- fetchStatus: canFetch(this.options.networkMode)
559
- ? 'fetching'
560
- : 'paused',
561
- ...(state.data === undefined && {
562
- error: null,
563
- status: 'pending',
564
- }),
565
557
  }
566
558
  case 'success':
567
559
  return {
@@ -620,6 +612,27 @@ export class Query<
620
612
  }
621
613
  }
622
614
 
615
+ export function fetchState<
616
+ TQueryFnData,
617
+ TError,
618
+ TData,
619
+ TQueryKey extends QueryKey,
620
+ >(
621
+ data: TData | undefined,
622
+ options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
623
+ ) {
624
+ return {
625
+ fetchFailureCount: 0,
626
+ fetchFailureReason: null,
627
+ fetchStatus: canFetch(options.networkMode) ? 'fetching' : 'paused',
628
+ ...(data === undefined &&
629
+ ({
630
+ error: null,
631
+ status: 'pending',
632
+ } as const)),
633
+ } as const
634
+ }
635
+
623
636
  function getDefaultState<
624
637
  TQueryFnData,
625
638
  TError,
@@ -9,9 +9,9 @@ import {
9
9
  import { notifyManager } from './notifyManager'
10
10
  import { focusManager } from './focusManager'
11
11
  import { Subscribable } from './subscribable'
12
- import { canFetch } from './retryer'
13
- import type { QueryClient } from './queryClient'
12
+ import { fetchState } from './query'
14
13
  import type { FetchOptions, Query, QueryState } from './query'
14
+ import type { QueryClient } from './queryClient'
15
15
  import type {
16
16
  DefaultError,
17
17
  DefaultedQueryObserverOptions,
@@ -437,7 +437,7 @@ export class QueryObserver<
437
437
  : this.#currentQueryInitialState
438
438
 
439
439
  const { state } = query
440
- let { error, errorUpdatedAt, fetchStatus, status } = state
440
+ let newState = { ...state }
441
441
  let isPlaceholderData = false
442
442
  let data: TData | undefined
443
443
 
@@ -451,31 +451,31 @@ export class QueryObserver<
451
451
  mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)
452
452
 
453
453
  if (fetchOnMount || fetchOptionally) {
454
- fetchStatus = canFetch(query.options.networkMode)
455
- ? 'fetching'
456
- : 'paused'
457
- if (state.data === undefined) {
458
- status = 'pending'
454
+ newState = {
455
+ ...newState,
456
+ ...fetchState(state.data, query.options),
459
457
  }
460
458
  }
461
459
  if (options._optimisticResults === 'isRestoring') {
462
- fetchStatus = 'idle'
460
+ newState.fetchStatus = 'idle'
463
461
  }
464
462
  }
465
463
 
464
+ let { error, errorUpdatedAt, status } = newState
465
+
466
466
  // Select data if needed
467
- if (options.select && state.data !== undefined) {
467
+ if (options.select && newState.data !== undefined) {
468
468
  // Memoize select result
469
469
  if (
470
470
  prevResult &&
471
- state.data === prevResultState?.data &&
471
+ newState.data === prevResultState?.data &&
472
472
  options.select === this.#selectFn
473
473
  ) {
474
474
  data = this.#selectResult
475
475
  } else {
476
476
  try {
477
477
  this.#selectFn = options.select
478
- data = options.select(state.data)
478
+ data = options.select(newState.data)
479
479
  data = replaceData(prevResult?.data, data, options)
480
480
  this.#selectResult = data
481
481
  this.#selectError = null
@@ -486,7 +486,7 @@ export class QueryObserver<
486
486
  }
487
487
  // Use query data
488
488
  else {
489
- data = state.data as unknown as TData
489
+ data = newState.data as unknown as TData
490
490
  }
491
491
 
492
492
  // Show placeholder data if needed
@@ -541,36 +541,36 @@ export class QueryObserver<
541
541
  status = 'error'
542
542
  }
543
543
 
544
- const isFetching = fetchStatus === 'fetching'
544
+ const isFetching = newState.fetchStatus === 'fetching'
545
545
  const isPending = status === 'pending'
546
546
  const isError = status === 'error'
547
547
 
548
548
  const isLoading = isPending && isFetching
549
- const hasData = state.data !== undefined
549
+ const hasData = data !== undefined
550
550
 
551
551
  const result: QueryObserverBaseResult<TData, TError> = {
552
552
  status,
553
- fetchStatus,
553
+ fetchStatus: newState.fetchStatus,
554
554
  isPending,
555
555
  isSuccess: status === 'success',
556
556
  isError,
557
557
  isInitialLoading: isLoading,
558
558
  isLoading,
559
559
  data,
560
- dataUpdatedAt: state.dataUpdatedAt,
560
+ dataUpdatedAt: newState.dataUpdatedAt,
561
561
  error,
562
562
  errorUpdatedAt,
563
- failureCount: state.fetchFailureCount,
564
- failureReason: state.fetchFailureReason,
565
- errorUpdateCount: state.errorUpdateCount,
566
- isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
563
+ failureCount: newState.fetchFailureCount,
564
+ failureReason: newState.fetchFailureReason,
565
+ errorUpdateCount: newState.errorUpdateCount,
566
+ isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
567
567
  isFetchedAfterMount:
568
- state.dataUpdateCount > queryInitialState.dataUpdateCount ||
569
- state.errorUpdateCount > queryInitialState.errorUpdateCount,
568
+ newState.dataUpdateCount > queryInitialState.dataUpdateCount ||
569
+ newState.errorUpdateCount > queryInitialState.errorUpdateCount,
570
570
  isFetching,
571
571
  isRefetching: isFetching && !isPending,
572
572
  isLoadingError: isError && !hasData,
573
- isPaused: fetchStatus === 'paused',
573
+ isPaused: newState.fetchStatus === 'paused',
574
574
  isPlaceholderData,
575
575
  isRefetchError: isError && hasData,
576
576
  isStale: isStale(query, options),
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes