@tanstack/query-core 4.35.0 → 4.35.3

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 (51) hide show
  1. package/build/lib/focusManager.d.ts.map +1 -0
  2. package/build/lib/hydration.d.ts.map +1 -0
  3. package/build/lib/index.d.ts.map +1 -0
  4. package/build/lib/infiniteQueryBehavior.d.ts.map +1 -0
  5. package/build/lib/infiniteQueryObserver.d.ts.map +1 -0
  6. package/build/lib/logger.d.ts.map +1 -0
  7. package/build/lib/logger.native.d.ts.map +1 -0
  8. package/build/lib/mutation.d.ts.map +1 -0
  9. package/build/lib/mutationCache.d.ts.map +1 -0
  10. package/build/lib/mutationObserver.d.ts.map +1 -0
  11. package/build/lib/notifyManager.d.ts.map +1 -0
  12. package/build/lib/onlineManager.d.ts.map +1 -0
  13. package/build/lib/queriesObserver.d.ts.map +1 -0
  14. package/build/lib/query.d.ts.map +1 -0
  15. package/build/lib/query.esm.js +4 -3
  16. package/build/lib/query.esm.js.map +1 -1
  17. package/build/lib/query.js +4 -3
  18. package/build/lib/query.js.map +1 -1
  19. package/build/lib/query.mjs +4 -3
  20. package/build/lib/query.mjs.map +1 -1
  21. package/build/lib/queryCache.d.ts.map +1 -0
  22. package/build/lib/queryClient.d.ts.map +1 -0
  23. package/build/lib/queryObserver.d.ts.map +1 -0
  24. package/build/lib/removable.d.ts.map +1 -0
  25. package/build/lib/retryer.d.ts.map +1 -0
  26. package/build/lib/subscribable.d.ts.map +1 -0
  27. package/build/lib/tests/focusManager.test.d.ts.map +1 -0
  28. package/build/lib/tests/hydration.test.d.ts.map +1 -0
  29. package/build/lib/tests/infiniteQueryBehavior.test.d.ts.map +1 -0
  30. package/build/lib/tests/infiniteQueryObserver.test.d.ts.map +1 -0
  31. package/build/lib/tests/mutationCache.test.d.ts.map +1 -0
  32. package/build/lib/tests/mutationObserver.test.d.ts.map +1 -0
  33. package/build/lib/tests/mutations.test.d.ts.map +1 -0
  34. package/build/lib/tests/notifyManager.test.d.ts.map +1 -0
  35. package/build/lib/tests/onlineManager.test.d.ts.map +1 -0
  36. package/build/lib/tests/queriesObserver.test.d.ts.map +1 -0
  37. package/build/lib/tests/query.test.d.ts.map +1 -0
  38. package/build/lib/tests/queryCache.test.d.ts.map +1 -0
  39. package/build/lib/tests/queryClient.test.d.ts.map +1 -0
  40. package/build/lib/tests/queryObserver.test.d.ts.map +1 -0
  41. package/build/lib/tests/utils.d.ts.map +1 -0
  42. package/build/lib/tests/utils.test.d.ts.map +1 -0
  43. package/build/lib/types.d.ts.map +1 -0
  44. package/build/lib/utils.d.ts.map +1 -0
  45. package/build/umd/index.development.js +4 -3
  46. package/build/umd/index.development.js.map +1 -1
  47. package/build/umd/index.production.js +1 -1
  48. package/build/umd/index.production.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/query.ts +3 -3
  51. package/src/tests/query.test.tsx +52 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "4.35.0",
3
+ "version": "4.35.3",
4
4
  "description": "The framework agnostic core that powers TanStack Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
package/src/query.ts CHANGED
@@ -354,8 +354,8 @@ export class Query<
354
354
  }
355
355
  }
356
356
 
357
- if (!Array.isArray(this.options.queryKey)) {
358
- if (process.env.NODE_ENV !== 'production') {
357
+ if (process.env.NODE_ENV !== 'production') {
358
+ if (!Array.isArray(this.options.queryKey)) {
359
359
  this.logger.error(
360
360
  `As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`,
361
361
  )
@@ -559,7 +559,7 @@ export class Query<
559
559
  const error = action.error as unknown
560
560
 
561
561
  if (isCancelledError(error) && error.revert && this.revertState) {
562
- return { ...this.revertState }
562
+ return { ...this.revertState, fetchStatus: 'idle' }
563
563
  }
564
564
 
565
565
  return {
@@ -911,4 +911,56 @@ describe('query', () => {
911
911
 
912
912
  unsubscribe()
913
913
  })
914
+
915
+ test('should always revert to idle state (#5958)', async () => {
916
+ let mockedData = [1]
917
+
918
+ const key = queryKey()
919
+
920
+ const queryFn = jest.fn<
921
+ Promise<unknown>,
922
+ [QueryFunctionContext<ReturnType<typeof queryKey>>]
923
+ >()
924
+
925
+ queryFn.mockImplementation(({ signal }) => {
926
+ return new Promise((resolve, reject) => {
927
+ const abortListener = () => {
928
+ clearTimeout(timerId)
929
+ reject(signal!.reason)
930
+ }
931
+ signal!.addEventListener('abort', abortListener)
932
+
933
+ const timerId = setTimeout(() => {
934
+ signal!.removeEventListener('abort', abortListener)
935
+ resolve(mockedData.join(' - '))
936
+ }, 50)
937
+ })
938
+ })
939
+
940
+ const observer = new QueryObserver(queryClient, {
941
+ queryKey: key,
942
+ queryFn,
943
+ })
944
+ const unsubscribe = observer.subscribe(() => undefined)
945
+ await sleep(60) // let it resolve
946
+
947
+ mockedData = [1, 2] // update "server" state in the background
948
+
949
+ queryClient.invalidateQueries(key)
950
+ await sleep(1)
951
+ queryClient.invalidateQueries(key)
952
+ await sleep(1)
953
+ unsubscribe() // unsubscribe to simulate unmount
954
+
955
+ // set up a new observer to simulate a mount of new component
956
+ const newObserver = new QueryObserver(queryClient, {
957
+ queryKey: key,
958
+ queryFn,
959
+ })
960
+
961
+ const spy = jest.fn()
962
+ newObserver.subscribe(({ data }) => spy(data))
963
+ await sleep(60) // let it resolve
964
+ expect(spy).toHaveBeenCalledWith('1 - 2')
965
+ })
914
966
  })