@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.
- package/build/lib/focusManager.d.ts.map +1 -0
- package/build/lib/hydration.d.ts.map +1 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/infiniteQueryBehavior.d.ts.map +1 -0
- package/build/lib/infiniteQueryObserver.d.ts.map +1 -0
- package/build/lib/logger.d.ts.map +1 -0
- package/build/lib/logger.native.d.ts.map +1 -0
- package/build/lib/mutation.d.ts.map +1 -0
- package/build/lib/mutationCache.d.ts.map +1 -0
- package/build/lib/mutationObserver.d.ts.map +1 -0
- package/build/lib/notifyManager.d.ts.map +1 -0
- package/build/lib/onlineManager.d.ts.map +1 -0
- package/build/lib/queriesObserver.d.ts.map +1 -0
- package/build/lib/query.d.ts.map +1 -0
- package/build/lib/query.esm.js +4 -3
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +4 -3
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs +4 -3
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/queryCache.d.ts.map +1 -0
- package/build/lib/queryClient.d.ts.map +1 -0
- package/build/lib/queryObserver.d.ts.map +1 -0
- package/build/lib/removable.d.ts.map +1 -0
- package/build/lib/retryer.d.ts.map +1 -0
- package/build/lib/subscribable.d.ts.map +1 -0
- package/build/lib/tests/focusManager.test.d.ts.map +1 -0
- package/build/lib/tests/hydration.test.d.ts.map +1 -0
- package/build/lib/tests/infiniteQueryBehavior.test.d.ts.map +1 -0
- package/build/lib/tests/infiniteQueryObserver.test.d.ts.map +1 -0
- package/build/lib/tests/mutationCache.test.d.ts.map +1 -0
- package/build/lib/tests/mutationObserver.test.d.ts.map +1 -0
- package/build/lib/tests/mutations.test.d.ts.map +1 -0
- package/build/lib/tests/notifyManager.test.d.ts.map +1 -0
- package/build/lib/tests/onlineManager.test.d.ts.map +1 -0
- package/build/lib/tests/queriesObserver.test.d.ts.map +1 -0
- package/build/lib/tests/query.test.d.ts.map +1 -0
- package/build/lib/tests/queryCache.test.d.ts.map +1 -0
- package/build/lib/tests/queryClient.test.d.ts.map +1 -0
- package/build/lib/tests/queryObserver.test.d.ts.map +1 -0
- package/build/lib/tests/utils.d.ts.map +1 -0
- package/build/lib/tests/utils.test.d.ts.map +1 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/umd/index.development.js +4 -3
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/query.ts +3 -3
- package/src/tests/query.test.tsx +52 -0
package/package.json
CHANGED
package/src/query.ts
CHANGED
|
@@ -354,8 +354,8 @@ export class Query<
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
if (
|
|
358
|
-
if (
|
|
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 {
|
package/src/tests/query.test.tsx
CHANGED
|
@@ -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
|
})
|