@tanstack/react-query 5.75.5 → 5.75.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.
- package/build/legacy/errorBoundaryUtils.cjs +2 -2
- package/build/legacy/errorBoundaryUtils.cjs.map +1 -1
- package/build/legacy/errorBoundaryUtils.js +1 -1
- package/build/legacy/errorBoundaryUtils.js.map +1 -1
- package/build/legacy/useMutation.cjs +1 -1
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.js +6 -2
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/utils.cjs +2 -10
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -2
- package/build/legacy/utils.d.ts +1 -2
- package/build/legacy/utils.js +1 -8
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/errorBoundaryUtils.cjs +2 -2
- package/build/modern/errorBoundaryUtils.cjs.map +1 -1
- package/build/modern/errorBoundaryUtils.js +1 -1
- package/build/modern/errorBoundaryUtils.js.map +1 -1
- package/build/modern/useMutation.cjs +1 -1
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.js +6 -2
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/utils.cjs +2 -10
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -2
- package/build/modern/utils.d.ts +1 -2
- package/build/modern/utils.js +1 -8
- package/build/modern/utils.js.map +1 -1
- package/build/query-codemods/eslint.config.js +1 -1
- package/build/query-codemods/root.eslint.config.js +1 -0
- package/package.json +4 -3
- package/src/errorBoundaryUtils.ts +1 -1
- package/src/useMutation.ts +6 -2
- package/src/utils.ts +0 -12
|
@@ -37,7 +37,7 @@ __export(errorBoundaryUtils_exports, {
|
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(errorBoundaryUtils_exports);
|
|
39
39
|
var React = __toESM(require("react"), 1);
|
|
40
|
-
var
|
|
40
|
+
var import_query_core = require("@tanstack/query-core");
|
|
41
41
|
var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
42
42
|
if (options.suspense || options.throwOnError || options.experimental_prefetchInRender) {
|
|
43
43
|
if (!errorResetBoundary.isReset()) {
|
|
@@ -57,7 +57,7 @@ var getHasError = ({
|
|
|
57
57
|
query,
|
|
58
58
|
suspense
|
|
59
59
|
}) => {
|
|
60
|
-
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && (suspense && result.data === void 0 || (0,
|
|
60
|
+
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && (suspense && result.data === void 0 || (0, import_query_core.shouldThrowError)(throwOnError, [result.error, query]));
|
|
61
61
|
};
|
|
62
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
63
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '
|
|
1
|
+
{"version":3,"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n ThrowOnError,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\n\nexport const ensurePreventErrorBoundaryRetry = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n if (\n options.suspense ||\n options.throwOnError ||\n options.experimental_prefetchInRender\n ) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n options.retryOnMount = false\n }\n }\n}\n\nexport const useClearResetErrorBoundary = (\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n}\n\nexport const getHasError = <\n TData,\n TError,\n TQueryFnData,\n TQueryData,\n TQueryKey extends QueryKey,\n>({\n result,\n errorResetBoundary,\n throwOnError,\n query,\n suspense,\n}: {\n result: QueryObserverResult<TData, TError>\n errorResetBoundary: QueryErrorResetBoundaryValue\n throwOnError: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined\n suspense: boolean | undefined\n}) => {\n return (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n query &&\n ((suspense && result.data === undefined) ||\n shouldThrowError(throwOnError, [result.error, query]))\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AACvB,wBAAiC;AAU1B,IAAM,kCAAkC,CAO7C,SAOA,uBACG;AACH,MACE,QAAQ,YACR,QAAQ,gBACR,QAAQ,+BACR;AAEA,QAAI,CAAC,mBAAmB,QAAQ,GAAG;AACjC,cAAQ,eAAe;AAAA,IACzB;AAAA,EACF;AACF;AAEO,IAAM,6BAA6B,CACxC,uBACG;AACH,EAAM,gBAAU,MAAM;AACpB,uBAAmB,WAAW;AAAA,EAChC,GAAG,CAAC,kBAAkB,CAAC;AACzB;AAEO,IAAM,cAAc,CAMzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAMM;AACJ,SACE,OAAO,WACP,CAAC,mBAAmB,QAAQ,KAC5B,CAAC,OAAO,cACR,UACE,YAAY,OAAO,SAAS,cAC5B,oCAAiB,cAAc,CAAC,OAAO,OAAO,KAAK,CAAC;AAE1D;","names":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/errorBoundaryUtils.ts
|
|
4
4
|
import * as React from "react";
|
|
5
|
-
import { shouldThrowError } from "
|
|
5
|
+
import { shouldThrowError } from "@tanstack/query-core";
|
|
6
6
|
var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
7
7
|
if (options.suspense || options.throwOnError || options.experimental_prefetchInRender) {
|
|
8
8
|
if (!errorResetBoundary.isReset()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '
|
|
1
|
+
{"version":3,"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n ThrowOnError,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\n\nexport const ensurePreventErrorBoundaryRetry = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n if (\n options.suspense ||\n options.throwOnError ||\n options.experimental_prefetchInRender\n ) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n options.retryOnMount = false\n }\n }\n}\n\nexport const useClearResetErrorBoundary = (\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n}\n\nexport const getHasError = <\n TData,\n TError,\n TQueryFnData,\n TQueryData,\n TQueryKey extends QueryKey,\n>({\n result,\n errorResetBoundary,\n throwOnError,\n query,\n suspense,\n}: {\n result: QueryObserverResult<TData, TError>\n errorResetBoundary: QueryErrorResetBoundaryValue\n throwOnError: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined\n suspense: boolean | undefined\n}) => {\n return (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n query &&\n ((suspense && result.data === undefined) ||\n shouldThrowError(throwOnError, [result.error, query]))\n )\n}\n"],"mappings":";;;AACA,YAAY,WAAW;AACvB,SAAS,wBAAwB;AAU1B,IAAM,kCAAkC,CAO7C,SAOA,uBACG;AACH,MACE,QAAQ,YACR,QAAQ,gBACR,QAAQ,+BACR;AAEA,QAAI,CAAC,mBAAmB,QAAQ,GAAG;AACjC,cAAQ,eAAe;AAAA,IACzB;AAAA,EACF;AACF;AAEO,IAAM,6BAA6B,CACxC,uBACG;AACH,EAAM,gBAAU,MAAM;AACpB,uBAAmB,WAAW;AAAA,EAChC,GAAG,CAAC,kBAAkB,CAAC;AACzB;AAEO,IAAM,cAAc,CAMzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAMM;AACJ,SACE,OAAO,WACP,CAAC,mBAAmB,QAAQ,KAC5B,CAAC,OAAO,cACR,UACE,YAAY,OAAO,SAAS,UAC5B,iBAAiB,cAAc,CAAC,OAAO,OAAO,KAAK,CAAC;AAE1D;","names":[]}
|
|
@@ -63,7 +63,7 @@ function useMutation(options, queryClient) {
|
|
|
63
63
|
},
|
|
64
64
|
[observer]
|
|
65
65
|
);
|
|
66
|
-
if (result.error && (0,
|
|
66
|
+
if (result.error && (0, import_query_core.shouldThrowError)(observer.options.throwOnError, [result.error])) {
|
|
67
67
|
throw result.error;
|
|
68
68
|
}
|
|
69
69
|
return { ...result, mutate, mutateAsync: result.mutate };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport {\n MutationObserver,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { noop } from './utils'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport type { DefaultError, QueryClient } from '@tanstack/query-core'\n\n// HOOK\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const client = useQueryClient(queryClient)\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n client,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n const mutate = React.useCallback<\n UseMutateFunction<TData, TError, TVariables, TContext>\n >(\n (variables, mutateOptions) => {\n observer.mutate(variables, mutateOptions).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwOnError, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AACvB,wBAIO;AACP,iCAA+B;AAC/B,mBAAqB;AAUd,SAAS,YAMd,SACA,aACwD;AACxD,QAAM,aAAS,2CAAe,WAAW;AAEzC,QAAM,CAAC,QAAQ,IAAU;AAAA,IACvB,MACE,IAAI;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACJ;AAEA,EAAM,gBAAU,MAAM;AACpB,aAAS,WAAW,OAAO;AAAA,EAC7B,GAAG,CAAC,UAAU,OAAO,CAAC;AAEtB,QAAM,SAAe;AAAA,IACb;AAAA,MACJ,CAAC,kBACC,SAAS,UAAU,gCAAc,WAAW,aAAa,CAAC;AAAA,MAC5D,CAAC,QAAQ;AAAA,IACX;AAAA,IACA,MAAM,SAAS,iBAAiB;AAAA,IAChC,MAAM,SAAS,iBAAiB;AAAA,EAClC;AAEA,QAAM,SAAe;AAAA,IAGnB,CAAC,WAAW,kBAAkB;AAC5B,eAAS,OAAO,WAAW,aAAa,EAAE,MAAM,iBAAI;AAAA,IACtD;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,MACE,OAAO,aACP,oCAAiB,SAAS,QAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,GAC9D;AACA,UAAM,OAAO;AAAA,EACf;AAEA,SAAO,EAAE,GAAG,QAAQ,QAAQ,aAAa,OAAO,OAAO;AACzD;","names":[]}
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
// src/useMutation.ts
|
|
4
4
|
import * as React from "react";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
MutationObserver,
|
|
7
|
+
notifyManager,
|
|
8
|
+
shouldThrowError
|
|
9
|
+
} from "@tanstack/query-core";
|
|
6
10
|
import { useQueryClient } from "./QueryClientProvider.js";
|
|
7
|
-
import { noop
|
|
11
|
+
import { noop } from "./utils.js";
|
|
8
12
|
function useMutation(options, queryClient) {
|
|
9
13
|
const client = useQueryClient(queryClient);
|
|
10
14
|
const [observer] = React.useState(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport {\n MutationObserver,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { noop } from './utils'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport type { DefaultError, QueryClient } from '@tanstack/query-core'\n\n// HOOK\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const client = useQueryClient(queryClient)\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n client,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n const mutate = React.useCallback<\n UseMutateFunction<TData, TError, TVariables, TContext>\n >(\n (variables, mutateOptions) => {\n observer.mutate(variables, mutateOptions).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwOnError, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n"],"mappings":";;;AACA,YAAY,WAAW;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAUd,SAAS,YAMd,SACA,aACwD;AACxD,QAAM,SAAS,eAAe,WAAW;AAEzC,QAAM,CAAC,QAAQ,IAAU;AAAA,IACvB,MACE,IAAI;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACJ;AAEA,EAAM,gBAAU,MAAM;AACpB,aAAS,WAAW,OAAO;AAAA,EAC7B,GAAG,CAAC,UAAU,OAAO,CAAC;AAEtB,QAAM,SAAe;AAAA,IACb;AAAA,MACJ,CAAC,kBACC,SAAS,UAAU,cAAc,WAAW,aAAa,CAAC;AAAA,MAC5D,CAAC,QAAQ;AAAA,IACX;AAAA,IACA,MAAM,SAAS,iBAAiB;AAAA,IAChC,MAAM,SAAS,iBAAiB;AAAA,EAClC;AAEA,QAAM,SAAe;AAAA,IAGnB,CAAC,WAAW,kBAAkB;AAC5B,eAAS,OAAO,WAAW,aAAa,EAAE,MAAM,IAAI;AAAA,IACtD;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,MACE,OAAO,SACP,iBAAiB,SAAS,QAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,GAC9D;AACA,UAAM,OAAO;AAAA,EACf;AAEA,SAAO,EAAE,GAAG,QAAQ,QAAQ,aAAa,OAAO,OAAO;AACzD;","names":[]}
|
package/build/legacy/utils.cjs
CHANGED
|
@@ -20,21 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
-
noop: () => noop
|
|
24
|
-
shouldThrowError: () => shouldThrowError
|
|
23
|
+
noop: () => noop
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(utils_exports);
|
|
27
|
-
function shouldThrowError(throwError, params) {
|
|
28
|
-
if (typeof throwError === "function") {
|
|
29
|
-
return throwError(...params);
|
|
30
|
-
}
|
|
31
|
-
return !!throwError;
|
|
32
|
-
}
|
|
33
26
|
function noop() {
|
|
34
27
|
}
|
|
35
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
29
|
0 && (module.exports = {
|
|
37
|
-
noop
|
|
38
|
-
shouldThrowError
|
|
30
|
+
noop
|
|
39
31
|
});
|
|
40
32
|
//# sourceMappingURL=utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function noop(): void {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,OAAa;AAAC;","names":[]}
|
package/build/legacy/utils.d.cts
CHANGED
package/build/legacy/utils.d.ts
CHANGED
package/build/legacy/utils.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
// src/utils.ts
|
|
2
|
-
function shouldThrowError(throwError, params) {
|
|
3
|
-
if (typeof throwError === "function") {
|
|
4
|
-
return throwError(...params);
|
|
5
|
-
}
|
|
6
|
-
return !!throwError;
|
|
7
|
-
}
|
|
8
2
|
function noop() {
|
|
9
3
|
}
|
|
10
4
|
export {
|
|
11
|
-
noop
|
|
12
|
-
shouldThrowError
|
|
5
|
+
noop
|
|
13
6
|
};
|
|
14
7
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function noop(): void {}\n"],"mappings":";AAAO,SAAS,OAAa;AAAC;","names":[]}
|
|
@@ -37,7 +37,7 @@ __export(errorBoundaryUtils_exports, {
|
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(errorBoundaryUtils_exports);
|
|
39
39
|
var React = __toESM(require("react"), 1);
|
|
40
|
-
var
|
|
40
|
+
var import_query_core = require("@tanstack/query-core");
|
|
41
41
|
var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
42
42
|
if (options.suspense || options.throwOnError || options.experimental_prefetchInRender) {
|
|
43
43
|
if (!errorResetBoundary.isReset()) {
|
|
@@ -57,7 +57,7 @@ var getHasError = ({
|
|
|
57
57
|
query,
|
|
58
58
|
suspense
|
|
59
59
|
}) => {
|
|
60
|
-
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && (suspense && result.data === void 0 || (0,
|
|
60
|
+
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && (suspense && result.data === void 0 || (0, import_query_core.shouldThrowError)(throwOnError, [result.error, query]));
|
|
61
61
|
};
|
|
62
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
63
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '
|
|
1
|
+
{"version":3,"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n ThrowOnError,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\n\nexport const ensurePreventErrorBoundaryRetry = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n if (\n options.suspense ||\n options.throwOnError ||\n options.experimental_prefetchInRender\n ) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n options.retryOnMount = false\n }\n }\n}\n\nexport const useClearResetErrorBoundary = (\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n}\n\nexport const getHasError = <\n TData,\n TError,\n TQueryFnData,\n TQueryData,\n TQueryKey extends QueryKey,\n>({\n result,\n errorResetBoundary,\n throwOnError,\n query,\n suspense,\n}: {\n result: QueryObserverResult<TData, TError>\n errorResetBoundary: QueryErrorResetBoundaryValue\n throwOnError: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined\n suspense: boolean | undefined\n}) => {\n return (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n query &&\n ((suspense && result.data === undefined) ||\n shouldThrowError(throwOnError, [result.error, query]))\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AACvB,wBAAiC;AAU1B,IAAM,kCAAkC,CAO7C,SAOA,uBACG;AACH,MACE,QAAQ,YACR,QAAQ,gBACR,QAAQ,+BACR;AAEA,QAAI,CAAC,mBAAmB,QAAQ,GAAG;AACjC,cAAQ,eAAe;AAAA,IACzB;AAAA,EACF;AACF;AAEO,IAAM,6BAA6B,CACxC,uBACG;AACH,EAAM,gBAAU,MAAM;AACpB,uBAAmB,WAAW;AAAA,EAChC,GAAG,CAAC,kBAAkB,CAAC;AACzB;AAEO,IAAM,cAAc,CAMzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAMM;AACJ,SACE,OAAO,WACP,CAAC,mBAAmB,QAAQ,KAC5B,CAAC,OAAO,cACR,UACE,YAAY,OAAO,SAAS,cAC5B,oCAAiB,cAAc,CAAC,OAAO,OAAO,KAAK,CAAC;AAE1D;","names":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/errorBoundaryUtils.ts
|
|
4
4
|
import * as React from "react";
|
|
5
|
-
import { shouldThrowError } from "
|
|
5
|
+
import { shouldThrowError } from "@tanstack/query-core";
|
|
6
6
|
var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
7
7
|
if (options.suspense || options.throwOnError || options.experimental_prefetchInRender) {
|
|
8
8
|
if (!errorResetBoundary.isReset()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '
|
|
1
|
+
{"version":3,"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n ThrowOnError,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\n\nexport const ensurePreventErrorBoundaryRetry = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n if (\n options.suspense ||\n options.throwOnError ||\n options.experimental_prefetchInRender\n ) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n options.retryOnMount = false\n }\n }\n}\n\nexport const useClearResetErrorBoundary = (\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n}\n\nexport const getHasError = <\n TData,\n TError,\n TQueryFnData,\n TQueryData,\n TQueryKey extends QueryKey,\n>({\n result,\n errorResetBoundary,\n throwOnError,\n query,\n suspense,\n}: {\n result: QueryObserverResult<TData, TError>\n errorResetBoundary: QueryErrorResetBoundaryValue\n throwOnError: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined\n suspense: boolean | undefined\n}) => {\n return (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n query &&\n ((suspense && result.data === undefined) ||\n shouldThrowError(throwOnError, [result.error, query]))\n )\n}\n"],"mappings":";;;AACA,YAAY,WAAW;AACvB,SAAS,wBAAwB;AAU1B,IAAM,kCAAkC,CAO7C,SAOA,uBACG;AACH,MACE,QAAQ,YACR,QAAQ,gBACR,QAAQ,+BACR;AAEA,QAAI,CAAC,mBAAmB,QAAQ,GAAG;AACjC,cAAQ,eAAe;AAAA,IACzB;AAAA,EACF;AACF;AAEO,IAAM,6BAA6B,CACxC,uBACG;AACH,EAAM,gBAAU,MAAM;AACpB,uBAAmB,WAAW;AAAA,EAChC,GAAG,CAAC,kBAAkB,CAAC;AACzB;AAEO,IAAM,cAAc,CAMzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAMM;AACJ,SACE,OAAO,WACP,CAAC,mBAAmB,QAAQ,KAC5B,CAAC,OAAO,cACR,UACE,YAAY,OAAO,SAAS,UAC5B,iBAAiB,cAAc,CAAC,OAAO,OAAO,KAAK,CAAC;AAE1D;","names":[]}
|
|
@@ -63,7 +63,7 @@ function useMutation(options, queryClient) {
|
|
|
63
63
|
},
|
|
64
64
|
[observer]
|
|
65
65
|
);
|
|
66
|
-
if (result.error && (0,
|
|
66
|
+
if (result.error && (0, import_query_core.shouldThrowError)(observer.options.throwOnError, [result.error])) {
|
|
67
67
|
throw result.error;
|
|
68
68
|
}
|
|
69
69
|
return { ...result, mutate, mutateAsync: result.mutate };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport {\n MutationObserver,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { noop } from './utils'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport type { DefaultError, QueryClient } from '@tanstack/query-core'\n\n// HOOK\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const client = useQueryClient(queryClient)\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n client,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n const mutate = React.useCallback<\n UseMutateFunction<TData, TError, TVariables, TContext>\n >(\n (variables, mutateOptions) => {\n observer.mutate(variables, mutateOptions).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwOnError, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AACvB,wBAIO;AACP,iCAA+B;AAC/B,mBAAqB;AAUd,SAAS,YAMd,SACA,aACwD;AACxD,QAAM,aAAS,2CAAe,WAAW;AAEzC,QAAM,CAAC,QAAQ,IAAU;AAAA,IACvB,MACE,IAAI;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACJ;AAEA,EAAM,gBAAU,MAAM;AACpB,aAAS,WAAW,OAAO;AAAA,EAC7B,GAAG,CAAC,UAAU,OAAO,CAAC;AAEtB,QAAM,SAAe;AAAA,IACb;AAAA,MACJ,CAAC,kBACC,SAAS,UAAU,gCAAc,WAAW,aAAa,CAAC;AAAA,MAC5D,CAAC,QAAQ;AAAA,IACX;AAAA,IACA,MAAM,SAAS,iBAAiB;AAAA,IAChC,MAAM,SAAS,iBAAiB;AAAA,EAClC;AAEA,QAAM,SAAe;AAAA,IAGnB,CAAC,WAAW,kBAAkB;AAC5B,eAAS,OAAO,WAAW,aAAa,EAAE,MAAM,iBAAI;AAAA,IACtD;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,MACE,OAAO,aACP,oCAAiB,SAAS,QAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,GAC9D;AACA,UAAM,OAAO;AAAA,EACf;AAEA,SAAO,EAAE,GAAG,QAAQ,QAAQ,aAAa,OAAO,OAAO;AACzD;","names":[]}
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
// src/useMutation.ts
|
|
4
4
|
import * as React from "react";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
MutationObserver,
|
|
7
|
+
notifyManager,
|
|
8
|
+
shouldThrowError
|
|
9
|
+
} from "@tanstack/query-core";
|
|
6
10
|
import { useQueryClient } from "./QueryClientProvider.js";
|
|
7
|
-
import { noop
|
|
11
|
+
import { noop } from "./utils.js";
|
|
8
12
|
function useMutation(options, queryClient) {
|
|
9
13
|
const client = useQueryClient(queryClient);
|
|
10
14
|
const [observer] = React.useState(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport {\n MutationObserver,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { noop } from './utils'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport type { DefaultError, QueryClient } from '@tanstack/query-core'\n\n// HOOK\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const client = useQueryClient(queryClient)\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n client,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n const mutate = React.useCallback<\n UseMutateFunction<TData, TError, TVariables, TContext>\n >(\n (variables, mutateOptions) => {\n observer.mutate(variables, mutateOptions).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwOnError, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n"],"mappings":";;;AACA,YAAY,WAAW;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAUd,SAAS,YAMd,SACA,aACwD;AACxD,QAAM,SAAS,eAAe,WAAW;AAEzC,QAAM,CAAC,QAAQ,IAAU;AAAA,IACvB,MACE,IAAI;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACJ;AAEA,EAAM,gBAAU,MAAM;AACpB,aAAS,WAAW,OAAO;AAAA,EAC7B,GAAG,CAAC,UAAU,OAAO,CAAC;AAEtB,QAAM,SAAe;AAAA,IACb;AAAA,MACJ,CAAC,kBACC,SAAS,UAAU,cAAc,WAAW,aAAa,CAAC;AAAA,MAC5D,CAAC,QAAQ;AAAA,IACX;AAAA,IACA,MAAM,SAAS,iBAAiB;AAAA,IAChC,MAAM,SAAS,iBAAiB;AAAA,EAClC;AAEA,QAAM,SAAe;AAAA,IAGnB,CAAC,WAAW,kBAAkB;AAC5B,eAAS,OAAO,WAAW,aAAa,EAAE,MAAM,IAAI;AAAA,IACtD;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,MACE,OAAO,SACP,iBAAiB,SAAS,QAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,GAC9D;AACA,UAAM,OAAO;AAAA,EACf;AAEA,SAAO,EAAE,GAAG,QAAQ,QAAQ,aAAa,OAAO,OAAO;AACzD;","names":[]}
|
package/build/modern/utils.cjs
CHANGED
|
@@ -20,21 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
-
noop: () => noop
|
|
24
|
-
shouldThrowError: () => shouldThrowError
|
|
23
|
+
noop: () => noop
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(utils_exports);
|
|
27
|
-
function shouldThrowError(throwError, params) {
|
|
28
|
-
if (typeof throwError === "function") {
|
|
29
|
-
return throwError(...params);
|
|
30
|
-
}
|
|
31
|
-
return !!throwError;
|
|
32
|
-
}
|
|
33
26
|
function noop() {
|
|
34
27
|
}
|
|
35
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
29
|
0 && (module.exports = {
|
|
37
|
-
noop
|
|
38
|
-
shouldThrowError
|
|
30
|
+
noop
|
|
39
31
|
});
|
|
40
32
|
//# sourceMappingURL=utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function noop(): void {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,OAAa;AAAC;","names":[]}
|
package/build/modern/utils.d.cts
CHANGED
package/build/modern/utils.d.ts
CHANGED
package/build/modern/utils.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
// src/utils.ts
|
|
2
|
-
function shouldThrowError(throwError, params) {
|
|
3
|
-
if (typeof throwError === "function") {
|
|
4
|
-
return throwError(...params);
|
|
5
|
-
}
|
|
6
|
-
return !!throwError;
|
|
7
|
-
}
|
|
8
2
|
function noop() {
|
|
9
3
|
}
|
|
10
4
|
export {
|
|
11
|
-
noop
|
|
12
|
-
shouldThrowError
|
|
5
|
+
noop
|
|
13
6
|
};
|
|
14
7
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function noop(): void {}\n"],"mappings":";AAAO,SAAS,OAAa;AAAC;","names":[]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import vitest from '@vitest/eslint-plugin'
|
|
4
3
|
import rootConfig from './root.eslint.config.js'
|
|
5
4
|
|
|
6
5
|
export default [
|
|
@@ -9,6 +8,7 @@ export default [
|
|
|
9
8
|
rules: {
|
|
10
9
|
'cspell/spellchecker': 'off',
|
|
11
10
|
'@typescript-eslint/no-unnecessary-condition': 'off',
|
|
11
|
+
'@typescript-eslint/require-await': 'off',
|
|
12
12
|
'import/no-duplicates': 'off',
|
|
13
13
|
'import/no-unresolved': 'off',
|
|
14
14
|
'import/order': 'off',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "5.75.
|
|
3
|
+
"version": "5.75.6",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"!build/codemods/**/__tests__"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@tanstack/query-core": "5.75.
|
|
47
|
+
"@tanstack/query-core": "5.75.6"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@testing-library/react": "^16.1.0",
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"react": "^19.0.0",
|
|
58
58
|
"react-dom": "^19.0.0",
|
|
59
59
|
"react-error-boundary": "^4.1.2",
|
|
60
|
-
"@tanstack/query-
|
|
60
|
+
"@tanstack/query-test-utils": "0.0.0",
|
|
61
|
+
"@tanstack/query-persist-client-core": "5.75.6"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
64
|
"react": "^18 || ^19"
|
package/src/useMutation.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
MutationObserver,
|
|
5
|
+
notifyManager,
|
|
6
|
+
shouldThrowError,
|
|
7
|
+
} from '@tanstack/query-core'
|
|
4
8
|
import { useQueryClient } from './QueryClientProvider'
|
|
5
|
-
import { noop
|
|
9
|
+
import { noop } from './utils'
|
|
6
10
|
import type {
|
|
7
11
|
UseMutateFunction,
|
|
8
12
|
UseMutationOptions,
|
package/src/utils.ts
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
export function shouldThrowError<T extends (...args: Array<any>) => boolean>(
|
|
2
|
-
throwError: boolean | T | undefined,
|
|
3
|
-
params: Parameters<T>,
|
|
4
|
-
): boolean {
|
|
5
|
-
// Allow throwError function to override throwing behavior on a per-error basis
|
|
6
|
-
if (typeof throwError === 'function') {
|
|
7
|
-
return throwError(...params)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return !!throwError
|
|
11
|
-
}
|
|
12
|
-
|
|
13
1
|
export function noop(): void {}
|