@tanstack/react-query-persist-client 5.104.0 → 5.104.2

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.
@@ -28,16 +28,26 @@ let _tanstack_query_persist_client_core = require("@tanstack/query-persist-clien
28
28
  let _tanstack_react_query = require("@tanstack/react-query");
29
29
  let react_jsx_runtime = require("react/jsx-runtime");
30
30
  //#region src/PersistQueryClientProvider.tsx
31
+ /**
32
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
33
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
34
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
35
+ * changes.
36
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
37
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
38
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
39
+ * @returns The `QueryClientProvider` wrapping the children.
40
+ */
31
41
  const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
32
42
  const [isRestoring, setIsRestoring] = react.useState(true);
33
- const refs = react.useRef({
43
+ const optionsRef = react.useRef({
34
44
  persistOptions,
35
45
  onSuccess,
36
46
  onError
37
47
  });
38
- const didRestore = react.useRef(false);
48
+ const didRestoreRef = react.useRef(false);
39
49
  react.useEffect(() => {
40
- refs.current = {
50
+ optionsRef.current = {
41
51
  persistOptions,
42
52
  onSuccess,
43
53
  onError
@@ -45,17 +55,17 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
45
55
  });
46
56
  react.useEffect(() => {
47
57
  const options = {
48
- ...refs.current.persistOptions,
58
+ ...optionsRef.current.persistOptions,
49
59
  queryClient: props.client
50
60
  };
51
- if (!didRestore.current) {
52
- didRestore.current = true;
61
+ if (!didRestoreRef.current) {
62
+ didRestoreRef.current = true;
53
63
  (0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() => {
54
- var _refs$current$onSucce, _refs$current;
55
- return (_refs$current$onSucce = (_refs$current = refs.current).onSuccess) === null || _refs$current$onSucce === void 0 ? void 0 : _refs$current$onSucce.call(_refs$current);
64
+ var _optionsRef$current$o, _optionsRef$current;
65
+ return (_optionsRef$current$o = (_optionsRef$current = optionsRef.current).onSuccess) === null || _optionsRef$current$o === void 0 ? void 0 : _optionsRef$current$o.call(_optionsRef$current);
56
66
  }).catch(() => {
57
- var _refs$current$onError, _refs$current2;
58
- return (_refs$current$onError = (_refs$current2 = refs.current).onError) === null || _refs$current$onError === void 0 ? void 0 : _refs$current$onError.call(_refs$current2);
67
+ var _optionsRef$current$o2, _optionsRef$current2;
68
+ return (_optionsRef$current$o2 = (_optionsRef$current2 = optionsRef.current).onError) === null || _optionsRef$current$o2 === void 0 ? void 0 : _optionsRef$current$o2.call(_optionsRef$current2);
59
69
  }).finally(() => {
60
70
  setIsRestoring(false);
61
71
  });
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.cjs","names":["React","persistQueryClientSubscribe","QueryClientProvider","IsRestoringProvider"],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): React.JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess, onError })\n const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess, onError }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n persistQueryClientRestore(options)\n .then(() => refs.current.onSuccess?.())\n .catch(() => refs.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACqD;CACxD,MAAM,CAAC,aAAa,kBAAkBA,MAAM,SAAS,IAAI;CACzD,MAAM,OAAOA,MAAM,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAChE,MAAM,aAAaA,MAAM,OAAO,KAAK;CAErC,MAAM,gBAAgB;EACpB,KAAK,UAAU;GAAE;GAAgB;GAAW;EAAQ;CACtD,CAAC;CAED,MAAM,gBAAgB;EACpB,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ;GAChB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,CAAA,GAAA,oCAAA,0BAAA,CAA0B,OAAO,CAAC,CAC/B,WAAW;;IAAK,QAAA,yBAAA,gBAAA,KAAA,QAAA,CAAQ,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,aAAY;GAAC,CAAA,CAAC,CACtC,YAAY;;IAAK,QAAA,yBAAA,iBAAA,KAAA,QAAA,CAAQ,aAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,cAAU;GAAC,CAAA,CAAC,CACrC,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,KAAA,GAAYC,oCAAAA,4BAAAA,CAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;EAAqB,GAAI;EACvB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
1
+ {"version":3,"file":"PersistQueryClientProvider.cjs","names":["React","persistQueryClientSubscribe","QueryClientProvider","IsRestoringProvider"],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'\n\n/**\n * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the\n * `persistOptions` and callbacks for when restoring succeeds or fails.\n */\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\n/**\n * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:\n * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish\n * before subscribing. Once restored, the client is saved with the persister whenever the cache\n * changes.\n * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and\n * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored\n * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.\n * @returns The `QueryClientProvider` wrapping the children.\n */\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): React.JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const optionsRef = React.useRef({ persistOptions, onSuccess, onError })\n const didRestoreRef = React.useRef(false)\n\n React.useEffect(() => {\n optionsRef.current = { persistOptions, onSuccess, onError }\n })\n\n React.useEffect(() => {\n const options = {\n ...optionsRef.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestoreRef.current) {\n didRestoreRef.current = true\n persistQueryClientRestore(options)\n .then(() => optionsRef.current.onSuccess?.())\n .catch(() => optionsRef.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACqD;CACxD,MAAM,CAAC,aAAa,kBAAkBA,MAAM,SAAS,IAAI;CACzD,MAAM,aAAaA,MAAM,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CACtE,MAAM,gBAAgBA,MAAM,OAAO,KAAK;CAExC,MAAM,gBAAgB;EACpB,WAAW,UAAU;GAAE;GAAgB;GAAW;EAAQ;CAC5D,CAAC;CAED,MAAM,gBAAgB;EACpB,MAAM,UAAU;GACd,GAAG,WAAW,QAAQ;GACtB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,cAAc,SAAS;GAC1B,cAAc,UAAU;GACxB,CAAA,GAAA,oCAAA,0BAAA,CAA0B,OAAO,CAAC,CAC/B,WAAW;;IAAW,QAAA,yBAAA,sBAAA,WAAA,QAAA,CAAQ,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,mBAAY;GAAC,CAAA,CAAC,CAC5C,YAAY;;IAAW,QAAA,0BAAA,uBAAA,WAAA,QAAA,CAAQ,aAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAA,KAAA,oBAAU;GAAC,CAAA,CAAC,CAC3C,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,KAAA,GAAYC,oCAAAA,4BAAAA,CAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;EAAqB,GAAI;EACvB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
@@ -2,11 +2,25 @@ import * as React from "react";
2
2
  import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
3
3
  import { OmitKeyof, QueryClientProviderProps } from "@tanstack/react-query";
4
4
  //#region src/PersistQueryClientProvider.d.ts
5
+ /**
6
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
7
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
8
+ */
5
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
6
10
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
7
11
  onSuccess?: () => Promise<unknown> | unknown;
8
12
  onError?: () => Promise<unknown> | unknown;
9
13
  };
14
+ /**
15
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
16
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
17
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
18
+ * changes.
19
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
20
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
21
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
22
+ * @returns The `QueryClientProvider` wrapping the children.
23
+ */
10
24
  export declare const PersistQueryClientProvider: ({ children, persistOptions, onSuccess, onError, ...props }: PersistQueryClientProviderProps) => React.JSX.Element;
11
25
  //#endregion
12
26
  //# sourceMappingURL=PersistQueryClientProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.d.cts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;YAWY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;qBAGL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC,MAAM,IAAI"}
1
+ {"version":3,"file":"PersistQueryClientProvider.d.cts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;;;;;YAeY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;;;;;;;;;;;qBAaL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC,MAAM,IAAI"}
@@ -2,11 +2,25 @@ import * as React from "react";
2
2
  import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
3
3
  import { OmitKeyof, QueryClientProviderProps } from "@tanstack/react-query";
4
4
  //#region src/PersistQueryClientProvider.d.ts
5
+ /**
6
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
7
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
8
+ */
5
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
6
10
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
7
11
  onSuccess?: () => Promise<unknown> | unknown;
8
12
  onError?: () => Promise<unknown> | unknown;
9
13
  };
14
+ /**
15
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
16
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
17
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
18
+ * changes.
19
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
20
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
21
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
22
+ * @returns The `QueryClientProvider` wrapping the children.
23
+ */
10
24
  export declare const PersistQueryClientProvider: ({ children, persistOptions, onSuccess, onError, ...props }: PersistQueryClientProviderProps) => React.JSX.Element;
11
25
  //#endregion
12
26
  //# sourceMappingURL=PersistQueryClientProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.d.ts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;YAWY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;qBAGL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC,MAAM,IAAI"}
1
+ {"version":3,"file":"PersistQueryClientProvider.d.ts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;;;;;YAeY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;;;;;;;;;;;qBAaL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC,MAAM,IAAI"}
@@ -4,16 +4,26 @@ import { persistQueryClientRestore, persistQueryClientSubscribe } from "@tanstac
4
4
  import { IsRestoringProvider, QueryClientProvider } from "@tanstack/react-query";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  //#region src/PersistQueryClientProvider.tsx
7
+ /**
8
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
9
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
10
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
11
+ * changes.
12
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
13
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
14
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
15
+ * @returns The `QueryClientProvider` wrapping the children.
16
+ */
7
17
  const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
8
18
  const [isRestoring, setIsRestoring] = React.useState(true);
9
- const refs = React.useRef({
19
+ const optionsRef = React.useRef({
10
20
  persistOptions,
11
21
  onSuccess,
12
22
  onError
13
23
  });
14
- const didRestore = React.useRef(false);
24
+ const didRestoreRef = React.useRef(false);
15
25
  React.useEffect(() => {
16
- refs.current = {
26
+ optionsRef.current = {
17
27
  persistOptions,
18
28
  onSuccess,
19
29
  onError
@@ -21,17 +31,17 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
21
31
  });
22
32
  React.useEffect(() => {
23
33
  const options = {
24
- ...refs.current.persistOptions,
34
+ ...optionsRef.current.persistOptions,
25
35
  queryClient: props.client
26
36
  };
27
- if (!didRestore.current) {
28
- didRestore.current = true;
37
+ if (!didRestoreRef.current) {
38
+ didRestoreRef.current = true;
29
39
  persistQueryClientRestore(options).then(() => {
30
- var _refs$current$onSucce, _refs$current;
31
- return (_refs$current$onSucce = (_refs$current = refs.current).onSuccess) === null || _refs$current$onSucce === void 0 ? void 0 : _refs$current$onSucce.call(_refs$current);
40
+ var _optionsRef$current$o, _optionsRef$current;
41
+ return (_optionsRef$current$o = (_optionsRef$current = optionsRef.current).onSuccess) === null || _optionsRef$current$o === void 0 ? void 0 : _optionsRef$current$o.call(_optionsRef$current);
32
42
  }).catch(() => {
33
- var _refs$current$onError, _refs$current2;
34
- return (_refs$current$onError = (_refs$current2 = refs.current).onError) === null || _refs$current$onError === void 0 ? void 0 : _refs$current$onError.call(_refs$current2);
43
+ var _optionsRef$current$o2, _optionsRef$current2;
44
+ return (_optionsRef$current$o2 = (_optionsRef$current2 = optionsRef.current).onError) === null || _optionsRef$current$o2 === void 0 ? void 0 : _optionsRef$current$o2.call(_optionsRef$current2);
35
45
  }).finally(() => {
36
46
  setIsRestoring(false);
37
47
  });
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.js","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): React.JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess, onError })\n const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess, onError }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n persistQueryClientRestore(options)\n .then(() => refs.current.onSuccess?.())\n .catch(() => refs.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;AAiBA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACqD;CACxD,MAAM,CAAC,aAAa,kBAAkB,MAAM,SAAS,IAAI;CACzD,MAAM,OAAO,MAAM,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAChE,MAAM,aAAa,MAAM,OAAO,KAAK;CAErC,MAAM,gBAAgB;EACpB,KAAK,UAAU;GAAE;GAAgB;GAAW;EAAQ;CACtD,CAAC;CAED,MAAM,gBAAgB;EACpB,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ;GAChB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,0BAA0B,OAAO,CAAC,CAC/B,WAAW;;IAAK,QAAA,yBAAA,gBAAA,KAAA,QAAA,CAAQ,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,aAAY;GAAC,CAAA,CAAC,CACtC,YAAY;;IAAK,QAAA,yBAAA,iBAAA,KAAA,QAAA,CAAQ,aAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,cAAU;GAAC,CAAA,CAAC,CACrC,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,IAAY,4BAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,oBAAC,qBAAD;EAAqB,GAAI;EACvB,UAAA,oBAAC,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
1
+ {"version":3,"file":"PersistQueryClientProvider.js","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'\n\n/**\n * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the\n * `persistOptions` and callbacks for when restoring succeeds or fails.\n */\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\n/**\n * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:\n * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish\n * before subscribing. Once restored, the client is saved with the persister whenever the cache\n * changes.\n * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and\n * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored\n * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.\n * @returns The `QueryClientProvider` wrapping the children.\n */\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): React.JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const optionsRef = React.useRef({ persistOptions, onSuccess, onError })\n const didRestoreRef = React.useRef(false)\n\n React.useEffect(() => {\n optionsRef.current = { persistOptions, onSuccess, onError }\n })\n\n React.useEffect(() => {\n const options = {\n ...optionsRef.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestoreRef.current) {\n didRestoreRef.current = true\n persistQueryClientRestore(options)\n .then(() => optionsRef.current.onSuccess?.())\n .catch(() => optionsRef.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACqD;CACxD,MAAM,CAAC,aAAa,kBAAkB,MAAM,SAAS,IAAI;CACzD,MAAM,aAAa,MAAM,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CACtE,MAAM,gBAAgB,MAAM,OAAO,KAAK;CAExC,MAAM,gBAAgB;EACpB,WAAW,UAAU;GAAE;GAAgB;GAAW;EAAQ;CAC5D,CAAC;CAED,MAAM,gBAAgB;EACpB,MAAM,UAAU;GACd,GAAG,WAAW,QAAQ;GACtB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,cAAc,SAAS;GAC1B,cAAc,UAAU;GACxB,0BAA0B,OAAO,CAAC,CAC/B,WAAW;;IAAW,QAAA,yBAAA,sBAAA,WAAA,QAAA,CAAQ,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,mBAAY;GAAC,CAAA,CAAC,CAC5C,YAAY;;IAAW,QAAA,0BAAA,uBAAA,WAAA,QAAA,CAAQ,aAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAA,KAAA,oBAAU;GAAC,CAAA,CAAC,CAC3C,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,IAAY,4BAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,oBAAC,qBAAD;EAAqB,GAAI;EACvB,UAAA,oBAAC,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
@@ -28,16 +28,26 @@ let _tanstack_query_persist_client_core = require("@tanstack/query-persist-clien
28
28
  let _tanstack_react_query = require("@tanstack/react-query");
29
29
  let react_jsx_runtime = require("react/jsx-runtime");
30
30
  //#region src/PersistQueryClientProvider.tsx
31
+ /**
32
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
33
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
34
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
35
+ * changes.
36
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
37
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
38
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
39
+ * @returns The `QueryClientProvider` wrapping the children.
40
+ */
31
41
  const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
32
42
  const [isRestoring, setIsRestoring] = react.useState(true);
33
- const refs = react.useRef({
43
+ const optionsRef = react.useRef({
34
44
  persistOptions,
35
45
  onSuccess,
36
46
  onError
37
47
  });
38
- const didRestore = react.useRef(false);
48
+ const didRestoreRef = react.useRef(false);
39
49
  react.useEffect(() => {
40
- refs.current = {
50
+ optionsRef.current = {
41
51
  persistOptions,
42
52
  onSuccess,
43
53
  onError
@@ -45,12 +55,12 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
45
55
  });
46
56
  react.useEffect(() => {
47
57
  const options = {
48
- ...refs.current.persistOptions,
58
+ ...optionsRef.current.persistOptions,
49
59
  queryClient: props.client
50
60
  };
51
- if (!didRestore.current) {
52
- didRestore.current = true;
53
- (0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() => refs.current.onSuccess?.()).catch(() => refs.current.onError?.()).finally(() => {
61
+ if (!didRestoreRef.current) {
62
+ didRestoreRef.current = true;
63
+ (0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() => optionsRef.current.onSuccess?.()).catch(() => optionsRef.current.onError?.()).finally(() => {
54
64
  setIsRestoring(false);
55
65
  });
56
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.cjs","names":["React","persistQueryClientSubscribe","QueryClientProvider","IsRestoringProvider"],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): React.JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess, onError })\n const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess, onError }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n persistQueryClientRestore(options)\n .then(() => refs.current.onSuccess?.())\n .catch(() => refs.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACqD;CACxD,MAAM,CAAC,aAAa,kBAAkBA,MAAM,SAAS,IAAI;CACzD,MAAM,OAAOA,MAAM,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAChE,MAAM,aAAaA,MAAM,OAAO,KAAK;CAErC,MAAM,gBAAgB;EACpB,KAAK,UAAU;GAAE;GAAgB;GAAW;EAAQ;CACtD,CAAC;CAED,MAAM,gBAAgB;EACpB,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ;GAChB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,CAAA,GAAA,oCAAA,0BAAA,CAA0B,OAAO,CAAC,CAC/B,WAAW,KAAK,QAAQ,YAAY,CAAC,CAAC,CACtC,YAAY,KAAK,QAAQ,UAAU,CAAC,CAAC,CACrC,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,KAAA,GAAYC,oCAAAA,4BAAAA,CAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;EAAqB,GAAI;EACvB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
1
+ {"version":3,"file":"PersistQueryClientProvider.cjs","names":["React","persistQueryClientSubscribe","QueryClientProvider","IsRestoringProvider"],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'\n\n/**\n * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the\n * `persistOptions` and callbacks for when restoring succeeds or fails.\n */\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\n/**\n * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:\n * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish\n * before subscribing. Once restored, the client is saved with the persister whenever the cache\n * changes.\n * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and\n * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored\n * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.\n * @returns The `QueryClientProvider` wrapping the children.\n */\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): React.JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const optionsRef = React.useRef({ persistOptions, onSuccess, onError })\n const didRestoreRef = React.useRef(false)\n\n React.useEffect(() => {\n optionsRef.current = { persistOptions, onSuccess, onError }\n })\n\n React.useEffect(() => {\n const options = {\n ...optionsRef.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestoreRef.current) {\n didRestoreRef.current = true\n persistQueryClientRestore(options)\n .then(() => optionsRef.current.onSuccess?.())\n .catch(() => optionsRef.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACqD;CACxD,MAAM,CAAC,aAAa,kBAAkBA,MAAM,SAAS,IAAI;CACzD,MAAM,aAAaA,MAAM,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CACtE,MAAM,gBAAgBA,MAAM,OAAO,KAAK;CAExC,MAAM,gBAAgB;EACpB,WAAW,UAAU;GAAE;GAAgB;GAAW;EAAQ;CAC5D,CAAC;CAED,MAAM,gBAAgB;EACpB,MAAM,UAAU;GACd,GAAG,WAAW,QAAQ;GACtB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,cAAc,SAAS;GAC1B,cAAc,UAAU;GACxB,CAAA,GAAA,oCAAA,0BAAA,CAA0B,OAAO,CAAC,CAC/B,WAAW,WAAW,QAAQ,YAAY,CAAC,CAAC,CAC5C,YAAY,WAAW,QAAQ,UAAU,CAAC,CAAC,CAC3C,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,KAAA,GAAYC,oCAAAA,4BAAAA,CAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;EAAqB,GAAI;EACvB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
@@ -2,11 +2,25 @@ import * as React from "react";
2
2
  import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
3
3
  import { OmitKeyof, QueryClientProviderProps } from "@tanstack/react-query";
4
4
  //#region src/PersistQueryClientProvider.d.ts
5
+ /**
6
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
7
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
8
+ */
5
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
6
10
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
7
11
  onSuccess?: () => Promise<unknown> | unknown;
8
12
  onError?: () => Promise<unknown> | unknown;
9
13
  };
14
+ /**
15
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
16
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
17
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
18
+ * changes.
19
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
20
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
21
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
22
+ * @returns The `QueryClientProvider` wrapping the children.
23
+ */
10
24
  export declare const PersistQueryClientProvider: ({ children, persistOptions, onSuccess, onError, ...props }: PersistQueryClientProviderProps) => React.JSX.Element;
11
25
  //#endregion
12
26
  //# sourceMappingURL=PersistQueryClientProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.d.cts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;YAWY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;qBAGL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC,MAAM,IAAI"}
1
+ {"version":3,"file":"PersistQueryClientProvider.d.cts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;;;;;YAeY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;;;;;;;;;;;qBAaL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC,MAAM,IAAI"}
@@ -2,11 +2,25 @@ import * as React from "react";
2
2
  import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
3
3
  import { OmitKeyof, QueryClientProviderProps } from "@tanstack/react-query";
4
4
  //#region src/PersistQueryClientProvider.d.ts
5
+ /**
6
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
7
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
8
+ */
5
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
6
10
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
7
11
  onSuccess?: () => Promise<unknown> | unknown;
8
12
  onError?: () => Promise<unknown> | unknown;
9
13
  };
14
+ /**
15
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
16
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
17
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
18
+ * changes.
19
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
20
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
21
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
22
+ * @returns The `QueryClientProvider` wrapping the children.
23
+ */
10
24
  export declare const PersistQueryClientProvider: ({ children, persistOptions, onSuccess, onError, ...props }: PersistQueryClientProviderProps) => React.JSX.Element;
11
25
  //#endregion
12
26
  //# sourceMappingURL=PersistQueryClientProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.d.ts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;YAWY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;qBAGL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC,MAAM,IAAI"}
1
+ {"version":3,"file":"PersistQueryClientProvider.d.ts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;;;;;YAeY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;;;;;;;;;;;qBAaL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC,MAAM,IAAI"}
@@ -4,16 +4,26 @@ import { persistQueryClientRestore, persistQueryClientSubscribe } from "@tanstac
4
4
  import { IsRestoringProvider, QueryClientProvider } from "@tanstack/react-query";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  //#region src/PersistQueryClientProvider.tsx
7
+ /**
8
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
9
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
10
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
11
+ * changes.
12
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
13
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
14
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
15
+ * @returns The `QueryClientProvider` wrapping the children.
16
+ */
7
17
  const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
8
18
  const [isRestoring, setIsRestoring] = React.useState(true);
9
- const refs = React.useRef({
19
+ const optionsRef = React.useRef({
10
20
  persistOptions,
11
21
  onSuccess,
12
22
  onError
13
23
  });
14
- const didRestore = React.useRef(false);
24
+ const didRestoreRef = React.useRef(false);
15
25
  React.useEffect(() => {
16
- refs.current = {
26
+ optionsRef.current = {
17
27
  persistOptions,
18
28
  onSuccess,
19
29
  onError
@@ -21,12 +31,12 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
21
31
  });
22
32
  React.useEffect(() => {
23
33
  const options = {
24
- ...refs.current.persistOptions,
34
+ ...optionsRef.current.persistOptions,
25
35
  queryClient: props.client
26
36
  };
27
- if (!didRestore.current) {
28
- didRestore.current = true;
29
- persistQueryClientRestore(options).then(() => refs.current.onSuccess?.()).catch(() => refs.current.onError?.()).finally(() => {
37
+ if (!didRestoreRef.current) {
38
+ didRestoreRef.current = true;
39
+ persistQueryClientRestore(options).then(() => optionsRef.current.onSuccess?.()).catch(() => optionsRef.current.onError?.()).finally(() => {
30
40
  setIsRestoring(false);
31
41
  });
32
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.js","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): React.JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess, onError })\n const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess, onError }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n persistQueryClientRestore(options)\n .then(() => refs.current.onSuccess?.())\n .catch(() => refs.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;AAiBA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACqD;CACxD,MAAM,CAAC,aAAa,kBAAkB,MAAM,SAAS,IAAI;CACzD,MAAM,OAAO,MAAM,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAChE,MAAM,aAAa,MAAM,OAAO,KAAK;CAErC,MAAM,gBAAgB;EACpB,KAAK,UAAU;GAAE;GAAgB;GAAW;EAAQ;CACtD,CAAC;CAED,MAAM,gBAAgB;EACpB,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ;GAChB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,0BAA0B,OAAO,CAAC,CAC/B,WAAW,KAAK,QAAQ,YAAY,CAAC,CAAC,CACtC,YAAY,KAAK,QAAQ,UAAU,CAAC,CAAC,CACrC,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,IAAY,4BAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,oBAAC,qBAAD;EAAqB,GAAI;EACvB,UAAA,oBAAC,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
1
+ {"version":3,"file":"PersistQueryClientProvider.js","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'\n\n/**\n * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the\n * `persistOptions` and callbacks for when restoring succeeds or fails.\n */\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\n/**\n * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:\n * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish\n * before subscribing. Once restored, the client is saved with the persister whenever the cache\n * changes.\n * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and\n * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored\n * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.\n * @returns The `QueryClientProvider` wrapping the children.\n */\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): React.JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const optionsRef = React.useRef({ persistOptions, onSuccess, onError })\n const didRestoreRef = React.useRef(false)\n\n React.useEffect(() => {\n optionsRef.current = { persistOptions, onSuccess, onError }\n })\n\n React.useEffect(() => {\n const options = {\n ...optionsRef.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestoreRef.current) {\n didRestoreRef.current = true\n persistQueryClientRestore(options)\n .then(() => optionsRef.current.onSuccess?.())\n .catch(() => optionsRef.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACqD;CACxD,MAAM,CAAC,aAAa,kBAAkB,MAAM,SAAS,IAAI;CACzD,MAAM,aAAa,MAAM,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CACtE,MAAM,gBAAgB,MAAM,OAAO,KAAK;CAExC,MAAM,gBAAgB;EACpB,WAAW,UAAU;GAAE;GAAgB;GAAW;EAAQ;CAC5D,CAAC;CAED,MAAM,gBAAgB;EACpB,MAAM,UAAU;GACd,GAAG,WAAW,QAAQ;GACtB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,cAAc,SAAS;GAC1B,cAAc,UAAU;GACxB,0BAA0B,OAAO,CAAC,CAC/B,WAAW,WAAW,QAAQ,YAAY,CAAC,CAAC,CAC5C,YAAY,WAAW,QAAQ,UAAU,CAAC,CAAC,CAC3C,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,IAAY,4BAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,oBAAC,qBAAD;EAAqB,GAAI;EACvB,UAAA,oBAAC,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query-persist-client",
3
- "version": "5.104.0",
3
+ "version": "5.104.2",
4
4
  "description": "React bindings to work with persisters in TanStack/react-query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -40,32 +40,34 @@
40
40
  "!src/__tests__"
41
41
  ],
42
42
  "dependencies": {
43
- "@tanstack/query-persist-client-core": "5.104.0"
43
+ "@tanstack/query-persist-client-core": "5.104.2"
44
44
  },
45
45
  "devDependencies": {
46
+ "@eslint-react/eslint-plugin": "^5.23.3",
46
47
  "@tanstack/query-test-utils": "0.0.0",
47
- "@tanstack/react-query": "5.104.0",
48
+ "@tanstack/react-query": "5.104.2",
48
49
  "@testing-library/react": "^16.1.0",
49
50
  "@types/react": "^19.2.7",
50
51
  "@vitejs/plugin-react": "^6.1.1",
51
- "npm-run-all2": "^9.0.3",
52
- "react": "^19.2.1"
52
+ "eslint-plugin-react-hooks": "^7.1.1",
53
+ "react": "^19.2.1",
54
+ "typescript": "6.0.3"
53
55
  },
54
56
  "peerDependencies": {
55
- "@tanstack/react-query": "^5.104.0",
57
+ "@tanstack/react-query": "^5.104.2",
56
58
  "react": "^18 || ^19"
57
59
  },
58
60
  "scripts": {
59
61
  "clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
60
62
  "compile": "tsc --project tsconfig.json",
61
- "test:eslint": "eslint --concurrency=auto ./src",
63
+ "test:oxlint": "oxlint ./src",
62
64
  "test:types": "npm-run-all --serial test:types:*",
63
- "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
64
65
  "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
65
66
  "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
66
67
  "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
67
68
  "test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
68
69
  "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
70
+ "test:types:ts71": "node ../../node_modules/typescript71/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts71 --tsBuildInfoFile .cache/test-types/ts71.tsbuildinfo",
69
71
  "test:lib": "vitest --retry=3",
70
72
  "test:lib:dev": "pnpm run test:lib --watch",
71
73
  "test:build": "publint --strict && attw --pack",
@@ -9,12 +9,26 @@ import { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'
9
9
  import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
10
10
  import type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'
11
11
 
12
+ /**
13
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
14
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
15
+ */
12
16
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
13
17
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
14
18
  onSuccess?: () => Promise<unknown> | unknown
15
19
  onError?: () => Promise<unknown> | unknown
16
20
  }
17
21
 
22
+ /**
23
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
24
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
25
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
26
+ * changes.
27
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
28
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
29
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
30
+ * @returns The `QueryClientProvider` wrapping the children.
31
+ */
18
32
  export const PersistQueryClientProvider = ({
19
33
  children,
20
34
  persistOptions,
@@ -23,23 +37,23 @@ export const PersistQueryClientProvider = ({
23
37
  ...props
24
38
  }: PersistQueryClientProviderProps): React.JSX.Element => {
25
39
  const [isRestoring, setIsRestoring] = React.useState(true)
26
- const refs = React.useRef({ persistOptions, onSuccess, onError })
27
- const didRestore = React.useRef(false)
40
+ const optionsRef = React.useRef({ persistOptions, onSuccess, onError })
41
+ const didRestoreRef = React.useRef(false)
28
42
 
29
43
  React.useEffect(() => {
30
- refs.current = { persistOptions, onSuccess, onError }
44
+ optionsRef.current = { persistOptions, onSuccess, onError }
31
45
  })
32
46
 
33
47
  React.useEffect(() => {
34
48
  const options = {
35
- ...refs.current.persistOptions,
49
+ ...optionsRef.current.persistOptions,
36
50
  queryClient: props.client,
37
51
  }
38
- if (!didRestore.current) {
39
- didRestore.current = true
52
+ if (!didRestoreRef.current) {
53
+ didRestoreRef.current = true
40
54
  persistQueryClientRestore(options)
41
- .then(() => refs.current.onSuccess?.())
42
- .catch(() => refs.current.onError?.())
55
+ .then(() => optionsRef.current.onSuccess?.())
56
+ .catch(() => optionsRef.current.onError?.())
43
57
  .finally(() => {
44
58
  setIsRestoring(false)
45
59
  })