@tanstack/react-query-persist-client 5.104.0 → 5.104.1
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/PersistQueryClientProvider.cjs +10 -10
- package/build/legacy/PersistQueryClientProvider.cjs.map +1 -1
- package/build/legacy/PersistQueryClientProvider.js +10 -10
- package/build/legacy/PersistQueryClientProvider.js.map +1 -1
- package/build/modern/PersistQueryClientProvider.cjs +7 -7
- package/build/modern/PersistQueryClientProvider.cjs.map +1 -1
- package/build/modern/PersistQueryClientProvider.js +7 -7
- package/build/modern/PersistQueryClientProvider.js.map +1 -1
- package/package.json +8 -6
- package/src/PersistQueryClientProvider.tsx +8 -8
|
@@ -30,14 +30,14 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
30
30
|
//#region src/PersistQueryClientProvider.tsx
|
|
31
31
|
const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
|
|
32
32
|
const [isRestoring, setIsRestoring] = react.useState(true);
|
|
33
|
-
const
|
|
33
|
+
const optionsRef = react.useRef({
|
|
34
34
|
persistOptions,
|
|
35
35
|
onSuccess,
|
|
36
36
|
onError
|
|
37
37
|
});
|
|
38
|
-
const
|
|
38
|
+
const didRestoreRef = react.useRef(false);
|
|
39
39
|
react.useEffect(() => {
|
|
40
|
-
|
|
40
|
+
optionsRef.current = {
|
|
41
41
|
persistOptions,
|
|
42
42
|
onSuccess,
|
|
43
43
|
onError
|
|
@@ -45,17 +45,17 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
|
|
|
45
45
|
});
|
|
46
46
|
react.useEffect(() => {
|
|
47
47
|
const options = {
|
|
48
|
-
...
|
|
48
|
+
...optionsRef.current.persistOptions,
|
|
49
49
|
queryClient: props.client
|
|
50
50
|
};
|
|
51
|
-
if (!
|
|
52
|
-
|
|
51
|
+
if (!didRestoreRef.current) {
|
|
52
|
+
didRestoreRef.current = true;
|
|
53
53
|
(0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() => {
|
|
54
|
-
var
|
|
55
|
-
return (
|
|
54
|
+
var _optionsRef$current$o, _optionsRef$current;
|
|
55
|
+
return (_optionsRef$current$o = (_optionsRef$current = optionsRef.current).onSuccess) === null || _optionsRef$current$o === void 0 ? void 0 : _optionsRef$current$o.call(_optionsRef$current);
|
|
56
56
|
}).catch(() => {
|
|
57
|
-
var
|
|
58
|
-
return (
|
|
57
|
+
var _optionsRef$current$o2, _optionsRef$current2;
|
|
58
|
+
return (_optionsRef$current$o2 = (_optionsRef$current2 = optionsRef.current).onError) === null || _optionsRef$current$o2 === void 0 ? void 0 : _optionsRef$current$o2.call(_optionsRef$current2);
|
|
59
59
|
}).finally(() => {
|
|
60
60
|
setIsRestoring(false);
|
|
61
61
|
});
|
|
@@ -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
|
|
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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,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"}
|
|
@@ -6,14 +6,14 @@ import { jsx } from "react/jsx-runtime";
|
|
|
6
6
|
//#region src/PersistQueryClientProvider.tsx
|
|
7
7
|
const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
|
|
8
8
|
const [isRestoring, setIsRestoring] = React.useState(true);
|
|
9
|
-
const
|
|
9
|
+
const optionsRef = React.useRef({
|
|
10
10
|
persistOptions,
|
|
11
11
|
onSuccess,
|
|
12
12
|
onError
|
|
13
13
|
});
|
|
14
|
-
const
|
|
14
|
+
const didRestoreRef = React.useRef(false);
|
|
15
15
|
React.useEffect(() => {
|
|
16
|
-
|
|
16
|
+
optionsRef.current = {
|
|
17
17
|
persistOptions,
|
|
18
18
|
onSuccess,
|
|
19
19
|
onError
|
|
@@ -21,17 +21,17 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
|
|
|
21
21
|
});
|
|
22
22
|
React.useEffect(() => {
|
|
23
23
|
const options = {
|
|
24
|
-
...
|
|
24
|
+
...optionsRef.current.persistOptions,
|
|
25
25
|
queryClient: props.client
|
|
26
26
|
};
|
|
27
|
-
if (!
|
|
28
|
-
|
|
27
|
+
if (!didRestoreRef.current) {
|
|
28
|
+
didRestoreRef.current = true;
|
|
29
29
|
persistQueryClientRestore(options).then(() => {
|
|
30
|
-
var
|
|
31
|
-
return (
|
|
30
|
+
var _optionsRef$current$o, _optionsRef$current;
|
|
31
|
+
return (_optionsRef$current$o = (_optionsRef$current = optionsRef.current).onSuccess) === null || _optionsRef$current$o === void 0 ? void 0 : _optionsRef$current$o.call(_optionsRef$current);
|
|
32
32
|
}).catch(() => {
|
|
33
|
-
var
|
|
34
|
-
return (
|
|
33
|
+
var _optionsRef$current$o2, _optionsRef$current2;
|
|
34
|
+
return (_optionsRef$current$o2 = (_optionsRef$current2 = optionsRef.current).onError) === null || _optionsRef$current$o2 === void 0 ? void 0 : _optionsRef$current$o2.call(_optionsRef$current2);
|
|
35
35
|
}).finally(() => {
|
|
36
36
|
setIsRestoring(false);
|
|
37
37
|
});
|
|
@@ -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
|
|
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 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":";;;;;;AAiBA,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"}
|
|
@@ -30,14 +30,14 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
30
30
|
//#region src/PersistQueryClientProvider.tsx
|
|
31
31
|
const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
|
|
32
32
|
const [isRestoring, setIsRestoring] = react.useState(true);
|
|
33
|
-
const
|
|
33
|
+
const optionsRef = react.useRef({
|
|
34
34
|
persistOptions,
|
|
35
35
|
onSuccess,
|
|
36
36
|
onError
|
|
37
37
|
});
|
|
38
|
-
const
|
|
38
|
+
const didRestoreRef = react.useRef(false);
|
|
39
39
|
react.useEffect(() => {
|
|
40
|
-
|
|
40
|
+
optionsRef.current = {
|
|
41
41
|
persistOptions,
|
|
42
42
|
onSuccess,
|
|
43
43
|
onError
|
|
@@ -45,12 +45,12 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
|
|
|
45
45
|
});
|
|
46
46
|
react.useEffect(() => {
|
|
47
47
|
const options = {
|
|
48
|
-
...
|
|
48
|
+
...optionsRef.current.persistOptions,
|
|
49
49
|
queryClient: props.client
|
|
50
50
|
};
|
|
51
|
-
if (!
|
|
52
|
-
|
|
53
|
-
(0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() =>
|
|
51
|
+
if (!didRestoreRef.current) {
|
|
52
|
+
didRestoreRef.current = true;
|
|
53
|
+
(0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() => optionsRef.current.onSuccess?.()).catch(() => optionsRef.current.onError?.()).finally(() => {
|
|
54
54
|
setIsRestoring(false);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -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
|
|
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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,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"}
|
|
@@ -6,14 +6,14 @@ import { jsx } from "react/jsx-runtime";
|
|
|
6
6
|
//#region src/PersistQueryClientProvider.tsx
|
|
7
7
|
const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
|
|
8
8
|
const [isRestoring, setIsRestoring] = React.useState(true);
|
|
9
|
-
const
|
|
9
|
+
const optionsRef = React.useRef({
|
|
10
10
|
persistOptions,
|
|
11
11
|
onSuccess,
|
|
12
12
|
onError
|
|
13
13
|
});
|
|
14
|
-
const
|
|
14
|
+
const didRestoreRef = React.useRef(false);
|
|
15
15
|
React.useEffect(() => {
|
|
16
|
-
|
|
16
|
+
optionsRef.current = {
|
|
17
17
|
persistOptions,
|
|
18
18
|
onSuccess,
|
|
19
19
|
onError
|
|
@@ -21,12 +21,12 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
|
|
|
21
21
|
});
|
|
22
22
|
React.useEffect(() => {
|
|
23
23
|
const options = {
|
|
24
|
-
...
|
|
24
|
+
...optionsRef.current.persistOptions,
|
|
25
25
|
queryClient: props.client
|
|
26
26
|
};
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
persistQueryClientRestore(options).then(() =>
|
|
27
|
+
if (!didRestoreRef.current) {
|
|
28
|
+
didRestoreRef.current = true;
|
|
29
|
+
persistQueryClientRestore(options).then(() => optionsRef.current.onSuccess?.()).catch(() => optionsRef.current.onError?.()).finally(() => {
|
|
30
30
|
setIsRestoring(false);
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -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
|
|
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 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":";;;;;;AAiBA,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.
|
|
3
|
+
"version": "5.104.1",
|
|
4
4
|
"description": "React bindings to work with persisters in TanStack/react-query",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,19 +40,21 @@
|
|
|
40
40
|
"!src/__tests__"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tanstack/query-persist-client-core": "5.104.
|
|
43
|
+
"@tanstack/query-persist-client-core": "5.104.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
+
"@eslint-react/eslint-plugin": "^5.21.0",
|
|
46
47
|
"@tanstack/query-test-utils": "0.0.0",
|
|
47
|
-
"@tanstack/react-query": "5.104.
|
|
48
|
+
"@tanstack/react-query": "5.104.1",
|
|
48
49
|
"@testing-library/react": "^16.1.0",
|
|
49
50
|
"@types/react": "^19.2.7",
|
|
50
51
|
"@vitejs/plugin-react": "^6.1.1",
|
|
51
|
-
"
|
|
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.
|
|
57
|
+
"@tanstack/react-query": "^5.104.1",
|
|
56
58
|
"react": "^18 || ^19"
|
|
57
59
|
},
|
|
58
60
|
"scripts": {
|
|
@@ -23,23 +23,23 @@ export const PersistQueryClientProvider = ({
|
|
|
23
23
|
...props
|
|
24
24
|
}: PersistQueryClientProviderProps): React.JSX.Element => {
|
|
25
25
|
const [isRestoring, setIsRestoring] = React.useState(true)
|
|
26
|
-
const
|
|
27
|
-
const
|
|
26
|
+
const optionsRef = React.useRef({ persistOptions, onSuccess, onError })
|
|
27
|
+
const didRestoreRef = React.useRef(false)
|
|
28
28
|
|
|
29
29
|
React.useEffect(() => {
|
|
30
|
-
|
|
30
|
+
optionsRef.current = { persistOptions, onSuccess, onError }
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
React.useEffect(() => {
|
|
34
34
|
const options = {
|
|
35
|
-
...
|
|
35
|
+
...optionsRef.current.persistOptions,
|
|
36
36
|
queryClient: props.client,
|
|
37
37
|
}
|
|
38
|
-
if (!
|
|
39
|
-
|
|
38
|
+
if (!didRestoreRef.current) {
|
|
39
|
+
didRestoreRef.current = true
|
|
40
40
|
persistQueryClientRestore(options)
|
|
41
|
-
.then(() =>
|
|
42
|
-
.catch(() =>
|
|
41
|
+
.then(() => optionsRef.current.onSuccess?.())
|
|
42
|
+
.catch(() => optionsRef.current.onError?.())
|
|
43
43
|
.finally(() => {
|
|
44
44
|
setIsRestoring(false)
|
|
45
45
|
})
|