@tanstack/react-query-persist-client 4.24.10 → 5.0.0-alpha.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/lib/PersistQueryClientProvider.d.ts +0 -1
- package/build/lib/PersistQueryClientProvider.esm.js +3 -2
- package/build/lib/PersistQueryClientProvider.esm.js.map +1 -1
- package/build/lib/PersistQueryClientProvider.js +7 -9
- package/build/lib/PersistQueryClientProvider.js.map +1 -1
- package/build/lib/PersistQueryClientProvider.mjs +3 -2
- package/build/lib/PersistQueryClientProvider.mjs.map +1 -1
- package/build/lib/__tests__/utils.d.ts +0 -6
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +0 -2
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js +1 -5
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +0 -2
- package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -1
- package/build/lib/index.js +0 -2
- package/build/lib/index.js.map +1 -1
- package/build/umd/index.development.js +42 -52
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +4 -6
- package/src/__tests__/PersistQueryClientProvider.test.tsx +73 -43
- package/src/__tests__/utils.ts +1 -8
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core';
|
|
3
2
|
import type { QueryClientProviderProps } from '@tanstack/react-query';
|
|
4
3
|
export declare type PersistQueryClientProviderProps = QueryClientProviderProps & {
|
|
@@ -24,12 +24,13 @@ const PersistQueryClientProvider = ({
|
|
|
24
24
|
React.useEffect(() => {
|
|
25
25
|
let isStale = false;
|
|
26
26
|
setIsRestoring(true);
|
|
27
|
-
const [unsubscribe, promise] = persistQueryClient({
|
|
27
|
+
const [unsubscribe, promise] = persistQueryClient({
|
|
28
|
+
...refs.current.persistOptions,
|
|
28
29
|
queryClient: client
|
|
29
30
|
});
|
|
30
31
|
promise.then(() => {
|
|
31
32
|
if (!isStale) {
|
|
32
|
-
refs.current.onSuccess
|
|
33
|
+
refs.current.onSuccess?.();
|
|
33
34
|
setIsRestoring(false);
|
|
34
35
|
}
|
|
35
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.esm.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then"],"mappings":";;;;;AAaO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.esm.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then"],"mappings":";;;;;AAaO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,MAAM;EACNC,QAAQ;EACRC,cAAc;EACdC,SAAS;EACT,GAAGC,KAAAA;AAC4B,CAAC,KAAkB;EAClD,MAAM,CAACC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,14 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
6
4
|
var React = require('react');
|
|
7
5
|
var queryPersistClientCore = require('@tanstack/query-persist-client-core');
|
|
8
6
|
var reactQuery = require('@tanstack/react-query');
|
|
9
7
|
|
|
10
|
-
function
|
|
11
|
-
if (e && e.__esModule) return e;
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
12
9
|
var n = Object.create(null);
|
|
13
10
|
if (e) {
|
|
14
11
|
Object.keys(e).forEach(function (k) {
|
|
@@ -21,11 +18,11 @@ function _interopNamespace(e) {
|
|
|
21
18
|
}
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
|
-
n
|
|
21
|
+
n.default = e;
|
|
25
22
|
return Object.freeze(n);
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
var React__namespace = /*#__PURE__*/
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
29
26
|
|
|
30
27
|
const PersistQueryClientProvider = ({
|
|
31
28
|
client,
|
|
@@ -48,12 +45,13 @@ const PersistQueryClientProvider = ({
|
|
|
48
45
|
React__namespace.useEffect(() => {
|
|
49
46
|
let isStale = false;
|
|
50
47
|
setIsRestoring(true);
|
|
51
|
-
const [unsubscribe, promise] = queryPersistClientCore.persistQueryClient({
|
|
48
|
+
const [unsubscribe, promise] = queryPersistClientCore.persistQueryClient({
|
|
49
|
+
...refs.current.persistOptions,
|
|
52
50
|
queryClient: client
|
|
53
51
|
});
|
|
54
52
|
promise.then(() => {
|
|
55
53
|
if (!isStale) {
|
|
56
|
-
refs.current.onSuccess
|
|
54
|
+
refs.current.onSuccess?.();
|
|
57
55
|
setIsRestoring(false);
|
|
58
56
|
}
|
|
59
57
|
});
|
|
@@ -62,7 +60,7 @@ const PersistQueryClientProvider = ({
|
|
|
62
60
|
unsubscribe();
|
|
63
61
|
};
|
|
64
62
|
}, [client]);
|
|
65
|
-
return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _rollupPluginBabelHelpers
|
|
63
|
+
return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _rollupPluginBabelHelpers.extends({
|
|
66
64
|
client: client
|
|
67
65
|
}, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
|
|
68
66
|
value: isRestoring
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","_extends","IsRestoringProvider"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","_extends","IsRestoringProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,MAAM;EACNC,QAAQ;EACRC,cAAc;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AAEhB,WAAAA;GAAcJ,EAAAA,QAAQ,CAAuB,CACrD,CAAA;AAE1B;;;;"}
|
|
@@ -24,12 +24,13 @@ const PersistQueryClientProvider = ({
|
|
|
24
24
|
React.useEffect(() => {
|
|
25
25
|
let isStale = false;
|
|
26
26
|
setIsRestoring(true);
|
|
27
|
-
const [unsubscribe, promise] = persistQueryClient({
|
|
27
|
+
const [unsubscribe, promise] = persistQueryClient({
|
|
28
|
+
...refs.current.persistOptions,
|
|
28
29
|
queryClient: client
|
|
29
30
|
});
|
|
30
31
|
promise.then(() => {
|
|
31
32
|
if (!isStale) {
|
|
32
|
-
refs.current.onSuccess
|
|
33
|
+
refs.current.onSuccess?.();
|
|
33
34
|
setIsRestoring(false);
|
|
34
35
|
}
|
|
35
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.mjs","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then"],"mappings":";;;;;AAaO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.mjs","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then"],"mappings":";;;;;AAaO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,MAAM;EACNC,QAAQ;EACRC,cAAc;EACdC,SAAS;EACT,GAAGC,KAAAA;AAC4B,CAAC,KAAkB;EAClD,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAC1D,EAAA,MAAMC,IAAI,GAAGF,KAAK,CAACG,MAAM,CAAC;IAAER,cAAc;AAAEC,IAAAA,SAAAA;AAAU,GAAC,CAAC,CAAA;EAExDI,KAAK,CAACI,SAAS,CAAC,MAAM;IACpBF,IAAI,CAACG,OAAO,GAAG;MAAEV,cAAc;AAAEC,MAAAA,SAAAA;KAAW,CAAA;AAC9C,GAAC,CAAC,CAAA;EAEFI,KAAK,CAACI,SAAS,CAAC,MAAM;IACpB,IAAIE,OAAO,GAAG,KAAK,CAAA;IACnBP,cAAc,CAAC,IAAI,CAAC,CAAA;AACpB,IAAA,MAAM,CAACQ,WAAW,EAAEC,OAAO,CAAC,GAAGC,kBAAkB,CAAC;AAChD,MAAA,GAAGP,IAAI,CAACG,OAAO,CAACV,cAAc;AAC9Be,MAAAA,WAAW,EAAEjB,MAAAA;AACf,KAAC,CAAC,CAAA;IAEFe,OAAO,CAACG,IAAI,CAAC,MAAM;MACjB,IAAI,CAACL,OAAO,EAAE;AACZJ,QAAAA,IAAI,CAACG,OAAO,CAACT,SAAS,IAAI,CAAA;QAC1BG,cAAc,CAAC,KAAK,CAAC,CAAA;AACvB,OAAA;AACF,KAAC,CAAC,CAAA;AAEF,IAAA,OAAO,MAAM;AACXO,MAAAA,OAAO,GAAG,IAAI,CAAA;AACdC,MAAAA,WAAW,EAAE,CAAA;KACd,CAAA;AACH,GAAC,EAAE,CAACd,MAAM,CAAC,CAAC,CAAA;AAEZ,EAAA,oBACE,oBAAC,mBAAmB,EAAA,QAAA,CAAA;AAAC,IAAA,MAAM,EAAEA,MAAAA;GAAYI,EAAAA,KAAK,CAC5C,eAAA,KAAA,CAAA,aAAA,CAAC,mBAAmB,EAAA;AAAC,IAAA,KAAK,EAAEC,WAAAA;GAAcJ,EAAAA,QAAQ,CAAuB,CACrD,CAAA;AAE1B;;;;"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
1
|
/// <reference types="node" />
|
|
3
2
|
import type { QueryClientConfig } from '@tanstack/query-core';
|
|
4
3
|
import { QueryClient } from '@tanstack/query-core';
|
|
5
4
|
export declare function createQueryClient(config?: QueryClientConfig): QueryClient;
|
|
6
|
-
export declare const mockLogger: {
|
|
7
|
-
log: jest.Mock<any, any>;
|
|
8
|
-
warn: jest.Mock<any, any>;
|
|
9
|
-
error: jest.Mock<any, any>;
|
|
10
|
-
};
|
|
11
5
|
export declare function queryKey(): Array<string>;
|
|
12
6
|
export declare function sleep(timeout: number): Promise<void>;
|
|
13
7
|
export declare function setActTimeout(fn: () => void, ms?: number): NodeJS.Timeout;
|
|
@@ -2,14 +2,12 @@ function _extends() {
|
|
|
2
2
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
3
3
|
for (var i = 1; i < arguments.length; i++) {
|
|
4
4
|
var source = arguments[i];
|
|
5
|
-
|
|
6
5
|
for (var key in source) {
|
|
7
6
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
7
|
target[key] = source[key];
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
return target;
|
|
14
12
|
};
|
|
15
13
|
return _extends.apply(this, arguments);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_rollupPluginBabelHelpers.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
function _extends() {
|
|
6
4
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
7
5
|
for (var i = 1; i < arguments.length; i++) {
|
|
8
6
|
var source = arguments[i];
|
|
9
|
-
|
|
10
7
|
for (var key in source) {
|
|
11
8
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
12
9
|
target[key] = source[key];
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
return target;
|
|
18
14
|
};
|
|
19
15
|
return _extends.apply(this, arguments);
|
|
20
16
|
}
|
|
21
17
|
|
|
22
|
-
exports
|
|
18
|
+
exports.extends = _extends;
|
|
23
19
|
//# sourceMappingURL=_rollupPluginBabelHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
|
@@ -2,14 +2,12 @@ function _extends() {
|
|
|
2
2
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
3
3
|
for (var i = 1; i < arguments.length; i++) {
|
|
4
4
|
var source = arguments[i];
|
|
5
|
-
|
|
6
5
|
for (var key in source) {
|
|
7
6
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
7
|
target[key] = source[key];
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
return target;
|
|
14
12
|
};
|
|
15
13
|
return _extends.apply(this, arguments);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_rollupPluginBabelHelpers.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
|
package/build/lib/index.js
CHANGED
package/build/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQueryPersistClient = {}, global.React, global.ReactQuery));
|
|
5
5
|
})(this, (function (exports, React, reactQuery) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function
|
|
8
|
-
if (e && e.__esModule) return e;
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
9
8
|
var n = Object.create(null);
|
|
10
9
|
if (e) {
|
|
11
10
|
Object.keys(e).forEach(function (k) {
|
|
@@ -18,25 +17,27 @@
|
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
|
-
n
|
|
20
|
+
n.default = e;
|
|
22
21
|
return Object.freeze(n);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
var React__namespace = /*#__PURE__*/
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
25
|
|
|
27
26
|
// TYPES
|
|
27
|
+
|
|
28
28
|
// FUNCTIONS
|
|
29
|
+
|
|
29
30
|
function dehydrateMutation(mutation) {
|
|
30
31
|
return {
|
|
31
32
|
mutationKey: mutation.options.mutationKey,
|
|
32
33
|
state: mutation.state
|
|
33
34
|
};
|
|
34
|
-
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Most config is not dehydrated but instead meant to configure again when
|
|
35
38
|
// consuming the de/rehydrated data, typically with useQuery on the client.
|
|
36
39
|
// Sometimes it might make sense to prefetch data on the server and include
|
|
37
40
|
// in the html-payload, but not consume it on the initial render.
|
|
38
|
-
|
|
39
|
-
|
|
40
41
|
function dehydrateQuery(query) {
|
|
41
42
|
return {
|
|
42
43
|
state: query.state,
|
|
@@ -44,7 +45,6 @@
|
|
|
44
45
|
queryHash: query.queryHash
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
|
-
|
|
48
48
|
function defaultShouldDehydrateMutation(mutation) {
|
|
49
49
|
return mutation.state.isPaused;
|
|
50
50
|
}
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
function dehydrate(client, options = {}) {
|
|
55
55
|
const mutations = [];
|
|
56
56
|
const queries = [];
|
|
57
|
-
|
|
58
57
|
if (options.dehydrateMutations !== false) {
|
|
59
58
|
const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
|
|
60
59
|
client.getMutationCache().getAll().forEach(mutation => {
|
|
@@ -63,7 +62,6 @@
|
|
|
63
62
|
}
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
|
-
|
|
67
65
|
if (options.dehydrateQueries !== false) {
|
|
68
66
|
const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
|
|
69
67
|
client.getQueryCache().getAll().forEach(query => {
|
|
@@ -72,7 +70,6 @@
|
|
|
72
70
|
}
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
|
-
|
|
76
73
|
return {
|
|
77
74
|
mutations,
|
|
78
75
|
queries
|
|
@@ -82,40 +79,40 @@
|
|
|
82
79
|
if (typeof dehydratedState !== 'object' || dehydratedState === null) {
|
|
83
80
|
return;
|
|
84
81
|
}
|
|
85
|
-
|
|
86
82
|
const mutationCache = client.getMutationCache();
|
|
87
|
-
const queryCache = client.getQueryCache();
|
|
88
|
-
|
|
89
|
-
const mutations = dehydratedState.mutations || []; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
83
|
+
const queryCache = client.getQueryCache();
|
|
90
84
|
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
86
|
+
const mutations = dehydratedState.mutations || [];
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
91
88
|
const queries = dehydratedState.queries || [];
|
|
92
89
|
mutations.forEach(dehydratedMutation => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
mutationCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio = options.defaultOptions) == null ? void 0 : _options$defaultOptio.mutations),
|
|
90
|
+
mutationCache.build(client, {
|
|
91
|
+
...options?.defaultOptions?.mutations,
|
|
96
92
|
mutationKey: dehydratedMutation.mutationKey
|
|
97
93
|
}, dehydratedMutation.state);
|
|
98
94
|
});
|
|
99
95
|
queries.forEach(dehydratedQuery => {
|
|
100
|
-
|
|
96
|
+
const query = queryCache.get(dehydratedQuery.queryHash);
|
|
101
97
|
|
|
102
|
-
|
|
98
|
+
// Reset fetch status to idle in the dehydrated state to avoid
|
|
103
99
|
// query being stuck in fetching state upon hydration
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
const dehydratedQueryState = {
|
|
101
|
+
...dehydratedQuery.state,
|
|
106
102
|
fetchStatus: 'idle'
|
|
107
|
-
};
|
|
103
|
+
};
|
|
108
104
|
|
|
105
|
+
// Do not hydrate if an existing query exists with newer data
|
|
109
106
|
if (query) {
|
|
110
107
|
if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
|
|
111
108
|
query.setState(dehydratedQueryState);
|
|
112
109
|
}
|
|
113
|
-
|
|
114
110
|
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
111
|
+
}
|
|
117
112
|
|
|
118
|
-
|
|
113
|
+
// Restore query
|
|
114
|
+
queryCache.build(client, {
|
|
115
|
+
...options?.defaultOptions?.queries,
|
|
119
116
|
queryKey: dehydratedQuery.queryKey,
|
|
120
117
|
queryHash: dehydratedQuery.queryHash
|
|
121
118
|
}, dehydratedQueryState);
|
|
@@ -127,18 +124,16 @@
|
|
|
127
124
|
* Useful for persist, where we only want to trigger save when cache is changed.
|
|
128
125
|
*/
|
|
129
126
|
const cacheableEventTypes = ['added', 'removed', 'updated'];
|
|
130
|
-
|
|
131
127
|
function isCacheableEventType(eventType) {
|
|
132
128
|
return cacheableEventTypes.includes(eventType);
|
|
133
129
|
}
|
|
130
|
+
|
|
134
131
|
/**
|
|
135
132
|
* Restores persisted data to the QueryCache
|
|
136
133
|
* - data obtained from persister.restoreClient
|
|
137
134
|
* - data is hydrated using hydrateOptions
|
|
138
135
|
* If data is expired, busted, empty, or throws, it runs persister.removeClient
|
|
139
136
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
137
|
async function persistQueryClientRestore({
|
|
143
138
|
queryClient,
|
|
144
139
|
persister,
|
|
@@ -148,12 +143,10 @@
|
|
|
148
143
|
}) {
|
|
149
144
|
try {
|
|
150
145
|
const persistedClient = await persister.restoreClient();
|
|
151
|
-
|
|
152
146
|
if (persistedClient) {
|
|
153
147
|
if (persistedClient.timestamp) {
|
|
154
148
|
const expired = Date.now() - persistedClient.timestamp > maxAge;
|
|
155
149
|
const busted = persistedClient.buster !== buster;
|
|
156
|
-
|
|
157
150
|
if (expired || busted) {
|
|
158
151
|
persister.removeClient();
|
|
159
152
|
} else {
|
|
@@ -165,19 +158,18 @@
|
|
|
165
158
|
}
|
|
166
159
|
} catch (err) {
|
|
167
160
|
{
|
|
168
|
-
|
|
169
|
-
|
|
161
|
+
console.error(err);
|
|
162
|
+
console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
|
|
170
163
|
}
|
|
171
|
-
|
|
172
164
|
persister.removeClient();
|
|
173
165
|
}
|
|
174
166
|
}
|
|
167
|
+
|
|
175
168
|
/**
|
|
176
169
|
* Persists data from the QueryCache
|
|
177
170
|
* - data dehydrated using dehydrateOptions
|
|
178
171
|
* - data is persisted using persister.persistClient
|
|
179
172
|
*/
|
|
180
|
-
|
|
181
173
|
async function persistQueryClientSave({
|
|
182
174
|
queryClient,
|
|
183
175
|
persister,
|
|
@@ -191,11 +183,11 @@
|
|
|
191
183
|
};
|
|
192
184
|
await persister.persistClient(persistClient);
|
|
193
185
|
}
|
|
186
|
+
|
|
194
187
|
/**
|
|
195
188
|
* Subscribe to QueryCache and MutationCache updates (for persisting)
|
|
196
189
|
* @returns an unsubscribe function (to discontinue monitoring)
|
|
197
190
|
*/
|
|
198
|
-
|
|
199
191
|
function persistQueryClientSubscribe(props) {
|
|
200
192
|
const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {
|
|
201
193
|
if (isCacheableEventType(event.type)) {
|
|
@@ -212,20 +204,19 @@
|
|
|
212
204
|
unusbscribeMutationCache();
|
|
213
205
|
};
|
|
214
206
|
}
|
|
207
|
+
|
|
215
208
|
/**
|
|
216
209
|
* Restores persisted data to QueryCache and persists further changes.
|
|
217
210
|
*/
|
|
218
|
-
|
|
219
211
|
function persistQueryClient(props) {
|
|
220
212
|
let hasUnsubscribed = false;
|
|
221
213
|
let persistQueryClientUnsubscribe;
|
|
222
|
-
|
|
223
214
|
const unsubscribe = () => {
|
|
224
215
|
hasUnsubscribed = true;
|
|
225
|
-
persistQueryClientUnsubscribe
|
|
226
|
-
};
|
|
227
|
-
|
|
216
|
+
persistQueryClientUnsubscribe?.();
|
|
217
|
+
};
|
|
228
218
|
|
|
219
|
+
// Attempt restore
|
|
229
220
|
const restorePromise = persistQueryClientRestore(props).then(() => {
|
|
230
221
|
if (!hasUnsubscribed) {
|
|
231
222
|
// Subscribe to changes in the query cache to trigger the save
|
|
@@ -240,21 +231,23 @@
|
|
|
240
231
|
}) => {
|
|
241
232
|
const mutations = [...persistedClient.clientState.mutations];
|
|
242
233
|
const queries = [...persistedClient.clientState.queries];
|
|
243
|
-
const client = {
|
|
234
|
+
const client = {
|
|
235
|
+
...persistedClient,
|
|
244
236
|
clientState: {
|
|
245
237
|
mutations,
|
|
246
238
|
queries
|
|
247
239
|
}
|
|
248
|
-
};
|
|
240
|
+
};
|
|
249
241
|
|
|
250
|
-
|
|
242
|
+
// sort queries by dataUpdatedAt (oldest first)
|
|
243
|
+
const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);
|
|
251
244
|
|
|
245
|
+
// clean oldest query
|
|
252
246
|
if (sortedQueries.length > 0) {
|
|
253
247
|
const oldestData = sortedQueries.shift();
|
|
254
248
|
client.clientState.queries = queries.filter(q => q !== oldestData);
|
|
255
249
|
return client;
|
|
256
250
|
}
|
|
257
|
-
|
|
258
251
|
return undefined;
|
|
259
252
|
};
|
|
260
253
|
|
|
@@ -262,14 +255,12 @@
|
|
|
262
255
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
263
256
|
for (var i = 1; i < arguments.length; i++) {
|
|
264
257
|
var source = arguments[i];
|
|
265
|
-
|
|
266
258
|
for (var key in source) {
|
|
267
259
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
268
260
|
target[key] = source[key];
|
|
269
261
|
}
|
|
270
262
|
}
|
|
271
263
|
}
|
|
272
|
-
|
|
273
264
|
return target;
|
|
274
265
|
};
|
|
275
266
|
return _extends.apply(this, arguments);
|
|
@@ -296,12 +287,13 @@
|
|
|
296
287
|
React__namespace.useEffect(() => {
|
|
297
288
|
let isStale = false;
|
|
298
289
|
setIsRestoring(true);
|
|
299
|
-
const [unsubscribe, promise] = persistQueryClient({
|
|
290
|
+
const [unsubscribe, promise] = persistQueryClient({
|
|
291
|
+
...refs.current.persistOptions,
|
|
300
292
|
queryClient: client
|
|
301
293
|
});
|
|
302
294
|
promise.then(() => {
|
|
303
295
|
if (!isStale) {
|
|
304
|
-
refs.current.onSuccess
|
|
296
|
+
refs.current.onSuccess?.();
|
|
305
297
|
setIsRestoring(false);
|
|
306
298
|
}
|
|
307
299
|
});
|
|
@@ -324,7 +316,5 @@
|
|
|
324
316
|
exports.persistQueryClientSubscribe = persistQueryClientSubscribe;
|
|
325
317
|
exports.removeOldestQuery = removeOldestQuery;
|
|
326
318
|
|
|
327
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
328
|
-
|
|
329
319
|
}));
|
|
330
320
|
//# sourceMappingURL=index.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.development.js","sources":["../../../query-core/build/lib/hydration.mjs","../../../query-persist-client-core/build/lib/persist.mjs","../../../query-persist-client-core/build/lib/retryStrategies.mjs","../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["// TYPES\n// FUNCTIONS\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state\n };\n} // Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\n\n\nfunction dehydrateQuery(query) {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash\n };\n}\n\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === 'success';\n}\nfunction dehydrate(client, options = {}) {\n const mutations = [];\n const queries = [];\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;\n client.getMutationCache().getAll().forEach(mutation => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation));\n }\n });\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;\n client.getQueryCache().getAll().forEach(query => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query));\n }\n });\n }\n\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return;\n }\n\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache(); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\n const mutations = dehydratedState.mutations || []; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\n const queries = dehydratedState.queries || [];\n mutations.forEach(dehydratedMutation => {\n var _options$defaultOptio;\n\n mutationCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio = options.defaultOptions) == null ? void 0 : _options$defaultOptio.mutations),\n mutationKey: dehydratedMutation.mutationKey\n }, dehydratedMutation.state);\n });\n queries.forEach(dehydratedQuery => {\n var _options$defaultOptio2;\n\n const query = queryCache.get(dehydratedQuery.queryHash); // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n\n const dehydratedQueryState = { ...dehydratedQuery.state,\n fetchStatus: 'idle'\n }; // Do not hydrate if an existing query exists with newer data\n\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState);\n }\n\n return;\n } // Restore query\n\n\n queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash\n }, dehydratedQueryState);\n });\n}\n\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };\n//# sourceMappingURL=hydration.mjs.map\n","import { hydrate, dehydrate } from '@tanstack/query-core';\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheableEventTypes = ['added', 'removed', 'updated'];\n\nfunction isCacheableEventType(eventType) {\n return cacheableEventTypes.includes(eventType);\n}\n/**\n * Restores persisted data to the QueryCache\n * - data obtained from persister.restoreClient\n * - data is hydrated using hydrateOptions\n * If data is expired, busted, empty, or throws, it runs persister.removeClient\n */\n\n\nasync function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions\n}) {\n try {\n const persistedClient = await persister.restoreClient();\n\n if (persistedClient) {\n if (persistedClient.timestamp) {\n const expired = Date.now() - persistedClient.timestamp > maxAge;\n const busted = persistedClient.buster !== buster;\n\n if (expired || busted) {\n persister.removeClient();\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions);\n }\n } else {\n persister.removeClient();\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n queryClient.getLogger().error(err);\n queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');\n }\n\n persister.removeClient();\n }\n}\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\n\nasync function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions\n}) {\n const persistClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions)\n };\n await persister.persistClient(persistClient);\n}\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\n\nfunction persistQueryClientSubscribe(props) {\n const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n return () => {\n unsubscribeQueryCache();\n unusbscribeMutationCache();\n };\n}\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\n\nfunction persistQueryClient(props) {\n let hasUnsubscribed = false;\n let persistQueryClientUnsubscribe;\n\n const unsubscribe = () => {\n hasUnsubscribed = true;\n persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();\n }; // Attempt restore\n\n\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);\n }\n });\n return [unsubscribe, restorePromise];\n}\n\nexport { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };\n//# sourceMappingURL=persist.mjs.map\n","const removeOldestQuery = ({\n persistedClient\n}) => {\n const mutations = [...persistedClient.clientState.mutations];\n const queries = [...persistedClient.clientState.queries];\n const client = { ...persistedClient,\n clientState: {\n mutations,\n queries\n }\n }; // sort queries by dataUpdatedAt (oldest first)\n\n const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query\n\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift();\n client.clientState.queries = queries.filter(q => q !== oldestData);\n return client;\n }\n\n return undefined;\n};\n\nexport { removeOldestQuery };\n//# sourceMappingURL=retryStrategies.mjs.map\n","'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","IsRestoringProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;EACA;EACA,SAAS,iBAAiB,CAAC,QAAQ,EAAE;EACrC,EAAE,OAAO;EACT,IAAI,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,WAAW;EAC7C,IAAI,KAAK,EAAE,QAAQ,CAAC,KAAK;EACzB,GAAG,CAAC;EACJ,CAAC;EACD;EACA;EACA;AACA;AACA;EACA,SAAS,cAAc,CAAC,KAAK,EAAE;EAC/B,EAAE,OAAO;EACT,IAAI,KAAK,EAAE,KAAK,CAAC,KAAK;EACtB,IAAI,QAAQ,EAAE,KAAK,CAAC,QAAQ;EAC5B,IAAI,SAAS,EAAE,KAAK,CAAC,SAAS;EAC9B,GAAG,CAAC;EACJ,CAAC;AACD;EACA,SAAS,8BAA8B,CAAC,QAAQ,EAAE;EAClD,EAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;EACjC,CAAC;EACD,SAAS,2BAA2B,CAAC,KAAK,EAAE;EAC5C,EAAE,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC;EAC1C,CAAC;EACD,SAAS,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE;EACzC,EAAE,MAAM,SAAS,GAAG,EAAE,CAAC;EACvB,EAAE,MAAM,OAAO,GAAG,EAAE,CAAC;AACrB;EACA,EAAE,IAAI,OAAO,CAAC,kBAAkB,KAAK,KAAK,EAAE;EAC5C,IAAI,MAAM,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,IAAI,8BAA8B,CAAC;EACtG,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,IAAI;EAC3D,MAAM,IAAI,uBAAuB,CAAC,QAAQ,CAA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ACY,8BAAD,EAAA,QAAA,CAAA;EAAqB,IAAA,MAAM,EAAEnB,MAAAA;KAAYI,EAAAA,KAAzC,CACE,eAAAG,gBAAA,CAAA,aAAA,CAACa,8BAAD,EAAA;EAAqB,IAAA,KAAK,EAAEf,WAAAA;KAAcJ,EAAAA,QAA1C,CADF,CADF,CAAA;EAKD;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.development.js","sources":["../../../query-core/build/lib/hydration.mjs","../../../query-persist-client-core/build/lib/persist.mjs","../../../query-persist-client-core/build/lib/retryStrategies.mjs","../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["// TYPES\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state\n };\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query) {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash\n };\n}\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === 'success';\n}\nfunction dehydrate(client, options = {}) {\n const mutations = [];\n const queries = [];\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;\n client.getMutationCache().getAll().forEach(mutation => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation));\n }\n });\n }\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;\n client.getQueryCache().getAll().forEach(query => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query));\n }\n });\n }\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return;\n }\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = dehydratedState.mutations || [];\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = dehydratedState.queries || [];\n mutations.forEach(dehydratedMutation => {\n mutationCache.build(client, {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey\n }, dehydratedMutation.state);\n });\n queries.forEach(dehydratedQuery => {\n const query = queryCache.get(dehydratedQuery.queryHash);\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle'\n };\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState);\n }\n return;\n }\n\n // Restore query\n queryCache.build(client, {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash\n }, dehydratedQueryState);\n });\n}\n\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };\n//# sourceMappingURL=hydration.mjs.map\n","import { hydrate, dehydrate } from '@tanstack/query-core';\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheableEventTypes = ['added', 'removed', 'updated'];\nfunction isCacheableEventType(eventType) {\n return cacheableEventTypes.includes(eventType);\n}\n\n/**\n * Restores persisted data to the QueryCache\n * - data obtained from persister.restoreClient\n * - data is hydrated using hydrateOptions\n * If data is expired, busted, empty, or throws, it runs persister.removeClient\n */\nasync function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions\n}) {\n try {\n const persistedClient = await persister.restoreClient();\n if (persistedClient) {\n if (persistedClient.timestamp) {\n const expired = Date.now() - persistedClient.timestamp > maxAge;\n const busted = persistedClient.buster !== buster;\n if (expired || busted) {\n persister.removeClient();\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions);\n }\n } else {\n persister.removeClient();\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(err);\n console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');\n }\n persister.removeClient();\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nasync function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions\n}) {\n const persistClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions)\n };\n await persister.persistClient(persistClient);\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nfunction persistQueryClientSubscribe(props) {\n const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n return () => {\n unsubscribeQueryCache();\n unusbscribeMutationCache();\n };\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nfunction persistQueryClient(props) {\n let hasUnsubscribed = false;\n let persistQueryClientUnsubscribe;\n const unsubscribe = () => {\n hasUnsubscribed = true;\n persistQueryClientUnsubscribe?.();\n };\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);\n }\n });\n return [unsubscribe, restorePromise];\n}\n\nexport { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };\n//# sourceMappingURL=persist.mjs.map\n","const removeOldestQuery = ({\n persistedClient\n}) => {\n const mutations = [...persistedClient.clientState.mutations];\n const queries = [...persistedClient.clientState.queries];\n const client = {\n ...persistedClient,\n clientState: {\n mutations,\n queries\n }\n };\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift();\n client.clientState.queries = queries.filter(q => q !== oldestData);\n return client;\n }\n return undefined;\n};\n\nexport { removeOldestQuery };\n//# sourceMappingURL=retryStrategies.mjs.map\n","'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale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AACG,OAAO,GAAG;QAAEV,cAAc;EAAEC,MAAAA,SAAAA;OAAW,CAAA;EAC9C,GAAC,CAAC,CAAA;IAEFI,gBAAK,CAACI,SAAS,CAAC,MAAM;MACpB,IAAIE,OAAO,GAAG,KAAK,CAAA;MACnBP,cAAc,CAAC,IAAI,CAAC,CAAA;EACpB,IAAA,MAAM,CAACQ,WAAW,EAAEC,OAAO,CAAC,GAAGC,kBAAkB,CAAC;EAChD,MAAA,GAAGP,IAAI,CAACG,OAAO,CAACV,cAAc;EAC9Be,MAAAA,WAAW,EAAEjB,MAAAA;EACf,KAAC,CAAC,CAAA;MAEFe,OAAO,CAACG,IAAI,CAAC,MAAM;QACjB,IAAI,CAACL,OAAO,EAAE;EACZJ,QAAAA,IAAI,CAACG,OAAO,CAACT,SAAS,IAAI,CAAA;UAC1BG,cAAc,CAAC,KAAK,CAAC,CAAA;EACvB,OAAA;EACF,KAAC,CAAC,CAAA;EAEF,IAAA,OAAO,MAAM;EACXO,MAAAA,OAAO,GAAG,IAAI,CAAA;EACdC,MAAAA,WAAW,EAAE,CAAA;OACd,CAAA;EACH,GAAC,EAAE,CAACd,MAAM,CAAC,CAAC,CAAA;EAEZ,EAAA,oBACEO,+BAACY,8BAAmB,EAAA,QAAA,CAAA;EAAC,IAAA,MAAM,EAAEnB,MAAAA;KAAYI,EAAAA,KAAK,CAC5C,eAAAG,gBAAA,CAAA,aAAA,CAACa,8BAAmB,EAAA;EAAC,IAAA,KAAK,EAAEf,WAAAA;KAAcJ,EAAAA,QAAQ,CAAuB,CACrD,CAAA;EAE1B;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","react","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryPersistClient={},e.React,e.ReactQuery)}(this,(function(e,t,r){"use strict";function n(e){
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","react","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryPersistClient={},e.React,e.ReactQuery)}(this,(function(e,t,r){"use strict";function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=n(t);function i(e){return e.state.isPaused}function u(e){return"success"===e.state.status}function a(e,t={}){const r=[],n=[];if(!1!==t.dehydrateMutations){const n=t.shouldDehydrateMutation||i;e.getMutationCache().getAll().forEach((e=>{n(e)&&r.push(function(e){return{mutationKey:e.options.mutationKey,state:e.state}}(e))}))}if(!1!==t.dehydrateQueries){const r=t.shouldDehydrateQuery||u;e.getQueryCache().getAll().forEach((e=>{r(e)&&n.push(function(e){return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash}}(e))}))}return{mutations:r,queries:n}}const o=["added","removed","updated"];function c(e){return o.includes(e)}async function l({queryClient:e,persister:t,maxAge:r=864e5,buster:n="",hydrateOptions:s}){try{const i=await t.restoreClient();if(i)if(i.timestamp){const u=Date.now()-i.timestamp>r,a=i.buster!==n;u||a?t.removeClient():function(e,t,r){if("object"!=typeof t||null===t)return;const n=e.getMutationCache(),s=e.getQueryCache(),i=t.mutations||[],u=t.queries||[];i.forEach((t=>{n.build(e,{...r?.defaultOptions?.mutations,mutationKey:t.mutationKey},t.state)})),u.forEach((t=>{const n=s.get(t.queryHash),i={...t.state,fetchStatus:"idle"};n?n.state.dataUpdatedAt<i.dataUpdatedAt&&n.setState(i):s.build(e,{...r?.defaultOptions?.queries,queryKey:t.queryKey,queryHash:t.queryHash},i)}))}(e,i.clientState,s)}else t.removeClient()}catch(e){t.removeClient()}}async function y({queryClient:e,persister:t,buster:r="",dehydrateOptions:n}){const s={buster:r,timestamp:Date.now(),clientState:a(e,n)};await t.persistClient(s)}function f(e){const t=e.queryClient.getQueryCache().subscribe((t=>{c(t.type)&&y(e)})),r=e.queryClient.getMutationCache().subscribe((t=>{c(t.type)&&y(e)}));return()=>{t(),r()}}function d(e){let t,r=!1;return[()=>{r=!0,t?.()},l(e).then((()=>{r||(t=f(e))}))]}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},p.apply(this,arguments)}e.PersistQueryClientProvider=({client:e,children:t,persistOptions:n,onSuccess:i,...u})=>{const[a,o]=s.useState(!0),c=s.useRef({persistOptions:n,onSuccess:i});return s.useEffect((()=>{c.current={persistOptions:n,onSuccess:i}})),s.useEffect((()=>{let t=!1;o(!0);const[r,n]=d({...c.current.persistOptions,queryClient:e});return n.then((()=>{t||(c.current.onSuccess?.(),o(!1))})),()=>{t=!0,r()}}),[e]),s.createElement(r.QueryClientProvider,p({client:e},u),s.createElement(r.IsRestoringProvider,{value:a},t))},e.persistQueryClient=d,e.persistQueryClientRestore=l,e.persistQueryClientSave=y,e.persistQueryClientSubscribe=f,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],r=[...e.clientState.queries],n={...e,clientState:{mutations:t,queries:r}},s=[...r].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(s.length>0){const e=s.shift();return n.clientState.queries=r.filter((t=>t!==e)),n}}}));
|
|
2
2
|
//# sourceMappingURL=index.production.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../../query-core/build/lib/hydration.mjs","../../../query-persist-client-core/build/lib/persist.mjs","../../src/PersistQueryClientProvider.tsx","../../../query-persist-client-core/build/lib/retryStrategies.mjs"],"sourcesContent":["// TYPES\n// FUNCTIONS\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state\n };\n} // Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\n\n\nfunction dehydrateQuery(query) {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash\n };\n}\n\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === 'success';\n}\nfunction dehydrate(client, options = {}) {\n const mutations = [];\n const queries = [];\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;\n client.getMutationCache().getAll().forEach(mutation => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation));\n }\n });\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;\n client.getQueryCache().getAll().forEach(query => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query));\n }\n });\n }\n\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return;\n }\n\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache(); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\n const mutations = dehydratedState.mutations || []; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\n const queries = dehydratedState.queries || [];\n mutations.forEach(dehydratedMutation => {\n var _options$defaultOptio;\n\n mutationCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio = options.defaultOptions) == null ? void 0 : _options$defaultOptio.mutations),\n mutationKey: dehydratedMutation.mutationKey\n }, dehydratedMutation.state);\n });\n queries.forEach(dehydratedQuery => {\n var _options$defaultOptio2;\n\n const query = queryCache.get(dehydratedQuery.queryHash); // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n\n const dehydratedQueryState = { ...dehydratedQuery.state,\n fetchStatus: 'idle'\n }; // Do not hydrate if an existing query exists with newer data\n\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState);\n }\n\n return;\n } // Restore query\n\n\n queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash\n }, dehydratedQueryState);\n });\n}\n\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };\n//# sourceMappingURL=hydration.mjs.map\n","import { hydrate, dehydrate } from '@tanstack/query-core';\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheableEventTypes = ['added', 'removed', 'updated'];\n\nfunction isCacheableEventType(eventType) {\n return cacheableEventTypes.includes(eventType);\n}\n/**\n * Restores persisted data to the QueryCache\n * - data obtained from persister.restoreClient\n * - data is hydrated using hydrateOptions\n * If data is expired, busted, empty, or throws, it runs persister.removeClient\n */\n\n\nasync function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions\n}) {\n try {\n const persistedClient = await persister.restoreClient();\n\n if (persistedClient) {\n if (persistedClient.timestamp) {\n const expired = Date.now() - persistedClient.timestamp > maxAge;\n const busted = persistedClient.buster !== buster;\n\n if (expired || busted) {\n persister.removeClient();\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions);\n }\n } else {\n persister.removeClient();\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n queryClient.getLogger().error(err);\n queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');\n }\n\n persister.removeClient();\n }\n}\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\n\nasync function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions\n}) {\n const persistClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions)\n };\n await persister.persistClient(persistClient);\n}\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\n\nfunction persistQueryClientSubscribe(props) {\n const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n return () => {\n unsubscribeQueryCache();\n unusbscribeMutationCache();\n };\n}\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\n\nfunction persistQueryClient(props) {\n let hasUnsubscribed = false;\n let persistQueryClientUnsubscribe;\n\n const unsubscribe = () => {\n hasUnsubscribed = true;\n persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();\n }; // Attempt restore\n\n\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);\n }\n });\n return [unsubscribe, restorePromise];\n}\n\nexport { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };\n//# sourceMappingURL=persist.mjs.map\n","'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n","const removeOldestQuery = ({\n persistedClient\n}) => {\n const mutations = [...persistedClient.clientState.mutations];\n const queries = [...persistedClient.clientState.queries];\n const client = { ...persistedClient,\n clientState: {\n mutations,\n queries\n }\n }; // sort queries by dataUpdatedAt (oldest first)\n\n const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query\n\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift();\n client.clientState.queries = queries.filter(q => q !== oldestData);\n return client;\n }\n\n return undefined;\n};\n\nexport { removeOldestQuery };\n//# sourceMappingURL=retryStrategies.mjs.map\n"],"names":["defaultShouldDehydrateMutation","mutation","state","isPaused","defaultShouldDehydrateQuery","query","status","dehydrate","client","options","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","mutationKey","dehydrateMutation","dehydrateQueries","shouldDehydrateQuery","getQueryCache","queryKey","queryHash","dehydrateQuery","cacheableEventTypes","isCacheableEventType","eventType","includes","async","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","dehydratedState","mutationCache","queryCache","dehydratedMutation","_options$defaultOptio","build","defaultOptions","dehydratedQuery","_options$defaultOptio2","get","dehydratedQueryState","fetchStatus","dataUpdatedAt","setState","hydrate","clientState","err","persistQueryClientSave","dehydrateOptions","persistClient","persistQueryClientSubscribe","props","unsubscribeQueryCache","subscribe","event","type","unusbscribeMutationCache","persistQueryClient","persistQueryClientUnsubscribe","hasUnsubscribed","then","children","persistOptions","onSuccess","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","QueryClientProvider","_extends","createElement","IsRestoringProvider","value","sortedQueries","sort","a","b","length","oldestData","shift","filter","q"],"mappings":"opBAqBA,SAASA,EAA+BC,GACtC,OAAOA,EAASC,MAAMC,SAExB,SAASC,EAA4BC,GACnC,MAA8B,YAAvBA,EAAMH,MAAMI,OAErB,SAASC,EAAUC,EAAQC,EAAU,IACnC,MAAMC,EAAY,GACZC,EAAU,GAEhB,IAAmC,IAA/BF,EAAQG,mBAA8B,CACxC,MAAMC,EAA0BJ,EAAQI,yBAA2Bb,EACnEQ,EAAOM,mBAAmBC,SAASC,SAAQf,IACrCY,EAAwBZ,IAC1BS,EAAUO,KAjClB,SAA2BhB,GACzB,MAAO,CACLiB,YAAajB,EAASQ,QAAQS,YAC9BhB,MAAOD,EAASC,OA8BGiB,CAAkBlB,OAKvC,IAAiC,IAA7BQ,EAAQW,iBAA4B,CACtC,MAAMC,EAAuBZ,EAAQY,sBAAwBjB,EAC7DI,EAAOc,gBAAgBP,SAASC,SAAQX,IAClCgB,EAAqBhB,IACvBM,EAAQM,KA/BhB,SAAwBZ,GACtB,MAAO,CACLH,MAAOG,EAAMH,MACbqB,SAAUlB,EAAMkB,SAChBC,UAAWnB,EAAMmB,WA2BAC,CAAepB,OAKlC,MAAO,CACLK,YACAC,WC7CJ,MAAMe,EAAsB,CAAC,QAAS,UAAW,WAEjD,SAASC,EAAqBC,GAC5B,OAAOF,EAAoBG,SAASD,GAUtCE,eAAeC,GAA0BC,YACvCA,EAAWC,UACXA,E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EAAE/F,MAAMuD,cAAgByC,EAAEhG,MAAMuD,gBAElF,GAAIsC,EAAcI,OAAS,EAAG,CAC5B,MAAMC,EAAaL,EAAcM,QAEjC,OADA7F,EAAOoD,YAAYjD,QAAUA,EAAQ2F,QAAOC,GAAKA,IAAMH,IAChD5F"}
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../../query-core/build/lib/hydration.mjs","../../../query-persist-client-core/build/lib/persist.mjs","../../src/PersistQueryClientProvider.tsx","../../../query-persist-client-core/build/lib/retryStrategies.mjs"],"sourcesContent":["// TYPES\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state\n };\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query) {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash\n };\n}\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === 'success';\n}\nfunction dehydrate(client, options = {}) {\n const mutations = [];\n const queries = [];\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;\n client.getMutationCache().getAll().forEach(mutation => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation));\n }\n });\n }\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;\n client.getQueryCache().getAll().forEach(query => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query));\n }\n });\n }\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return;\n }\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = dehydratedState.mutations || [];\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = dehydratedState.queries || [];\n mutations.forEach(dehydratedMutation => {\n mutationCache.build(client, {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey\n }, dehydratedMutation.state);\n });\n queries.forEach(dehydratedQuery => {\n const query = queryCache.get(dehydratedQuery.queryHash);\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle'\n };\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState);\n }\n return;\n }\n\n // Restore query\n queryCache.build(client, {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash\n }, dehydratedQueryState);\n });\n}\n\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };\n//# sourceMappingURL=hydration.mjs.map\n","import { hydrate, dehydrate } from '@tanstack/query-core';\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheableEventTypes = ['added', 'removed', 'updated'];\nfunction isCacheableEventType(eventType) {\n return cacheableEventTypes.includes(eventType);\n}\n\n/**\n * Restores persisted data to the QueryCache\n * - data obtained from persister.restoreClient\n * - data is hydrated using hydrateOptions\n * If data is expired, busted, empty, or throws, it runs persister.removeClient\n */\nasync function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions\n}) {\n try {\n const persistedClient = await persister.restoreClient();\n if (persistedClient) {\n if (persistedClient.timestamp) {\n const expired = Date.now() - persistedClient.timestamp > maxAge;\n const busted = persistedClient.buster !== buster;\n if (expired || busted) {\n persister.removeClient();\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions);\n }\n } else {\n persister.removeClient();\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(err);\n console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');\n }\n persister.removeClient();\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nasync function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions\n}) {\n const persistClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions)\n };\n await persister.persistClient(persistClient);\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nfunction persistQueryClientSubscribe(props) {\n const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n return () => {\n unsubscribeQueryCache();\n unusbscribeMutationCache();\n };\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nfunction persistQueryClient(props) {\n let hasUnsubscribed = false;\n let persistQueryClientUnsubscribe;\n const unsubscribe = () => {\n hasUnsubscribed = true;\n persistQueryClientUnsubscribe?.();\n };\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);\n }\n });\n return [unsubscribe, restorePromise];\n}\n\nexport { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };\n//# sourceMappingURL=persist.mjs.map\n","'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n","const removeOldestQuery = ({\n persistedClient\n}) => {\n const mutations = [...persistedClient.clientState.mutations];\n const queries = [...persistedClient.clientState.queries];\n const client = {\n ...persistedClient,\n clientState: {\n mutations,\n queries\n }\n };\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift();\n client.clientState.queries = queries.filter(q => q !== oldestData);\n return client;\n }\n return undefined;\n};\n\nexport { removeOldestQuery };\n//# sourceMappingURL=retryStrategies.mjs.map\n"],"names":["defaultShouldDehydrateMutation","mutation","state","isPaused","defaultShouldDehydrateQuery","query","status","dehydrate","client","options","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","mutationKey","dehydrateMutation","dehydrateQueries","shouldDehydrateQuery","getQueryCache","queryKey","queryHash","dehydrateQuery","cacheableEventTypes","isCacheableEventType","eventType","includes","async","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","dehydratedState","mutationCache","queryCache","dehydratedMutation","build","defaultOptions","dehydratedQuery","get","dehydratedQueryState","fetchStatus","dataUpdatedAt","setState","hydrate","clientState","err","persistQueryClientSave","dehydrateOptions","persistClient","persistQueryClientSubscribe","props","unsubscribeQueryCache","subscribe","event","type","unusbscribeMutationCache","persistQueryClient","persistQueryClientUnsubscribe","hasUnsubscribed","then","children","persistOptions","onSuccess","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","QueryClientProvider","_extends","createElement","IsRestoringProvider","value","sortedQueries","sort","a","b","length","oldestData","shift","filter","q"],"mappings":"wnBAsBA,SAASA,EAA+BC,GACtC,OAAOA,EAASC,MAAMC,SAExB,SAASC,EAA4BC,GACnC,MAA8B,YAAvBA,EAAMH,MAAMI,OAErB,SAASC,EAAUC,EAAQC,EAAU,IACnC,MAAMC,EAAY,GACZC,EAAU,GAChB,IAAmC,IAA/BF,EAAQG,mBAA8B,CACxC,MAAMC,EAA0BJ,EAAQI,yBAA2Bb,EACnEQ,EAAOM,mBAAmBC,SAASC,SAAQf,IACrCY,EAAwBZ,IAC1BS,EAAUO,KA/BlB,SAA2BhB,GACzB,MAAO,CACLiB,YAAajB,EAASQ,QAAQS,YAC9BhB,MAAOD,EAASC,OA4BGiB,CAAkBlB,OAIvC,IAAiC,IAA7BQ,EAAQW,iBAA4B,CACtC,MAAMC,EAAuBZ,EAAQY,sBAAwBjB,EAC7DI,EAAOc,gBAAgBP,SAASC,SAAQX,IAClCgB,EAAqBhB,IACvBM,EAAQM,KA5BhB,SAAwBZ,GACtB,MAAO,CACLH,MAAOG,EAAMH,MACbqB,SAAUlB,EAAMkB,SAChBC,UAAWnB,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AGC,IAAMD,EAAE7F,MAAMqD,cAAgByC,EAAE9F,MAAMqD,gBAGlF,GAAIsC,EAAcI,OAAS,EAAG,CAC5B,MAAMC,EAAaL,EAAcM,QAEjC,OADA3F,EAAOkD,YAAY/C,QAAUA,EAAQyF,QAAOC,GAAKA,IAAMH,IAChD1F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query-persist-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha.1",
|
|
4
4
|
"description": "React bindings to work with persisters in TanStack/react-query",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,16 +31,14 @@
|
|
|
31
31
|
"@types/react": "^18.0.14",
|
|
32
32
|
"@types/react-dom": "^18.0.5",
|
|
33
33
|
"react": "^18.2.0",
|
|
34
|
-
"react-17": "npm:react@^17.0.2",
|
|
35
34
|
"react-dom": "^18.2.0",
|
|
36
|
-
"react-
|
|
37
|
-
"@tanstack/react-query": "4.24.10"
|
|
35
|
+
"@tanstack/react-query": "5.0.0-alpha.1"
|
|
38
36
|
},
|
|
39
37
|
"dependencies": {
|
|
40
|
-
"@tanstack/query-persist-client-core": "
|
|
38
|
+
"@tanstack/query-persist-client-core": "5.0.0-alpha.1"
|
|
41
39
|
},
|
|
42
40
|
"peerDependencies": {
|
|
43
|
-
"@tanstack/react-query": "
|
|
41
|
+
"@tanstack/react-query": "5.0.0-alpha.1"
|
|
44
42
|
},
|
|
45
43
|
"scripts": {
|
|
46
44
|
"clean": "rimraf ./build",
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
} from '@tanstack/query-persist-client-core'
|
|
13
13
|
import { persistQueryClientSave } from '@tanstack/query-persist-client-core'
|
|
14
14
|
|
|
15
|
-
import { createQueryClient,
|
|
15
|
+
import { createQueryClient, queryKey, sleep } from './utils'
|
|
16
16
|
import { PersistQueryClientProvider } from '../PersistQueryClientProvider'
|
|
17
17
|
|
|
18
18
|
const createMockPersister = (): Persister => {
|
|
@@ -57,7 +57,10 @@ describe('PersistQueryClientProvider', () => {
|
|
|
57
57
|
const states: UseQueryResult<string>[] = []
|
|
58
58
|
|
|
59
59
|
const queryClient = createQueryClient()
|
|
60
|
-
await queryClient.prefetchQuery(
|
|
60
|
+
await queryClient.prefetchQuery({
|
|
61
|
+
queryKey: key,
|
|
62
|
+
queryFn: () => Promise.resolve('hydrated'),
|
|
63
|
+
})
|
|
61
64
|
|
|
62
65
|
const persister = createMockPersister()
|
|
63
66
|
|
|
@@ -66,9 +69,12 @@ describe('PersistQueryClientProvider', () => {
|
|
|
66
69
|
queryClient.clear()
|
|
67
70
|
|
|
68
71
|
function Page() {
|
|
69
|
-
const state = useQuery(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
const state = useQuery({
|
|
73
|
+
queryKey: key,
|
|
74
|
+
queryFn: async () => {
|
|
75
|
+
await sleep(10)
|
|
76
|
+
return 'fetched'
|
|
77
|
+
},
|
|
72
78
|
})
|
|
73
79
|
|
|
74
80
|
states.push(state)
|
|
@@ -97,7 +103,7 @@ describe('PersistQueryClientProvider', () => {
|
|
|
97
103
|
expect(states).toHaveLength(4)
|
|
98
104
|
|
|
99
105
|
expect(states[0]).toMatchObject({
|
|
100
|
-
status: '
|
|
106
|
+
status: 'pending',
|
|
101
107
|
fetchStatus: 'idle',
|
|
102
108
|
data: undefined,
|
|
103
109
|
})
|
|
@@ -126,7 +132,10 @@ describe('PersistQueryClientProvider', () => {
|
|
|
126
132
|
const states: UseQueryResult[] = []
|
|
127
133
|
|
|
128
134
|
const queryClient = createQueryClient()
|
|
129
|
-
await queryClient.prefetchQuery(
|
|
135
|
+
await queryClient.prefetchQuery({
|
|
136
|
+
queryKey: key,
|
|
137
|
+
queryFn: () => Promise.resolve('hydrated'),
|
|
138
|
+
})
|
|
130
139
|
|
|
131
140
|
const persister = createMockPersister()
|
|
132
141
|
|
|
@@ -173,7 +182,7 @@ describe('PersistQueryClientProvider', () => {
|
|
|
173
182
|
expect(states).toHaveLength(4)
|
|
174
183
|
|
|
175
184
|
expect(states[0]).toMatchObject({
|
|
176
|
-
status: '
|
|
185
|
+
status: 'pending',
|
|
177
186
|
fetchStatus: 'idle',
|
|
178
187
|
data: undefined,
|
|
179
188
|
})
|
|
@@ -202,7 +211,10 @@ describe('PersistQueryClientProvider', () => {
|
|
|
202
211
|
const states: DefinedUseQueryResult<string>[] = []
|
|
203
212
|
|
|
204
213
|
const queryClient = createQueryClient()
|
|
205
|
-
await queryClient.prefetchQuery(
|
|
214
|
+
await queryClient.prefetchQuery({
|
|
215
|
+
queryKey: key,
|
|
216
|
+
queryFn: () => Promise.resolve('hydrated'),
|
|
217
|
+
})
|
|
206
218
|
|
|
207
219
|
const persister = createMockPersister()
|
|
208
220
|
|
|
@@ -211,19 +223,18 @@ describe('PersistQueryClientProvider', () => {
|
|
|
211
223
|
queryClient.clear()
|
|
212
224
|
|
|
213
225
|
function Page() {
|
|
214
|
-
const state = useQuery(
|
|
215
|
-
key,
|
|
216
|
-
async () => {
|
|
226
|
+
const state = useQuery({
|
|
227
|
+
queryKey: key,
|
|
228
|
+
queryFn: async () => {
|
|
217
229
|
await sleep(10)
|
|
218
230
|
return 'fetched'
|
|
219
231
|
},
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
)
|
|
232
|
+
|
|
233
|
+
initialData: 'initial',
|
|
234
|
+
// make sure that initial data is older than the hydration data
|
|
235
|
+
// otherwise initialData would be newer and takes precedence
|
|
236
|
+
initialDataUpdatedAt: 1,
|
|
237
|
+
})
|
|
227
238
|
|
|
228
239
|
states.push(state)
|
|
229
240
|
|
|
@@ -280,7 +291,10 @@ describe('PersistQueryClientProvider', () => {
|
|
|
280
291
|
const states: UseQueryResult<string>[] = []
|
|
281
292
|
|
|
282
293
|
const queryClient = createQueryClient()
|
|
283
|
-
await queryClient.prefetchQuery(
|
|
294
|
+
await queryClient.prefetchQuery({
|
|
295
|
+
queryKey: key,
|
|
296
|
+
queryFn: () => Promise.resolve('hydrated'),
|
|
297
|
+
})
|
|
284
298
|
|
|
285
299
|
const persister = createMockPersister()
|
|
286
300
|
|
|
@@ -289,16 +303,15 @@ describe('PersistQueryClientProvider', () => {
|
|
|
289
303
|
queryClient.clear()
|
|
290
304
|
|
|
291
305
|
function Page() {
|
|
292
|
-
const state = useQuery(
|
|
293
|
-
key,
|
|
294
|
-
async () => {
|
|
306
|
+
const state = useQuery({
|
|
307
|
+
queryKey: key,
|
|
308
|
+
queryFn: async () => {
|
|
295
309
|
await sleep(10)
|
|
296
310
|
return 'fetched'
|
|
297
311
|
},
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
)
|
|
312
|
+
|
|
313
|
+
staleTime: Infinity,
|
|
314
|
+
})
|
|
302
315
|
|
|
303
316
|
states.push(state)
|
|
304
317
|
|
|
@@ -325,7 +338,7 @@ describe('PersistQueryClientProvider', () => {
|
|
|
325
338
|
expect(states).toHaveLength(2)
|
|
326
339
|
|
|
327
340
|
expect(states[0]).toMatchObject({
|
|
328
|
-
status: '
|
|
341
|
+
status: 'pending',
|
|
329
342
|
fetchStatus: 'idle',
|
|
330
343
|
data: undefined,
|
|
331
344
|
})
|
|
@@ -341,7 +354,10 @@ describe('PersistQueryClientProvider', () => {
|
|
|
341
354
|
const key = queryKey()
|
|
342
355
|
|
|
343
356
|
const queryClient = createQueryClient()
|
|
344
|
-
await queryClient.prefetchQuery(
|
|
357
|
+
await queryClient.prefetchQuery({
|
|
358
|
+
queryKey: key,
|
|
359
|
+
queryFn: () => Promise.resolve('hydrated'),
|
|
360
|
+
})
|
|
345
361
|
|
|
346
362
|
const persister = createMockPersister()
|
|
347
363
|
|
|
@@ -350,9 +366,12 @@ describe('PersistQueryClientProvider', () => {
|
|
|
350
366
|
queryClient.clear()
|
|
351
367
|
|
|
352
368
|
function Page() {
|
|
353
|
-
const state = useQuery(
|
|
354
|
-
|
|
355
|
-
|
|
369
|
+
const state = useQuery({
|
|
370
|
+
queryKey: key,
|
|
371
|
+
queryFn: async () => {
|
|
372
|
+
await sleep(10)
|
|
373
|
+
return 'fetched'
|
|
374
|
+
},
|
|
356
375
|
})
|
|
357
376
|
|
|
358
377
|
return (
|
|
@@ -383,8 +402,11 @@ describe('PersistQueryClientProvider', () => {
|
|
|
383
402
|
|
|
384
403
|
test('should remove cache after non-successful restoring', async () => {
|
|
385
404
|
const key = queryKey()
|
|
386
|
-
jest.spyOn(console, '
|
|
387
|
-
|
|
405
|
+
const consoleMock = jest.spyOn(console, 'error')
|
|
406
|
+
const consoleWarn = jest
|
|
407
|
+
.spyOn(console, 'warn')
|
|
408
|
+
.mockImplementation(() => undefined)
|
|
409
|
+
consoleMock.mockImplementation(() => undefined)
|
|
388
410
|
|
|
389
411
|
const queryClient = createQueryClient()
|
|
390
412
|
const removeClient = jest.fn()
|
|
@@ -392,9 +414,12 @@ describe('PersistQueryClientProvider', () => {
|
|
|
392
414
|
const [error, persister] = createMockErrorPersister(removeClient)
|
|
393
415
|
|
|
394
416
|
function Page() {
|
|
395
|
-
const state = useQuery(
|
|
396
|
-
|
|
397
|
-
|
|
417
|
+
const state = useQuery({
|
|
418
|
+
queryKey: key,
|
|
419
|
+
queryFn: async () => {
|
|
420
|
+
await sleep(10)
|
|
421
|
+
return 'fetched'
|
|
422
|
+
},
|
|
398
423
|
})
|
|
399
424
|
|
|
400
425
|
return (
|
|
@@ -416,8 +441,10 @@ describe('PersistQueryClientProvider', () => {
|
|
|
416
441
|
|
|
417
442
|
await waitFor(() => rendered.getByText('fetched'))
|
|
418
443
|
expect(removeClient).toHaveBeenCalledTimes(1)
|
|
419
|
-
expect(
|
|
420
|
-
expect(
|
|
444
|
+
expect(consoleMock).toHaveBeenCalledTimes(1)
|
|
445
|
+
expect(consoleMock).toHaveBeenNthCalledWith(1, error)
|
|
446
|
+
consoleMock.mockRestore()
|
|
447
|
+
consoleWarn.mockRestore()
|
|
421
448
|
})
|
|
422
449
|
|
|
423
450
|
test('should be able to persist into multiple clients', async () => {
|
|
@@ -425,7 +452,10 @@ describe('PersistQueryClientProvider', () => {
|
|
|
425
452
|
const states: UseQueryResult[] = []
|
|
426
453
|
|
|
427
454
|
const queryClient = createQueryClient()
|
|
428
|
-
await queryClient.prefetchQuery(
|
|
455
|
+
await queryClient.prefetchQuery({
|
|
456
|
+
queryKey: key,
|
|
457
|
+
queryFn: () => Promise.resolve('hydrated'),
|
|
458
|
+
})
|
|
429
459
|
|
|
430
460
|
const persister = createMockPersister()
|
|
431
461
|
|
|
@@ -480,7 +510,7 @@ describe('PersistQueryClientProvider', () => {
|
|
|
480
510
|
}
|
|
481
511
|
|
|
482
512
|
function Page() {
|
|
483
|
-
const state = useQuery(key)
|
|
513
|
+
const state = useQuery({ queryKey: key })
|
|
484
514
|
|
|
485
515
|
states.push(state)
|
|
486
516
|
|
|
@@ -504,13 +534,13 @@ describe('PersistQueryClientProvider', () => {
|
|
|
504
534
|
expect(states).toHaveLength(5)
|
|
505
535
|
|
|
506
536
|
expect(states[0]).toMatchObject({
|
|
507
|
-
status: '
|
|
537
|
+
status: 'pending',
|
|
508
538
|
fetchStatus: 'idle',
|
|
509
539
|
data: undefined,
|
|
510
540
|
})
|
|
511
541
|
|
|
512
542
|
expect(states[1]).toMatchObject({
|
|
513
|
-
status: '
|
|
543
|
+
status: 'pending',
|
|
514
544
|
fetchStatus: 'idle',
|
|
515
545
|
data: undefined,
|
|
516
546
|
})
|
package/src/__tests__/utils.ts
CHANGED
|
@@ -4,14 +4,7 @@ import type { QueryClientConfig } from '@tanstack/query-core'
|
|
|
4
4
|
import { QueryClient } from '@tanstack/query-core'
|
|
5
5
|
|
|
6
6
|
export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
7
|
-
|
|
8
|
-
return new QueryClient({ logger: mockLogger, ...config })
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const mockLogger = {
|
|
12
|
-
log: jest.fn(),
|
|
13
|
-
warn: jest.fn(),
|
|
14
|
-
error: jest.fn(),
|
|
7
|
+
return new QueryClient(config)
|
|
15
8
|
}
|
|
16
9
|
|
|
17
10
|
let queryKeyCount = 0
|