@tanstack/react-query 5.0.0-alpha.9 → 5.0.0-alpha.91
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/codemods/remove-overloads/remove-overloads.js +59 -0
- package/build/codemods/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
- package/build/codemods/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
- package/build/codemods/remove-overloads/utils/index.js +124 -0
- package/build/codemods/remove-overloads/utils/unknown-usage-error.js +27 -0
- package/build/codemods/rename-hydrate/rename-hydrate.js +55 -0
- package/build/codemods/rename-properties/rename-properties.js +41 -0
- package/build/codemods/src/utils/index.js +205 -0
- package/build/codemods/src/v4/key-transformation.js +138 -0
- package/build/codemods/src/v4/replace-import-specifier.js +25 -0
- package/build/codemods/transformers/query-cache-transformer.js +116 -0
- package/build/codemods/transformers/query-client-transformer.js +48 -0
- package/build/codemods/transformers/use-query-like-transformer.js +32 -0
- package/build/codemods/utils/replacers/key-replacer.js +164 -0
- package/build/legacy/HydrationBoundary.cjs +60 -0
- package/build/legacy/HydrationBoundary.cjs.map +1 -0
- package/build/legacy/HydrationBoundary.d.cts +12 -0
- package/build/legacy/HydrationBoundary.d.ts +12 -0
- package/build/legacy/HydrationBoundary.js +26 -0
- package/build/legacy/HydrationBoundary.js.map +1 -0
- package/build/legacy/QueryClientProvider.cjs +71 -0
- package/build/legacy/QueryClientProvider.cjs.map +1 -0
- package/build/legacy/QueryClientProvider.d.cts +12 -0
- package/build/legacy/QueryClientProvider.d.ts +12 -0
- package/build/legacy/QueryClientProvider.js +35 -0
- package/build/legacy/QueryClientProvider.js.map +1 -0
- package/build/legacy/QueryErrorResetBoundary.cjs +66 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts +14 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts +14 -0
- package/build/legacy/QueryErrorResetBoundary.js +31 -0
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -0
- package/build/legacy/errorBoundaryUtils.cjs +67 -0
- package/build/legacy/errorBoundaryUtils.cjs.map +1 -0
- package/build/legacy/errorBoundaryUtils.d.cts +14 -0
- package/build/legacy/errorBoundaryUtils.d.ts +14 -0
- package/build/legacy/errorBoundaryUtils.js +31 -0
- package/build/legacy/errorBoundaryUtils.js.map +1 -0
- package/build/legacy/index.cjs +85 -0
- package/build/legacy/index.cjs.map +1 -0
- package/build/legacy/index.d.cts +17 -0
- package/build/legacy/index.d.ts +17 -0
- package/build/legacy/index.js +46 -0
- package/build/legacy/index.js.map +1 -0
- package/build/legacy/infiniteQueryOptions.cjs +33 -0
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -0
- package/build/legacy/infiniteQueryOptions.d.cts +13 -0
- package/build/legacy/infiniteQueryOptions.d.ts +13 -0
- package/build/legacy/infiniteQueryOptions.js +8 -0
- package/build/legacy/infiniteQueryOptions.js.map +1 -0
- package/build/legacy/isRestoring.cjs +47 -0
- package/build/legacy/isRestoring.cjs.map +1 -0
- package/build/legacy/isRestoring.d.cts +6 -0
- package/build/legacy/isRestoring.d.ts +6 -0
- package/build/legacy/isRestoring.js +12 -0
- package/build/legacy/isRestoring.js.map +1 -0
- package/build/legacy/queryOptions.cjs +33 -0
- package/build/legacy/queryOptions.cjs.map +1 -0
- package/build/legacy/queryOptions.d.cts +13 -0
- package/build/legacy/queryOptions.d.ts +13 -0
- package/build/legacy/queryOptions.js +8 -0
- package/build/legacy/queryOptions.js.map +1 -0
- package/build/legacy/suspense.cjs +48 -0
- package/build/legacy/suspense.cjs.map +1 -0
- package/build/legacy/suspense.d.cts +10 -0
- package/build/legacy/suspense.d.ts +10 -0
- package/build/legacy/suspense.js +20 -0
- package/build/legacy/suspense.js.map +1 -0
- package/build/legacy/types.cjs +19 -0
- package/build/legacy/types.cjs.map +1 -0
- package/build/legacy/types.d.cts +34 -0
- package/build/legacy/types.d.ts +34 -0
- package/build/legacy/types.js +1 -0
- package/build/legacy/types.js.map +1 -0
- package/build/legacy/useBaseQuery.cjs +92 -0
- package/build/legacy/useBaseQuery.cjs.map +1 -0
- package/build/legacy/useBaseQuery.d.cts +92 -0
- package/build/legacy/useBaseQuery.d.ts +92 -0
- package/build/legacy/useBaseQuery.js +62 -0
- package/build/legacy/useBaseQuery.js.map +1 -0
- package/build/legacy/useInfiniteQuery.cjs +41 -0
- package/build/legacy/useInfiniteQuery.cjs.map +1 -0
- package/build/legacy/useInfiniteQuery.d.cts +8 -0
- package/build/legacy/useInfiniteQuery.d.ts +8 -0
- package/build/legacy/useInfiniteQuery.js +17 -0
- package/build/legacy/useInfiniteQuery.js.map +1 -0
- package/build/legacy/useIsFetching.cjs +56 -0
- package/build/legacy/useIsFetching.cjs.map +1 -0
- package/build/legacy/useIsFetching.d.cts +5 -0
- package/build/legacy/useIsFetching.d.ts +5 -0
- package/build/legacy/useIsFetching.js +22 -0
- package/build/legacy/useIsFetching.js.map +1 -0
- package/build/legacy/useMutation.cjs +77 -0
- package/build/legacy/useMutation.cjs.map +1 -0
- package/build/legacy/useMutation.d.cts +6 -0
- package/build/legacy/useMutation.d.ts +6 -0
- package/build/legacy/useMutation.js +43 -0
- package/build/legacy/useMutation.js.map +1 -0
- package/build/legacy/useMutationState.cjs +88 -0
- package/build/legacy/useMutationState.cjs.map +1 -0
- package/build/legacy/useMutationState.d.cts +10 -0
- package/build/legacy/useMutationState.d.ts +10 -0
- package/build/legacy/useMutationState.js +53 -0
- package/build/legacy/useMutationState.js.map +1 -0
- package/build/legacy/useQueries.cjs +128 -0
- package/build/legacy/useQueries.cjs.map +1 -0
- package/build/legacy/useQueries.d.cts +53 -0
- package/build/{lib → legacy}/useQueries.d.ts +14 -11
- package/build/legacy/useQueries.js +103 -0
- package/build/legacy/useQueries.js.map +1 -0
- package/build/legacy/useQuery.cjs +36 -0
- package/build/legacy/useQuery.cjs.map +1 -0
- package/build/legacy/useQuery.d.cts +8 -0
- package/build/legacy/useQuery.d.ts +8 -0
- package/build/legacy/useQuery.js +12 -0
- package/build/legacy/useQuery.js.map +1 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs +46 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +6 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +6 -0
- package/build/legacy/useSuspenseInfiniteQuery.js +22 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -0
- package/build/legacy/useSuspenseQuery.cjs +45 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -0
- package/build/legacy/useSuspenseQuery.d.cts +6 -0
- package/build/legacy/useSuspenseQuery.d.ts +6 -0
- package/build/legacy/useSuspenseQuery.js +21 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -0
- package/build/legacy/utils.cjs +36 -0
- package/build/legacy/utils.cjs.map +1 -0
- package/build/legacy/utils.d.cts +3 -0
- package/build/legacy/utils.d.ts +3 -0
- package/build/legacy/utils.js +11 -0
- package/build/legacy/utils.js.map +1 -0
- package/build/modern/HydrationBoundary.cjs +60 -0
- package/build/modern/HydrationBoundary.cjs.map +1 -0
- package/build/modern/HydrationBoundary.d.cts +12 -0
- package/build/modern/HydrationBoundary.d.ts +12 -0
- package/build/modern/HydrationBoundary.js +26 -0
- package/build/modern/HydrationBoundary.js.map +1 -0
- package/build/modern/QueryClientProvider.cjs +71 -0
- package/build/modern/QueryClientProvider.cjs.map +1 -0
- package/build/modern/QueryClientProvider.d.cts +12 -0
- package/build/modern/QueryClientProvider.d.ts +12 -0
- package/build/modern/QueryClientProvider.js +35 -0
- package/build/modern/QueryClientProvider.js.map +1 -0
- package/build/modern/QueryErrorResetBoundary.cjs +66 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -0
- package/build/modern/QueryErrorResetBoundary.d.cts +14 -0
- package/build/modern/QueryErrorResetBoundary.d.ts +14 -0
- package/build/modern/QueryErrorResetBoundary.js +31 -0
- package/build/modern/QueryErrorResetBoundary.js.map +1 -0
- package/build/modern/errorBoundaryUtils.cjs +67 -0
- package/build/modern/errorBoundaryUtils.cjs.map +1 -0
- package/build/modern/errorBoundaryUtils.d.cts +14 -0
- package/build/modern/errorBoundaryUtils.d.ts +14 -0
- package/build/modern/errorBoundaryUtils.js +31 -0
- package/build/modern/errorBoundaryUtils.js.map +1 -0
- package/build/modern/index.cjs +85 -0
- package/build/modern/index.cjs.map +1 -0
- package/build/modern/index.d.cts +17 -0
- package/build/modern/index.d.ts +17 -0
- package/build/modern/index.js +46 -0
- package/build/modern/index.js.map +1 -0
- package/build/modern/infiniteQueryOptions.cjs +33 -0
- package/build/modern/infiniteQueryOptions.cjs.map +1 -0
- package/build/modern/infiniteQueryOptions.d.cts +13 -0
- package/build/modern/infiniteQueryOptions.d.ts +13 -0
- package/build/modern/infiniteQueryOptions.js +8 -0
- package/build/modern/infiniteQueryOptions.js.map +1 -0
- package/build/modern/isRestoring.cjs +47 -0
- package/build/modern/isRestoring.cjs.map +1 -0
- package/build/modern/isRestoring.d.cts +6 -0
- package/build/modern/isRestoring.d.ts +6 -0
- package/build/modern/isRestoring.js +12 -0
- package/build/modern/isRestoring.js.map +1 -0
- package/build/modern/queryOptions.cjs +33 -0
- package/build/modern/queryOptions.cjs.map +1 -0
- package/build/modern/queryOptions.d.cts +13 -0
- package/build/modern/queryOptions.d.ts +13 -0
- package/build/modern/queryOptions.js +8 -0
- package/build/modern/queryOptions.js.map +1 -0
- package/build/modern/suspense.cjs +48 -0
- package/build/modern/suspense.cjs.map +1 -0
- package/build/modern/suspense.d.cts +10 -0
- package/build/modern/suspense.d.ts +10 -0
- package/build/modern/suspense.js +20 -0
- package/build/modern/suspense.js.map +1 -0
- package/build/modern/types.cjs +19 -0
- package/build/modern/types.cjs.map +1 -0
- package/build/modern/types.d.cts +34 -0
- package/build/modern/types.d.ts +34 -0
- package/build/modern/types.js +1 -0
- package/build/modern/types.js.map +1 -0
- package/build/modern/useBaseQuery.cjs +92 -0
- package/build/modern/useBaseQuery.cjs.map +1 -0
- package/build/modern/useBaseQuery.d.cts +92 -0
- package/build/modern/useBaseQuery.d.ts +92 -0
- package/build/modern/useBaseQuery.js +62 -0
- package/build/modern/useBaseQuery.js.map +1 -0
- package/build/modern/useInfiniteQuery.cjs +41 -0
- package/build/modern/useInfiniteQuery.cjs.map +1 -0
- package/build/modern/useInfiniteQuery.d.cts +8 -0
- package/build/modern/useInfiniteQuery.d.ts +8 -0
- package/build/modern/useInfiniteQuery.js +17 -0
- package/build/modern/useInfiniteQuery.js.map +1 -0
- package/build/modern/useIsFetching.cjs +56 -0
- package/build/modern/useIsFetching.cjs.map +1 -0
- package/build/modern/useIsFetching.d.cts +5 -0
- package/build/modern/useIsFetching.d.ts +5 -0
- package/build/modern/useIsFetching.js +22 -0
- package/build/modern/useIsFetching.js.map +1 -0
- package/build/modern/useMutation.cjs +77 -0
- package/build/modern/useMutation.cjs.map +1 -0
- package/build/modern/useMutation.d.cts +6 -0
- package/build/modern/useMutation.d.ts +6 -0
- package/build/modern/useMutation.js +43 -0
- package/build/modern/useMutation.js.map +1 -0
- package/build/modern/useMutationState.cjs +88 -0
- package/build/modern/useMutationState.cjs.map +1 -0
- package/build/modern/useMutationState.d.cts +10 -0
- package/build/modern/useMutationState.d.ts +10 -0
- package/build/modern/useMutationState.js +53 -0
- package/build/modern/useMutationState.js.map +1 -0
- package/build/modern/useQueries.cjs +125 -0
- package/build/modern/useQueries.cjs.map +1 -0
- package/build/modern/useQueries.d.cts +53 -0
- package/build/modern/useQueries.d.ts +53 -0
- package/build/modern/useQueries.js +100 -0
- package/build/modern/useQueries.js.map +1 -0
- package/build/modern/useQuery.cjs +36 -0
- package/build/modern/useQuery.cjs.map +1 -0
- package/build/modern/useQuery.d.cts +8 -0
- package/build/modern/useQuery.d.ts +8 -0
- package/build/modern/useQuery.js +12 -0
- package/build/modern/useQuery.js.map +1 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs +46 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -0
- package/build/modern/useSuspenseInfiniteQuery.d.cts +6 -0
- package/build/modern/useSuspenseInfiniteQuery.d.ts +6 -0
- package/build/modern/useSuspenseInfiniteQuery.js +22 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -0
- package/build/modern/useSuspenseQuery.cjs +45 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -0
- package/build/modern/useSuspenseQuery.d.cts +6 -0
- package/build/modern/useSuspenseQuery.d.ts +6 -0
- package/build/modern/useSuspenseQuery.js +21 -0
- package/build/modern/useSuspenseQuery.js.map +1 -0
- package/build/modern/utils.cjs +36 -0
- package/build/modern/utils.cjs.map +1 -0
- package/build/modern/utils.d.cts +3 -0
- package/build/modern/utils.d.ts +3 -0
- package/build/modern/utils.js +11 -0
- package/build/modern/utils.js.map +1 -0
- package/package.json +29 -17
- package/src/HydrationBoundary.tsx +1 -1
- package/src/__tests__/HydrationBoundary.test.tsx +5 -5
- package/src/__tests__/QueryClientProvider.test.tsx +2 -2
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +753 -621
- package/src/__tests__/ssr-hydration.test.tsx +4 -4
- package/src/__tests__/ssr.test.tsx +2 -2
- package/src/__tests__/suspense.test.tsx +8 -90
- package/src/__tests__/useInfiniteQuery.test.tsx +36 -74
- package/src/__tests__/useInfiniteQuery.type.test.tsx +2 -29
- package/src/__tests__/useIsFetching.test.tsx +1 -1
- package/src/__tests__/useMutation.test.tsx +22 -23
- package/src/__tests__/useMutationState.test.tsx +23 -0
- package/src/__tests__/useQueries.test.tsx +214 -91
- package/src/__tests__/useQuery.test.tsx +691 -551
- package/src/__tests__/useQuery.types.test.tsx +22 -1
- package/src/__tests__/utils.tsx +11 -5
- package/src/errorBoundaryUtils.ts +7 -7
- package/src/index.ts +4 -0
- package/src/infiniteQueryOptions.ts +93 -0
- package/src/queryOptions.ts +42 -0
- package/src/suspense.ts +9 -15
- package/src/types.ts +50 -8
- package/src/useBaseQuery.ts +14 -26
- package/src/useInfiniteQuery.ts +50 -7
- package/src/useIsFetching.ts +1 -1
- package/src/useMutation.ts +4 -4
- package/src/useMutationState.ts +8 -8
- package/src/useQueries.ts +53 -36
- package/src/useQuery.ts +6 -21
- package/src/useSuspenseInfiniteQuery.ts +47 -0
- package/src/useSuspenseQuery.ts +26 -0
- package/build/lib/HydrationBoundary.d.ts +0 -9
- package/build/lib/HydrationBoundary.esm.js +0 -29
- package/build/lib/HydrationBoundary.esm.js.map +0 -1
- package/build/lib/HydrationBoundary.js +0 -50
- package/build/lib/HydrationBoundary.js.map +0 -1
- package/build/lib/HydrationBoundary.mjs +0 -29
- package/build/lib/HydrationBoundary.mjs.map +0 -1
- package/build/lib/QueryClientProvider.d.ts +0 -9
- package/build/lib/QueryClientProvider.esm.js +0 -31
- package/build/lib/QueryClientProvider.esm.js.map +0 -1
- package/build/lib/QueryClientProvider.js +0 -54
- package/build/lib/QueryClientProvider.js.map +0 -1
- package/build/lib/QueryClientProvider.mjs +0 -31
- package/build/lib/QueryClientProvider.mjs.map +0 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +0 -11
- package/build/lib/QueryErrorResetBoundary.esm.js +0 -38
- package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.js +0 -60
- package/build/lib/QueryErrorResetBoundary.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.mjs +0 -38
- package/build/lib/QueryErrorResetBoundary.mjs.map +0 -1
- package/build/lib/__tests__/HydrationBoundary.test.d.ts +0 -1
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +0 -1
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +0 -6
- package/build/lib/__tests__/ssr-hydration.test.d.ts +0 -1
- package/build/lib/__tests__/ssr.test.d.ts +0 -1
- package/build/lib/__tests__/suspense.test.d.ts +0 -1
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +0 -1
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +0 -1
- package/build/lib/__tests__/useIsFetching.test.d.ts +0 -1
- package/build/lib/__tests__/useMutation.test.d.ts +0 -1
- package/build/lib/__tests__/useMutationState.test.d.ts +0 -1
- package/build/lib/__tests__/useQueries.test.d.ts +0 -1
- package/build/lib/__tests__/useQuery.test.d.ts +0 -1
- package/build/lib/__tests__/useQuery.types.test.d.ts +0 -1
- package/build/lib/__tests__/utils.d.ts +0 -28
- package/build/lib/errorBoundaryUtils.d.ts +0 -10
- package/build/lib/errorBoundaryUtils.esm.js +0 -28
- package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
- package/build/lib/errorBoundaryUtils.js +0 -51
- package/build/lib/errorBoundaryUtils.js.map +0 -1
- package/build/lib/errorBoundaryUtils.mjs +0 -28
- package/build/lib/errorBoundaryUtils.mjs.map +0 -1
- package/build/lib/index.d.ts +0 -16
- package/build/lib/index.esm.js +0 -12
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.js +0 -38
- package/build/lib/index.js.map +0 -1
- package/build/lib/index.mjs +0 -12
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/isRestoring.d.ts +0 -3
- package/build/lib/isRestoring.esm.js +0 -9
- package/build/lib/isRestoring.esm.js.map +0 -1
- package/build/lib/isRestoring.js +0 -31
- package/build/lib/isRestoring.js.map +0 -1
- package/build/lib/isRestoring.mjs +0 -9
- package/build/lib/isRestoring.mjs.map +0 -1
- package/build/lib/suspense.d.ts +0 -9
- package/build/lib/suspense.esm.js +0 -24
- package/build/lib/suspense.esm.js.map +0 -1
- package/build/lib/suspense.js +0 -29
- package/build/lib/suspense.js.map +0 -1
- package/build/lib/suspense.mjs +0 -24
- package/build/lib/suspense.mjs.map +0 -1
- package/build/lib/types.d.ts +0 -26
- package/build/lib/useBaseQuery.d.ts +0 -3
- package/build/lib/useBaseQuery.esm.js +0 -63
- package/build/lib/useBaseQuery.esm.js.map +0 -1
- package/build/lib/useBaseQuery.js +0 -84
- package/build/lib/useBaseQuery.js.map +0 -1
- package/build/lib/useBaseQuery.mjs +0 -63
- package/build/lib/useBaseQuery.mjs.map +0 -1
- package/build/lib/useInfiniteQuery.d.ts +0 -3
- package/build/lib/useInfiniteQuery.esm.js +0 -13
- package/build/lib/useInfiniteQuery.esm.js.map +0 -1
- package/build/lib/useInfiniteQuery.js +0 -15
- package/build/lib/useInfiniteQuery.js.map +0 -1
- package/build/lib/useInfiniteQuery.mjs +0 -13
- package/build/lib/useInfiniteQuery.mjs.map +0 -1
- package/build/lib/useIsFetching.d.ts +0 -2
- package/build/lib/useIsFetching.esm.js +0 -13
- package/build/lib/useIsFetching.esm.js.map +0 -1
- package/build/lib/useIsFetching.js +0 -34
- package/build/lib/useIsFetching.js.map +0 -1
- package/build/lib/useIsFetching.mjs +0 -13
- package/build/lib/useIsFetching.mjs.map +0 -1
- package/build/lib/useMutation.d.ts +0 -3
- package/build/lib/useMutation.esm.js +0 -33
- package/build/lib/useMutation.esm.js.map +0 -1
- package/build/lib/useMutation.js +0 -54
- package/build/lib/useMutation.js.map +0 -1
- package/build/lib/useMutation.mjs +0 -33
- package/build/lib/useMutation.mjs.map +0 -1
- package/build/lib/useMutationState.d.ts +0 -8
- package/build/lib/useMutationState.esm.js +0 -38
- package/build/lib/useMutationState.esm.js.map +0 -1
- package/build/lib/useMutationState.js +0 -60
- package/build/lib/useMutationState.js.map +0 -1
- package/build/lib/useMutationState.mjs +0 -38
- package/build/lib/useMutationState.mjs.map +0 -1
- package/build/lib/useQueries.esm.js +0 -73
- package/build/lib/useQueries.esm.js.map +0 -1
- package/build/lib/useQueries.js +0 -94
- package/build/lib/useQueries.js.map +0 -1
- package/build/lib/useQueries.mjs +0 -70
- package/build/lib/useQueries.mjs.map +0 -1
- package/build/lib/useQuery.d.ts +0 -11
- package/build/lib/useQuery.esm.js +0 -12
- package/build/lib/useQuery.esm.js.map +0 -1
- package/build/lib/useQuery.js +0 -14
- package/build/lib/useQuery.js.map +0 -1
- package/build/lib/useQuery.mjs +0 -12
- package/build/lib/useQuery.mjs.map +0 -1
- package/build/lib/utils.d.ts +0 -1
- package/build/lib/utils.esm.js +0 -10
- package/build/lib/utils.esm.js.map +0 -1
- package/build/lib/utils.js +0 -12
- package/build/lib/utils.js.map +0 -1
- package/build/lib/utils.mjs +0 -10
- package/build/lib/utils.mjs.map +0 -1
- package/build/umd/index.development.js +0 -3040
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -2
- package/build/umd/index.production.js.map +0 -1
- /package/src/{isRestoring.tsx → isRestoring.ts} +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import ReactDOM from 'react-dom'
|
|
3
|
-
import ReactDOMTestUtils from 'react-dom/test-utils'
|
|
4
|
-
import ReactDOMServer from 'react-dom/server'
|
|
3
|
+
import * as ReactDOMTestUtils from 'react-dom/test-utils'
|
|
4
|
+
import * as ReactDOMServer from 'react-dom/server'
|
|
5
5
|
// eslint-disable-next-line import/no-unresolved -- types only for module augmentation
|
|
6
6
|
import type {} from 'react-dom/next'
|
|
7
7
|
import { vi } from 'vitest'
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
useQuery,
|
|
11
|
-
QueryClientProvider,
|
|
12
10
|
QueryCache,
|
|
11
|
+
QueryClientProvider,
|
|
13
12
|
dehydrate,
|
|
14
13
|
hydrate,
|
|
14
|
+
useQuery,
|
|
15
15
|
} from '..'
|
|
16
16
|
import { createQueryClient, setIsServer, sleep } from './utils'
|
|
17
17
|
|
|
@@ -2,9 +2,9 @@ import * as React from 'react'
|
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
import { renderToString } from 'react-dom/server'
|
|
4
4
|
|
|
5
|
-
import { sleep, queryKey, createQueryClient } from './utils'
|
|
6
|
-
import { useQuery, QueryClientProvider, QueryCache, useInfiniteQuery } from '..'
|
|
7
5
|
import { vi } from 'vitest'
|
|
6
|
+
import { QueryCache, QueryClientProvider, useInfiniteQuery, useQuery } from '..'
|
|
7
|
+
import { createQueryClient, queryKey, sleep } from './utils'
|
|
8
8
|
|
|
9
9
|
describe('Server Side Rendering', () => {
|
|
10
10
|
it('should not trigger fetch', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fireEvent, waitFor } from '@testing-library/react'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
import { ErrorBoundary } from 'react-error-boundary'
|
|
4
|
-
import
|
|
4
|
+
import { vi } from 'vitest'
|
|
5
5
|
import {
|
|
6
6
|
QueryCache,
|
|
7
7
|
QueryErrorResetBoundary,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
useQueryErrorResetBoundary,
|
|
12
12
|
} from '..'
|
|
13
13
|
import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
|
|
14
|
-
import {
|
|
14
|
+
import type { InfiniteData, UseInfiniteQueryResult, UseQueryResult } from '..'
|
|
15
15
|
|
|
16
16
|
describe("useQuery's in Suspense mode", () => {
|
|
17
17
|
const queryCache = new QueryCache()
|
|
@@ -190,88 +190,6 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
190
190
|
expect(queryCache.find({ queryKey: key })?.getObserversCount()).toBe(0)
|
|
191
191
|
})
|
|
192
192
|
|
|
193
|
-
it('should call onSuccess on the first successful call', async () => {
|
|
194
|
-
const key = queryKey()
|
|
195
|
-
|
|
196
|
-
const successFn = vi.fn()
|
|
197
|
-
|
|
198
|
-
function Page() {
|
|
199
|
-
useQuery({
|
|
200
|
-
queryKey: [key],
|
|
201
|
-
queryFn: async () => {
|
|
202
|
-
await sleep(10)
|
|
203
|
-
return key
|
|
204
|
-
},
|
|
205
|
-
suspense: true,
|
|
206
|
-
select: () => 'selected',
|
|
207
|
-
onSuccess: successFn,
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
return <>rendered</>
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const rendered = renderWithClient(
|
|
214
|
-
queryClient,
|
|
215
|
-
<React.Suspense fallback="loading">
|
|
216
|
-
<Page />
|
|
217
|
-
</React.Suspense>,
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
await waitFor(() => rendered.getByText('rendered'))
|
|
221
|
-
|
|
222
|
-
await waitFor(() => expect(successFn).toHaveBeenCalledTimes(1))
|
|
223
|
-
await waitFor(() => expect(successFn).toHaveBeenCalledWith('selected'))
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('should call every onSuccess handler within a suspense boundary', async () => {
|
|
227
|
-
const key = queryKey()
|
|
228
|
-
|
|
229
|
-
const successFn1 = vi.fn()
|
|
230
|
-
const successFn2 = vi.fn()
|
|
231
|
-
|
|
232
|
-
function FirstComponent() {
|
|
233
|
-
useQuery({
|
|
234
|
-
queryKey: key,
|
|
235
|
-
queryFn: () => {
|
|
236
|
-
sleep(10)
|
|
237
|
-
return 'data'
|
|
238
|
-
},
|
|
239
|
-
suspense: true,
|
|
240
|
-
onSuccess: successFn1,
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
return <span>first</span>
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function SecondComponent() {
|
|
247
|
-
useQuery({
|
|
248
|
-
queryKey: key,
|
|
249
|
-
queryFn: () => {
|
|
250
|
-
sleep(10)
|
|
251
|
-
return 'data'
|
|
252
|
-
},
|
|
253
|
-
|
|
254
|
-
suspense: true,
|
|
255
|
-
onSuccess: successFn2,
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
return <span>second</span>
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const rendered = renderWithClient(
|
|
262
|
-
queryClient,
|
|
263
|
-
<React.Suspense fallback="loading">
|
|
264
|
-
<FirstComponent />
|
|
265
|
-
<SecondComponent />
|
|
266
|
-
</React.Suspense>,
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
await waitFor(() => rendered.getByText('second'))
|
|
270
|
-
|
|
271
|
-
await waitFor(() => expect(successFn1).toHaveBeenCalledTimes(1))
|
|
272
|
-
await waitFor(() => expect(successFn2).toHaveBeenCalledTimes(1))
|
|
273
|
-
})
|
|
274
|
-
|
|
275
193
|
// https://github.com/tannerlinsley/react-query/issues/468
|
|
276
194
|
it('should reset error state if new component instances are mounted', async () => {
|
|
277
195
|
const consoleMock = vi
|
|
@@ -616,7 +534,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
616
534
|
consoleMock.mockRestore()
|
|
617
535
|
})
|
|
618
536
|
|
|
619
|
-
it('should not throw errors to the error boundary when
|
|
537
|
+
it('should not throw errors to the error boundary when throwOnError: false', async () => {
|
|
620
538
|
const key = queryKey()
|
|
621
539
|
|
|
622
540
|
function Page() {
|
|
@@ -628,7 +546,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
628
546
|
},
|
|
629
547
|
retry: false,
|
|
630
548
|
suspense: true,
|
|
631
|
-
|
|
549
|
+
throwOnError: false,
|
|
632
550
|
})
|
|
633
551
|
return <div>rendered</div>
|
|
634
552
|
}
|
|
@@ -655,7 +573,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
655
573
|
await waitFor(() => rendered.getByText('rendered'))
|
|
656
574
|
})
|
|
657
575
|
|
|
658
|
-
it('should throw errors to the error boundary when a
|
|
576
|
+
it('should throw errors to the error boundary when a throwOnError function returns true', async () => {
|
|
659
577
|
const consoleMock = vi
|
|
660
578
|
.spyOn(console, 'error')
|
|
661
579
|
.mockImplementation(() => undefined)
|
|
@@ -670,7 +588,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
670
588
|
},
|
|
671
589
|
retry: false,
|
|
672
590
|
suspense: true,
|
|
673
|
-
|
|
591
|
+
throwOnError: (err) => err.message !== 'Local Error',
|
|
674
592
|
})
|
|
675
593
|
return <div>rendered</div>
|
|
676
594
|
}
|
|
@@ -698,7 +616,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
698
616
|
consoleMock.mockRestore()
|
|
699
617
|
})
|
|
700
618
|
|
|
701
|
-
it('should not throw errors to the error boundary when a
|
|
619
|
+
it('should not throw errors to the error boundary when a throwOnError function returns false', async () => {
|
|
702
620
|
const key = queryKey()
|
|
703
621
|
|
|
704
622
|
function Page() {
|
|
@@ -710,7 +628,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
710
628
|
},
|
|
711
629
|
retry: false,
|
|
712
630
|
suspense: true,
|
|
713
|
-
|
|
631
|
+
throwOnError: (err) => err.message !== 'Local Error',
|
|
714
632
|
})
|
|
715
633
|
return <div>rendered</div>
|
|
716
634
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { fireEvent, render, waitFor } from '@testing-library/react'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
+
import { vi } from 'vitest'
|
|
5
|
+
import { QueryCache, keepPreviousData, useInfiniteQuery } from '..'
|
|
4
6
|
import {
|
|
5
7
|
createQueryClient,
|
|
6
8
|
queryKey,
|
|
@@ -13,8 +15,6 @@ import type {
|
|
|
13
15
|
QueryFunctionContext,
|
|
14
16
|
UseInfiniteQueryResult,
|
|
15
17
|
} from '..'
|
|
16
|
-
import { QueryCache, useInfiniteQuery, keepPreviousData } from '..'
|
|
17
|
-
import { vi } from 'vitest'
|
|
18
18
|
import type { Mock } from 'vitest'
|
|
19
19
|
|
|
20
20
|
interface Result {
|
|
@@ -213,7 +213,7 @@ describe('useInfiniteQuery', () => {
|
|
|
213
213
|
|
|
214
214
|
await waitFor(() => rendered.getByText('data: 0-asc'))
|
|
215
215
|
await waitFor(() => rendered.getByText('isFetching: false'))
|
|
216
|
-
await waitFor(() => expect(states.length).toBe(
|
|
216
|
+
await waitFor(() => expect(states.length).toBe(6))
|
|
217
217
|
|
|
218
218
|
expect(states[0]).toMatchObject({
|
|
219
219
|
data: undefined,
|
|
@@ -251,15 +251,7 @@ describe('useInfiniteQuery', () => {
|
|
|
251
251
|
isSuccess: true,
|
|
252
252
|
isPlaceholderData: true,
|
|
253
253
|
})
|
|
254
|
-
// Hook state update
|
|
255
254
|
expect(states[5]).toMatchObject({
|
|
256
|
-
data: { pages: ['0-desc', '1-desc'] },
|
|
257
|
-
isFetching: true,
|
|
258
|
-
isFetchingNextPage: false,
|
|
259
|
-
isSuccess: true,
|
|
260
|
-
isPlaceholderData: true,
|
|
261
|
-
})
|
|
262
|
-
expect(states[6]).toMatchObject({
|
|
263
255
|
data: { pages: ['0-asc'] },
|
|
264
256
|
isFetching: false,
|
|
265
257
|
isFetchingNextPage: false,
|
|
@@ -606,77 +598,47 @@ describe('useInfiniteQuery', () => {
|
|
|
606
598
|
|
|
607
599
|
it('should silently cancel any ongoing fetch when fetching more', async () => {
|
|
608
600
|
const key = queryKey()
|
|
609
|
-
const states: UseInfiniteQueryResult<InfiniteData<number>>[] = []
|
|
610
601
|
|
|
611
602
|
function Page() {
|
|
612
603
|
const start = 10
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
states.push(state)
|
|
625
|
-
|
|
626
|
-
const { refetch, fetchNextPage } = state
|
|
627
|
-
|
|
628
|
-
React.useEffect(() => {
|
|
629
|
-
setActTimeout(() => {
|
|
630
|
-
refetch()
|
|
631
|
-
}, 100)
|
|
632
|
-
setActTimeout(() => {
|
|
633
|
-
fetchNextPage()
|
|
634
|
-
}, 110)
|
|
635
|
-
}, [fetchNextPage, refetch])
|
|
604
|
+
const { data, fetchNextPage, refetch, status, fetchStatus } =
|
|
605
|
+
useInfiniteQuery({
|
|
606
|
+
queryKey: key,
|
|
607
|
+
queryFn: async ({ pageParam }) => {
|
|
608
|
+
await sleep(50)
|
|
609
|
+
return Number(pageParam)
|
|
610
|
+
},
|
|
611
|
+
defaultPageParam: start,
|
|
612
|
+
getNextPageParam: (lastPage) => lastPage + 1,
|
|
613
|
+
})
|
|
636
614
|
|
|
637
|
-
return
|
|
615
|
+
return (
|
|
616
|
+
<div>
|
|
617
|
+
<button onClick={() => fetchNextPage()}>fetchNextPage</button>
|
|
618
|
+
<button onClick={() => refetch()}>refetch</button>
|
|
619
|
+
<div>data: {JSON.stringify(data)}</div>
|
|
620
|
+
<div>
|
|
621
|
+
status: {status}, {fetchStatus}
|
|
622
|
+
</div>
|
|
623
|
+
</div>
|
|
624
|
+
)
|
|
638
625
|
}
|
|
639
626
|
|
|
640
|
-
renderWithClient(queryClient, <Page />)
|
|
627
|
+
const rendered = renderWithClient(queryClient, <Page />)
|
|
641
628
|
|
|
642
|
-
await
|
|
629
|
+
await waitFor(() => rendered.getByText('status: success, idle'))
|
|
630
|
+
await waitFor(() =>
|
|
631
|
+
rendered.getByText('data: {"pages":[10],"pageParams":[10]}'),
|
|
632
|
+
)
|
|
643
633
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
expect(states[1]).toMatchObject({
|
|
653
|
-
hasNextPage: true,
|
|
654
|
-
data: { pages: [10] },
|
|
655
|
-
isFetching: false,
|
|
656
|
-
isFetchingNextPage: false,
|
|
657
|
-
isSuccess: true,
|
|
658
|
-
})
|
|
659
|
-
expect(states[2]).toMatchObject({
|
|
660
|
-
hasNextPage: true,
|
|
661
|
-
data: { pages: [10] },
|
|
662
|
-
isFetching: true,
|
|
663
|
-
isFetchingNextPage: false,
|
|
664
|
-
isSuccess: true,
|
|
665
|
-
})
|
|
666
|
-
expect(states[3]).toMatchObject({
|
|
667
|
-
hasNextPage: true,
|
|
668
|
-
data: { pages: [10] },
|
|
669
|
-
isFetching: true,
|
|
670
|
-
isFetchingNextPage: true,
|
|
671
|
-
isSuccess: true,
|
|
672
|
-
})
|
|
673
|
-
expect(states[4]).toMatchObject({
|
|
674
|
-
hasNextPage: true,
|
|
675
|
-
data: { pages: [10, 11] },
|
|
676
|
-
isFetching: false,
|
|
677
|
-
isFetchingNextPage: false,
|
|
678
|
-
isSuccess: true,
|
|
679
|
-
})
|
|
634
|
+
fireEvent.click(rendered.getByRole('button', { name: /refetch/i }))
|
|
635
|
+
await waitFor(() => rendered.getByText('status: success, fetching'))
|
|
636
|
+
fireEvent.click(rendered.getByRole('button', { name: /fetchNextPage/i }))
|
|
637
|
+
|
|
638
|
+
await waitFor(() => rendered.getByText('status: success, idle'))
|
|
639
|
+
await waitFor(() =>
|
|
640
|
+
rendered.getByText('data: {"pages":[10,11],"pageParams":[10,11]}'),
|
|
641
|
+
)
|
|
680
642
|
})
|
|
681
643
|
|
|
682
644
|
it('should silently cancel an ongoing fetchNextPage request when another fetchNextPage is invoked', async () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { InfiniteData } from '@tanstack/query-core'
|
|
2
1
|
import { QueryClient } from '@tanstack/query-core'
|
|
3
2
|
import { useInfiniteQuery } from '../useInfiniteQuery'
|
|
4
3
|
import { useQuery } from '../useQuery'
|
|
5
|
-
import type { Expect, Equal } from './utils'
|
|
6
4
|
import { doNotExecute } from './utils'
|
|
5
|
+
import type { Equal, Expect } from './utils'
|
|
6
|
+
import type { InfiniteData } from '@tanstack/query-core'
|
|
7
7
|
|
|
8
8
|
describe('pageParam', () => {
|
|
9
9
|
it('defaultPageParam should define type of param passed to queryFunctionContext', () => {
|
|
@@ -128,33 +128,6 @@ describe('select', () => {
|
|
|
128
128
|
return result
|
|
129
129
|
})
|
|
130
130
|
})
|
|
131
|
-
it('should pass transformed data to onSuccess', () => {
|
|
132
|
-
doNotExecute(() => {
|
|
133
|
-
const infiniteQuery = useInfiniteQuery({
|
|
134
|
-
queryKey: ['key'],
|
|
135
|
-
queryFn: ({ pageParam }) => {
|
|
136
|
-
return pageParam * 5
|
|
137
|
-
},
|
|
138
|
-
defaultPageParam: 1,
|
|
139
|
-
getNextPageParam: () => undefined,
|
|
140
|
-
select: (data) => {
|
|
141
|
-
return {
|
|
142
|
-
...data,
|
|
143
|
-
pages: data.pages.map((page) => page.toString()),
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
onSuccess: (data) => {
|
|
147
|
-
const result: Expect<Equal<InfiniteData<string>, typeof data>> = true
|
|
148
|
-
doNotExecute(() => result)
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
const result: Expect<
|
|
153
|
-
Equal<InfiniteData<string> | undefined, (typeof infiniteQuery)['data']>
|
|
154
|
-
> = true
|
|
155
|
-
return result
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
131
|
})
|
|
159
132
|
describe('getNextPageParam / getPreviousPageParam', () => {
|
|
160
133
|
it('should get typed params', () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fireEvent, render, waitFor } from '@testing-library/react'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
+
import { QueryCache, useIsFetching, useQuery } from '..'
|
|
4
5
|
import {
|
|
5
6
|
createQueryClient,
|
|
6
7
|
queryKey,
|
|
@@ -8,7 +9,6 @@ import {
|
|
|
8
9
|
setActTimeout,
|
|
9
10
|
sleep,
|
|
10
11
|
} from './utils'
|
|
11
|
-
import { QueryCache, useIsFetching, useQuery } from '..'
|
|
12
12
|
|
|
13
13
|
describe('useIsFetching', () => {
|
|
14
14
|
// See https://github.com/tannerlinsley/react-query/issues/105
|
|
@@ -3,17 +3,17 @@ import '@testing-library/jest-dom'
|
|
|
3
3
|
import * as React from 'react'
|
|
4
4
|
import { ErrorBoundary } from 'react-error-boundary'
|
|
5
5
|
|
|
6
|
+
import { vi } from 'vitest'
|
|
6
7
|
import { MutationCache, QueryCache, useMutation } from '..'
|
|
7
|
-
import type { UseMutationResult } from '../types'
|
|
8
8
|
import {
|
|
9
9
|
createQueryClient,
|
|
10
|
-
|
|
10
|
+
mockOnlineManagerIsOnline,
|
|
11
11
|
queryKey,
|
|
12
12
|
renderWithClient,
|
|
13
13
|
setActTimeout,
|
|
14
14
|
sleep,
|
|
15
15
|
} from './utils'
|
|
16
|
-
import {
|
|
16
|
+
import type { UseMutationResult } from '../types'
|
|
17
17
|
|
|
18
18
|
describe('useMutation', () => {
|
|
19
19
|
const queryCache = new QueryCache()
|
|
@@ -427,7 +427,7 @@ describe('useMutation', () => {
|
|
|
427
427
|
})
|
|
428
428
|
|
|
429
429
|
it('should not retry mutations while offline', async () => {
|
|
430
|
-
const onlineMock =
|
|
430
|
+
const onlineMock = mockOnlineManagerIsOnline(false)
|
|
431
431
|
|
|
432
432
|
let count = 0
|
|
433
433
|
|
|
@@ -455,6 +455,8 @@ describe('useMutation', () => {
|
|
|
455
455
|
|
|
456
456
|
const rendered = renderWithClient(queryClient, <Page />)
|
|
457
457
|
|
|
458
|
+
window.dispatchEvent(new Event('offline'))
|
|
459
|
+
|
|
458
460
|
await waitFor(() => {
|
|
459
461
|
expect(
|
|
460
462
|
rendered.getByText('error: null, status: idle, isPaused: false'),
|
|
@@ -471,7 +473,7 @@ describe('useMutation', () => {
|
|
|
471
473
|
|
|
472
474
|
expect(count).toBe(0)
|
|
473
475
|
|
|
474
|
-
onlineMock.
|
|
476
|
+
onlineMock.mockRestore()
|
|
475
477
|
window.dispatchEvent(new Event('online'))
|
|
476
478
|
|
|
477
479
|
await sleep(100)
|
|
@@ -483,12 +485,10 @@ describe('useMutation', () => {
|
|
|
483
485
|
})
|
|
484
486
|
|
|
485
487
|
expect(count).toBe(2)
|
|
486
|
-
|
|
487
|
-
onlineMock.mockRestore()
|
|
488
488
|
})
|
|
489
489
|
|
|
490
490
|
it('should call onMutate even if paused', async () => {
|
|
491
|
-
const onlineMock =
|
|
491
|
+
const onlineMock = mockOnlineManagerIsOnline(false)
|
|
492
492
|
const onMutate = vi.fn()
|
|
493
493
|
let count = 0
|
|
494
494
|
|
|
@@ -517,6 +517,8 @@ describe('useMutation', () => {
|
|
|
517
517
|
|
|
518
518
|
await rendered.findByText('data: null, status: idle, isPaused: false')
|
|
519
519
|
|
|
520
|
+
window.dispatchEvent(new Event('offline'))
|
|
521
|
+
|
|
520
522
|
fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
|
|
521
523
|
|
|
522
524
|
await rendered.findByText('data: null, status: pending, isPaused: true')
|
|
@@ -524,19 +526,17 @@ describe('useMutation', () => {
|
|
|
524
526
|
expect(onMutate).toHaveBeenCalledTimes(1)
|
|
525
527
|
expect(onMutate).toHaveBeenCalledWith('todo')
|
|
526
528
|
|
|
527
|
-
onlineMock.
|
|
529
|
+
onlineMock.mockRestore()
|
|
528
530
|
window.dispatchEvent(new Event('online'))
|
|
529
531
|
|
|
530
532
|
await rendered.findByText('data: 1, status: success, isPaused: false')
|
|
531
533
|
|
|
532
534
|
expect(onMutate).toHaveBeenCalledTimes(1)
|
|
533
535
|
expect(count).toBe(1)
|
|
534
|
-
|
|
535
|
-
onlineMock.mockRestore()
|
|
536
536
|
})
|
|
537
537
|
|
|
538
538
|
it('should optimistically go to paused state if offline', async () => {
|
|
539
|
-
const onlineMock =
|
|
539
|
+
const onlineMock = mockOnlineManagerIsOnline(false)
|
|
540
540
|
let count = 0
|
|
541
541
|
const states: Array<string> = []
|
|
542
542
|
|
|
@@ -566,6 +566,8 @@ describe('useMutation', () => {
|
|
|
566
566
|
|
|
567
567
|
await rendered.findByText('data: null, status: idle, isPaused: false')
|
|
568
568
|
|
|
569
|
+
window.dispatchEvent(new Event('offline'))
|
|
570
|
+
|
|
569
571
|
fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
|
|
570
572
|
|
|
571
573
|
await rendered.findByText('data: null, status: pending, isPaused: true')
|
|
@@ -574,16 +576,14 @@ describe('useMutation', () => {
|
|
|
574
576
|
expect(states[0]).toBe('idle, false')
|
|
575
577
|
expect(states[1]).toBe('pending, true')
|
|
576
578
|
|
|
577
|
-
onlineMock.
|
|
579
|
+
onlineMock.mockRestore()
|
|
578
580
|
window.dispatchEvent(new Event('online'))
|
|
579
581
|
|
|
580
582
|
await rendered.findByText('data: 1, status: success, isPaused: false')
|
|
581
|
-
|
|
582
|
-
onlineMock.mockRestore()
|
|
583
583
|
})
|
|
584
584
|
|
|
585
585
|
it('should be able to retry a mutation when online', async () => {
|
|
586
|
-
const onlineMock =
|
|
586
|
+
const onlineMock = mockOnlineManagerIsOnline(false)
|
|
587
587
|
|
|
588
588
|
let count = 0
|
|
589
589
|
const states: UseMutationResult<any, any, any, any>[] = []
|
|
@@ -608,6 +608,7 @@ describe('useMutation', () => {
|
|
|
608
608
|
|
|
609
609
|
React.useEffect(() => {
|
|
610
610
|
setActTimeout(() => {
|
|
611
|
+
window.dispatchEvent(new Event('offline'))
|
|
611
612
|
mutate('todo')
|
|
612
613
|
}, 10)
|
|
613
614
|
}, [mutate])
|
|
@@ -645,7 +646,7 @@ describe('useMutation', () => {
|
|
|
645
646
|
failureReason: new Error('oops'),
|
|
646
647
|
})
|
|
647
648
|
|
|
648
|
-
onlineMock.
|
|
649
|
+
onlineMock.mockRestore()
|
|
649
650
|
window.dispatchEvent(new Event('online'))
|
|
650
651
|
|
|
651
652
|
await sleep(50)
|
|
@@ -664,8 +665,6 @@ describe('useMutation', () => {
|
|
|
664
665
|
failureReason: null,
|
|
665
666
|
data: 'data',
|
|
666
667
|
})
|
|
667
|
-
|
|
668
|
-
onlineMock.mockRestore()
|
|
669
668
|
})
|
|
670
669
|
|
|
671
670
|
it('should not change state if unmounted', async () => {
|
|
@@ -688,7 +687,7 @@ describe('useMutation', () => {
|
|
|
688
687
|
fireEvent.click(getByText('unmount'))
|
|
689
688
|
})
|
|
690
689
|
|
|
691
|
-
it('should be able to throw an error when
|
|
690
|
+
it('should be able to throw an error when throwOnError is set to true', async () => {
|
|
692
691
|
const consoleMock = vi
|
|
693
692
|
.spyOn(console, 'error')
|
|
694
693
|
.mockImplementation(() => undefined)
|
|
@@ -699,7 +698,7 @@ describe('useMutation', () => {
|
|
|
699
698
|
err.stack = ''
|
|
700
699
|
return Promise.reject(err)
|
|
701
700
|
},
|
|
702
|
-
|
|
701
|
+
throwOnError: true,
|
|
703
702
|
})
|
|
704
703
|
|
|
705
704
|
return (
|
|
@@ -735,7 +734,7 @@ describe('useMutation', () => {
|
|
|
735
734
|
consoleMock.mockRestore()
|
|
736
735
|
})
|
|
737
736
|
|
|
738
|
-
it('should be able to throw an error when
|
|
737
|
+
it('should be able to throw an error when throwOnError is a function that returns true', async () => {
|
|
739
738
|
const consoleMock = vi
|
|
740
739
|
.spyOn(console, 'error')
|
|
741
740
|
.mockImplementation(() => undefined)
|
|
@@ -747,7 +746,7 @@ describe('useMutation', () => {
|
|
|
747
746
|
err.stack = ''
|
|
748
747
|
return Promise.reject(err)
|
|
749
748
|
},
|
|
750
|
-
|
|
749
|
+
throwOnError: () => {
|
|
751
750
|
boundary = !boundary
|
|
752
751
|
return !boundary
|
|
753
752
|
},
|
|
@@ -4,10 +4,12 @@ import { useIsMutating, useMutationState } from '../useMutationState'
|
|
|
4
4
|
import { useMutation } from '../useMutation'
|
|
5
5
|
import {
|
|
6
6
|
createQueryClient,
|
|
7
|
+
doNotExecute,
|
|
7
8
|
renderWithClient,
|
|
8
9
|
setActTimeout,
|
|
9
10
|
sleep,
|
|
10
11
|
} from './utils'
|
|
12
|
+
import type { MutationState, MutationStatus } from '@tanstack/query-core'
|
|
11
13
|
|
|
12
14
|
describe('useIsMutating', () => {
|
|
13
15
|
it('should return the number of fetching mutations', async () => {
|
|
@@ -172,6 +174,27 @@ describe('useIsMutating', () => {
|
|
|
172
174
|
})
|
|
173
175
|
|
|
174
176
|
describe('useMutationState', () => {
|
|
177
|
+
describe('types', () => {
|
|
178
|
+
it('should default to QueryState', () => {
|
|
179
|
+
doNotExecute(() => {
|
|
180
|
+
const result = useMutationState({
|
|
181
|
+
filters: { status: 'pending' },
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
expectTypeOf(result).toEqualTypeOf<Array<MutationState>>()
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
it('should infer with select', () => {
|
|
188
|
+
doNotExecute(() => {
|
|
189
|
+
const result = useMutationState({
|
|
190
|
+
filters: { status: 'pending' },
|
|
191
|
+
select: (mutation) => mutation.state.status,
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
expectTypeOf(result).toEqualTypeOf<Array<MutationStatus>>()
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
})
|
|
175
198
|
it('should return variables after calling mutate', async () => {
|
|
176
199
|
const queryClient = createQueryClient()
|
|
177
200
|
const variables: unknown[][] = []
|