@tanstack/react-query-persist-client 4.35.3 → 4.35.5
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.esm.js +18 -15
- package/build/lib/PersistQueryClientProvider.esm.js.map +1 -1
- package/build/lib/PersistQueryClientProvider.js +17 -14
- package/build/lib/PersistQueryClientProvider.js.map +1 -1
- package/build/lib/PersistQueryClientProvider.mjs +18 -15
- package/build/lib/PersistQueryClientProvider.mjs.map +1 -1
- package/build/umd/index.development.js +17 -14
- 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 +1 -1
- package/src/PersistQueryClientProvider.tsx +19 -17
- package/src/__tests__/PersistQueryClientProvider.test.tsx +135 -1
- package/build/lib/PersistQueryClientProvider.d.ts.map +0 -1
- package/build/lib/__tests__/PersistQueryClientProvider.test.d.ts.map +0 -1
- package/build/lib/__tests__/utils.d.ts.map +0 -1
- package/build/lib/index.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { extends as _extends } from './_virtual/_rollupPluginBabelHelpers.esm.js';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { persistQueryClientRestore, persistQueryClientSubscribe } from '@tanstack/query-persist-client-core';
|
|
5
5
|
import { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query';
|
|
6
6
|
|
|
7
7
|
const PersistQueryClientProvider = ({
|
|
@@ -16,6 +16,7 @@ const PersistQueryClientProvider = ({
|
|
|
16
16
|
persistOptions,
|
|
17
17
|
onSuccess
|
|
18
18
|
});
|
|
19
|
+
const didRestore = React.useRef(false);
|
|
19
20
|
React.useEffect(() => {
|
|
20
21
|
refs.current = {
|
|
21
22
|
persistOptions,
|
|
@@ -23,22 +24,24 @@ const PersistQueryClientProvider = ({
|
|
|
23
24
|
};
|
|
24
25
|
});
|
|
25
26
|
React.useEffect(() => {
|
|
26
|
-
|
|
27
|
-
setIsRestoring(true);
|
|
28
|
-
const [unsubscribe, promise] = persistQueryClient({ ...refs.current.persistOptions,
|
|
27
|
+
const options = { ...refs.current.persistOptions,
|
|
29
28
|
queryClient: client
|
|
30
|
-
});
|
|
31
|
-
promise.then(() => {
|
|
32
|
-
if (!isStale) {
|
|
33
|
-
refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
|
|
34
|
-
setIsRestoring(false);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return () => {
|
|
38
|
-
isStale = true;
|
|
39
|
-
unsubscribe();
|
|
40
29
|
};
|
|
41
|
-
|
|
30
|
+
|
|
31
|
+
if (!didRestore.current) {
|
|
32
|
+
didRestore.current = true;
|
|
33
|
+
setIsRestoring(true);
|
|
34
|
+
persistQueryClientRestore(options).then(async () => {
|
|
35
|
+
try {
|
|
36
|
+
await (refs.current.onSuccess == null ? void 0 : refs.current.onSuccess());
|
|
37
|
+
} finally {
|
|
38
|
+
setIsRestoring(false);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return isRestoring ? undefined : persistQueryClientSubscribe(options);
|
|
44
|
+
}, [client, isRestoring]);
|
|
42
45
|
return /*#__PURE__*/React.createElement(QueryClientProvider, _extends({
|
|
43
46
|
client: client
|
|
44
47
|
}, props), /*#__PURE__*/React.createElement(IsRestoringProvider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.esm.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.esm.js","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 { QueryClientProviderProps } 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n persistQueryClientRestore(options).then(async () => {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [client, isRestoring])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["onSuccess","queryClient","persistQueryClientRestore"],"mappings":";;;;;;AAgBO;;;;;;AAAoC;;AAQzC;;AAA4CA;AAAlB;AAC1B;;;;AAGmCA;;;;;AAM/BC;;;AAEF;;;AAGEC;;;AAGG;;AAEA;;AAEJ;;AACD;AACD;AAED;AACuB;;AACE;;AAG1B;;"}
|
|
@@ -40,6 +40,7 @@ const PersistQueryClientProvider = ({
|
|
|
40
40
|
persistOptions,
|
|
41
41
|
onSuccess
|
|
42
42
|
});
|
|
43
|
+
const didRestore = React__namespace.useRef(false);
|
|
43
44
|
React__namespace.useEffect(() => {
|
|
44
45
|
refs.current = {
|
|
45
46
|
persistOptions,
|
|
@@ -47,22 +48,24 @@ const PersistQueryClientProvider = ({
|
|
|
47
48
|
};
|
|
48
49
|
});
|
|
49
50
|
React__namespace.useEffect(() => {
|
|
50
|
-
|
|
51
|
-
setIsRestoring(true);
|
|
52
|
-
const [unsubscribe, promise] = queryPersistClientCore.persistQueryClient({ ...refs.current.persistOptions,
|
|
51
|
+
const options = { ...refs.current.persistOptions,
|
|
53
52
|
queryClient: client
|
|
54
|
-
});
|
|
55
|
-
promise.then(() => {
|
|
56
|
-
if (!isStale) {
|
|
57
|
-
refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
|
|
58
|
-
setIsRestoring(false);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return () => {
|
|
62
|
-
isStale = true;
|
|
63
|
-
unsubscribe();
|
|
64
53
|
};
|
|
65
|
-
|
|
54
|
+
|
|
55
|
+
if (!didRestore.current) {
|
|
56
|
+
didRestore.current = true;
|
|
57
|
+
setIsRestoring(true);
|
|
58
|
+
queryPersistClientCore.persistQueryClientRestore(options).then(async () => {
|
|
59
|
+
try {
|
|
60
|
+
await (refs.current.onSuccess == null ? void 0 : refs.current.onSuccess());
|
|
61
|
+
} finally {
|
|
62
|
+
setIsRestoring(false);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return isRestoring ? undefined : queryPersistClientCore.persistQueryClientSubscribe(options);
|
|
68
|
+
}, [client, isRestoring]);
|
|
66
69
|
return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _rollupPluginBabelHelpers["extends"]({
|
|
67
70
|
client: client
|
|
68
71
|
}, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.js","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 { QueryClientProviderProps } 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n persistQueryClientRestore(options).then(async () => {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [client, isRestoring])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["onSuccess","queryClient","persistQueryClientRestore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBO;;;;;;AAAoC;;AAQzC;;AAA4CA;AAAlB;AAC1B;;;;AAGmCA;;;;;AAM/BC;;;AAEF;;;AAGEC;;;AAGG;;AAEA;;AAEJ;;AACD;AACD;AAED;AACuB;;AACE;;AAG1B;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { extends as _extends } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { persistQueryClientRestore, persistQueryClientSubscribe } from '@tanstack/query-persist-client-core';
|
|
5
5
|
import { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query';
|
|
6
6
|
|
|
7
7
|
const PersistQueryClientProvider = ({
|
|
@@ -16,6 +16,7 @@ const PersistQueryClientProvider = ({
|
|
|
16
16
|
persistOptions,
|
|
17
17
|
onSuccess
|
|
18
18
|
});
|
|
19
|
+
const didRestore = React.useRef(false);
|
|
19
20
|
React.useEffect(() => {
|
|
20
21
|
refs.current = {
|
|
21
22
|
persistOptions,
|
|
@@ -23,22 +24,24 @@ const PersistQueryClientProvider = ({
|
|
|
23
24
|
};
|
|
24
25
|
});
|
|
25
26
|
React.useEffect(() => {
|
|
26
|
-
|
|
27
|
-
setIsRestoring(true);
|
|
28
|
-
const [unsubscribe, promise] = persistQueryClient({ ...refs.current.persistOptions,
|
|
27
|
+
const options = { ...refs.current.persistOptions,
|
|
29
28
|
queryClient: client
|
|
30
|
-
});
|
|
31
|
-
promise.then(() => {
|
|
32
|
-
if (!isStale) {
|
|
33
|
-
refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
|
|
34
|
-
setIsRestoring(false);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return () => {
|
|
38
|
-
isStale = true;
|
|
39
|
-
unsubscribe();
|
|
40
29
|
};
|
|
41
|
-
|
|
30
|
+
|
|
31
|
+
if (!didRestore.current) {
|
|
32
|
+
didRestore.current = true;
|
|
33
|
+
setIsRestoring(true);
|
|
34
|
+
persistQueryClientRestore(options).then(async () => {
|
|
35
|
+
try {
|
|
36
|
+
await (refs.current.onSuccess == null ? void 0 : refs.current.onSuccess());
|
|
37
|
+
} finally {
|
|
38
|
+
setIsRestoring(false);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return isRestoring ? undefined : persistQueryClientSubscribe(options);
|
|
44
|
+
}, [client, isRestoring]);
|
|
42
45
|
return /*#__PURE__*/React.createElement(QueryClientProvider, _extends({
|
|
43
46
|
client: client
|
|
44
47
|
}, props), /*#__PURE__*/React.createElement(IsRestoringProvider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.mjs","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport {
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.mjs","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 { QueryClientProviderProps } 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n persistQueryClientRestore(options).then(async () => {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [client, isRestoring])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["onSuccess","queryClient","persistQueryClientRestore"],"mappings":";;;;;;AAgBO;;;;;;AAAoC;;AAQzC;;AAA4CA;AAAlB;AAC1B;;;;AAGmCA;;;;;AAM/BC;;;AAEF;;;AAGEC;;;AAGG;;AAEA;;AAEJ;;AACD;AACD;AAED;AACuB;;AACE;;AAG1B;;"}
|
|
@@ -287,6 +287,7 @@
|
|
|
287
287
|
persistOptions,
|
|
288
288
|
onSuccess
|
|
289
289
|
});
|
|
290
|
+
const didRestore = React__namespace.useRef(false);
|
|
290
291
|
React__namespace.useEffect(() => {
|
|
291
292
|
refs.current = {
|
|
292
293
|
persistOptions,
|
|
@@ -294,22 +295,24 @@
|
|
|
294
295
|
};
|
|
295
296
|
});
|
|
296
297
|
React__namespace.useEffect(() => {
|
|
297
|
-
|
|
298
|
-
setIsRestoring(true);
|
|
299
|
-
const [unsubscribe, promise] = persistQueryClient({ ...refs.current.persistOptions,
|
|
298
|
+
const options = { ...refs.current.persistOptions,
|
|
300
299
|
queryClient: client
|
|
301
|
-
});
|
|
302
|
-
promise.then(() => {
|
|
303
|
-
if (!isStale) {
|
|
304
|
-
refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
|
|
305
|
-
setIsRestoring(false);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
return () => {
|
|
309
|
-
isStale = true;
|
|
310
|
-
unsubscribe();
|
|
311
300
|
};
|
|
312
|
-
|
|
301
|
+
|
|
302
|
+
if (!didRestore.current) {
|
|
303
|
+
didRestore.current = true;
|
|
304
|
+
setIsRestoring(true);
|
|
305
|
+
persistQueryClientRestore(options).then(async () => {
|
|
306
|
+
try {
|
|
307
|
+
await (refs.current.onSuccess == null ? void 0 : refs.current.onSuccess());
|
|
308
|
+
} finally {
|
|
309
|
+
setIsRestoring(false);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return isRestoring ? undefined : persistQueryClientSubscribe(options);
|
|
315
|
+
}, [client, isRestoring]);
|
|
313
316
|
return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _extends({
|
|
314
317
|
client: client
|
|
315
318
|
}, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
|
|
@@ -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 { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } 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,CAAC,EAAE;EAC7C,QAAQ,SAAS,CAAC,IAAI,CAAC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M,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// 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 {\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 { QueryClientProviderProps } 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n persistQueryClientRestore(options).then(async () => {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [client, isRestoring])\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","didRestore","useEffect","current","options","queryClient","persistQueryClientRestore","then","undefined","persistQueryClientSubscribe","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,CA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AAAA,GAAAA,IAAI,CAACI,OAAL,CAAaV,SAAb,EAAN,CAAA,CAAA;EACD,SAFD,SAEU;YACRG,cAAc,CAAC,KAAD,CAAd,CAAA;EACD,SAAA;SALH,CAAA,CAAA;EAOD,KAAA;;EACD,IAAA,OAAOD,WAAW,GAAGa,SAAH,GAAeC,2BAA2B,CAACL,OAAD,CAA5D,CAAA;EACD,GAjBD,EAiBG,CAACd,MAAD,EAASK,WAAT,CAjBH,CAAA,CAAA;EAmBA,EAAA,oBACEE,+BAACa,8BAAD,EAAA,QAAA,CAAA;EAAqB,IAAA,MAAM,EAAEpB,MAAAA;KAAYI,EAAAA,KAAzC,CACE,eAAAG,gBAAA,CAAA,aAAA,CAACc,8BAAD,EAAA;EAAqB,IAAA,KAAK,EAAEhB,WAAAA;KAAcJ,EAAAA,QAA1C,CADF,CADF,CAAA;EAKD;;;;;;;;;;;;;;;"}
|
|
@@ -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){if(e&&e.__esModule)return 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 u(e){return e.state.isPaused}function i(e){return"success"===e.state.status}function a(e,t={}){const r=[],n=[];if(!1!==t.dehydrateMutations){const n=t.shouldDehydrateMutation||u;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||i;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 u=await t.restoreClient();if(u)if(u.timestamp){const i=Date.now()-u.timestamp>r,a=u.buster!==n;i||a?t.removeClient():function(e,t,r){if("object"!=typeof t||null===t)return;const n=e.getMutationCache(),s=e.getQueryCache(),u=t.mutations||[],i=t.queries||[];u.forEach((t=>{var s;n.build(e,{...null==r||null==(s=r.defaultOptions)?void 0:s.mutations,mutationKey:t.mutationKey},t.state)})),i.forEach((t=>{var n;const u=s.get(t.queryHash),i={...t.state,fetchStatus:"idle"};u?u.state.dataUpdatedAt<i.dataUpdatedAt&&u.setState(i):s.build(e,{...null==r||null==(n=r.defaultOptions)?void 0:n.queries,queryKey:t.queryKey,queryHash:t.queryHash},i)}))}(e,u.clientState,s)}else t.removeClient()}catch(e){t.removeClient()}}async function
|
|
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){if(e&&e.__esModule)return 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 u(e){return e.state.isPaused}function i(e){return"success"===e.state.status}function a(e,t={}){const r=[],n=[];if(!1!==t.dehydrateMutations){const n=t.shouldDehydrateMutation||u;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||i;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 u=await t.restoreClient();if(u)if(u.timestamp){const i=Date.now()-u.timestamp>r,a=u.buster!==n;i||a?t.removeClient():function(e,t,r){if("object"!=typeof t||null===t)return;const n=e.getMutationCache(),s=e.getQueryCache(),u=t.mutations||[],i=t.queries||[];u.forEach((t=>{var s;n.build(e,{...null==r||null==(s=r.defaultOptions)?void 0:s.mutations,mutationKey:t.mutationKey},t.state)})),i.forEach((t=>{var n;const u=s.get(t.queryHash),i={...t.state,fetchStatus:"idle"};u?u.state.dataUpdatedAt<i.dataUpdatedAt&&u.setState(i):s.build(e,{...null==r||null==(n=r.defaultOptions)?void 0:n.queries,queryKey:t.queryKey,queryHash:t.queryHash},i)}))}(e,u.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 d(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 f(){return f=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},f.apply(this,arguments)}e.PersistQueryClientProvider=({client:e,children:t,persistOptions:n,onSuccess:u,...i})=>{const[a,o]=s.useState(!0),c=s.useRef({persistOptions:n,onSuccess:u}),y=s.useRef(!1);return s.useEffect((()=>{c.current={persistOptions:n,onSuccess:u}})),s.useEffect((()=>{const t={...c.current.persistOptions,queryClient:e};return y.current||(y.current=!0,o(!0),l(t).then((async()=>{try{await(null==c.current.onSuccess?void 0:c.current.onSuccess())}finally{o(!1)}}))),a?void 0:d(t)}),[e,a]),s.createElement(r.QueryClientProvider,f({client:e},i),s.createElement(r.IsRestoringProvider,{value:a},t))},e.persistQueryClient=function(e){let t,r=!1;return[()=>{r=!0,null==t||t()},l(e).then((()=>{r||(t=d(e))}))]},e.persistQueryClientRestore=l,e.persistQueryClientSave=y,e.persistQueryClientSubscribe=d,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}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
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 { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } 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,MA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ACGZ,MAEH,MAAOa,EAAaC,GAAkBC,EAAMC,UAAS,GAC/CC,EAAOF,EAAMG,OAAO,CAAEP,iBAAgBC,cA2B5C,OAzBAG,EAAMI,WAAU,KACdF,EAAKG,QAAU,CAAET,iBAAgBC,gBAGnCG,EAAMI,WAAU,KACd,IAAIE,GAAU,EACdP,GAAe,GACf,MAAOQ,EAAaC,GAAWjB,EAAmB,IAC7CW,EAAKG,QAAQT,eAChB7C,YAAaxB,IAUf,OAPAiF,EAAQd,MAAK,KACNY,UACHJ,EAAKG,QAAQR,WAAbK,EAAKG,QAAQR,YACbE,GAAe,OAIZ,KACLO,GAAU,EACVC,OAED,CAAChF,IAGFyE,gBAACS,EAADA,oBAAAC,EAAA,CAAqBnF,OAAQA,GAAY0D,GACvCe,EAAAW,cAACC,EAAAA,oBAAD,CAAqBC,MAAOf,GAAcH,yIClDtB,EACxBvC,sBAEA,MAAM3B,EAAY,IAAI2B,EAAgBuB,YAAYlD,WAC5CC,EAAU,IAAI0B,EAAgBuB,YAAYjD,SAC1CH,EAAS,IAAK6B,EAClBuB,YAAa,CACXlD,YACAC,YAIEoF,EAAgB,IAAIpF,GAASqF,MAAK,CAACC,EAAGC,IAAMD,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// 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 {\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 { QueryClientProviderProps } 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n persistQueryClientRestore(options).then(async () => {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [client, isRestoring])\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","children","persistOptions","onSuccess","isRestoring","setIsRestoring","React","useState","refs","useRef","didRestore","useEffect","current","then","undefined","QueryClientProvider","_extends","createElement","IsRestoringProvider","value","persistQueryClientUnsubscribe","hasUnsubscribed","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,EAASC,OACTA,EAAS,MAAmBC,OAC5B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AAgB,IAAIlF,GAASmF,MAAK,CAACC,EAAGC,IAAMD,EAAE7F,MAAMuD,cAAgBuC,EAAE9F,MAAMuD,gBAElF,GAAIoC,EAAcI,OAAS,EAAG,CAC5B,MAAMC,EAAaL,EAAcM,QAEjC,OADA3F,EAAOoD,YAAYjD,QAAUA,EAAQyF,QAAOC,GAAKA,IAAMH,IAChD1F"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
persistQueryClientRestore,
|
|
6
|
+
persistQueryClientSubscribe,
|
|
7
|
+
} from '@tanstack/query-persist-client-core'
|
|
5
8
|
import { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'
|
|
6
9
|
import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
|
|
7
10
|
import type { QueryClientProviderProps } from '@tanstack/react-query'
|
|
@@ -20,31 +23,30 @@ export const PersistQueryClientProvider = ({
|
|
|
20
23
|
}: PersistQueryClientProviderProps): JSX.Element => {
|
|
21
24
|
const [isRestoring, setIsRestoring] = React.useState(true)
|
|
22
25
|
const refs = React.useRef({ persistOptions, onSuccess })
|
|
26
|
+
const didRestore = React.useRef(false)
|
|
23
27
|
|
|
24
28
|
React.useEffect(() => {
|
|
25
29
|
refs.current = { persistOptions, onSuccess }
|
|
26
30
|
})
|
|
27
31
|
|
|
28
32
|
React.useEffect(() => {
|
|
29
|
-
|
|
30
|
-
setIsRestoring(true)
|
|
31
|
-
const [unsubscribe, promise] = persistQueryClient({
|
|
33
|
+
const options = {
|
|
32
34
|
...refs.current.persistOptions,
|
|
33
35
|
queryClient: client,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
promise.then(() => {
|
|
37
|
-
if (!isStale) {
|
|
38
|
-
refs.current.onSuccess?.()
|
|
39
|
-
setIsRestoring(false)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
return () => {
|
|
44
|
-
isStale = true
|
|
45
|
-
unsubscribe()
|
|
46
36
|
}
|
|
47
|
-
|
|
37
|
+
if (!didRestore.current) {
|
|
38
|
+
didRestore.current = true
|
|
39
|
+
setIsRestoring(true)
|
|
40
|
+
persistQueryClientRestore(options).then(async () => {
|
|
41
|
+
try {
|
|
42
|
+
await refs.current.onSuccess?.()
|
|
43
|
+
} finally {
|
|
44
|
+
setIsRestoring(false)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
return isRestoring ? undefined : persistQueryClientSubscribe(options)
|
|
49
|
+
}, [client, isRestoring])
|
|
48
50
|
|
|
49
51
|
return (
|
|
50
52
|
<QueryClientProvider client={client} {...props}>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
-
import { render, waitFor } from '@testing-library/react'
|
|
2
|
+
import { fireEvent, render, waitFor } from '@testing-library/react'
|
|
3
3
|
|
|
4
4
|
import { QueryClient, useQueries, useQuery } from '@tanstack/react-query'
|
|
5
5
|
import { persistQueryClientSave } from '@tanstack/query-persist-client-core'
|
|
@@ -121,6 +121,70 @@ describe('PersistQueryClientProvider', () => {
|
|
|
121
121
|
})
|
|
122
122
|
})
|
|
123
123
|
|
|
124
|
+
test('should subscribe correctly in StrictMode', async () => {
|
|
125
|
+
const key = queryKey()
|
|
126
|
+
|
|
127
|
+
const queryClient = createQueryClient()
|
|
128
|
+
await queryClient.prefetchQuery({
|
|
129
|
+
queryKey: key,
|
|
130
|
+
queryFn: () => Promise.resolve('hydrated'),
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const persister = createMockPersister()
|
|
134
|
+
|
|
135
|
+
await persistQueryClientSave({ queryClient, persister })
|
|
136
|
+
|
|
137
|
+
queryClient.clear()
|
|
138
|
+
|
|
139
|
+
function Page() {
|
|
140
|
+
const state = useQuery({
|
|
141
|
+
queryKey: key,
|
|
142
|
+
queryFn: async () => {
|
|
143
|
+
await sleep(10)
|
|
144
|
+
return 'fetched'
|
|
145
|
+
},
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<div>
|
|
150
|
+
<h1>{state.data}</h1>
|
|
151
|
+
<h2>fetchStatus: {state.fetchStatus}</h2>
|
|
152
|
+
<button
|
|
153
|
+
onClick={() => {
|
|
154
|
+
queryClient.setQueryData(key, 'updated')
|
|
155
|
+
}}
|
|
156
|
+
>
|
|
157
|
+
update
|
|
158
|
+
</button>
|
|
159
|
+
</div>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const rendered = render(
|
|
164
|
+
<React.StrictMode>
|
|
165
|
+
<PersistQueryClientProvider
|
|
166
|
+
client={queryClient}
|
|
167
|
+
persistOptions={{ persister }}
|
|
168
|
+
>
|
|
169
|
+
<Page />
|
|
170
|
+
</PersistQueryClientProvider>
|
|
171
|
+
,
|
|
172
|
+
</React.StrictMode>,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
await waitFor(() => rendered.getByText('fetchStatus: idle'))
|
|
176
|
+
await waitFor(() => rendered.getByText('hydrated'))
|
|
177
|
+
await waitFor(() => rendered.getByText('fetched'))
|
|
178
|
+
|
|
179
|
+
fireEvent.click(rendered.getByRole('button', { name: /update/i }))
|
|
180
|
+
|
|
181
|
+
await waitFor(() => rendered.getByText('updated'))
|
|
182
|
+
|
|
183
|
+
const state = await persister.restoreClient()
|
|
184
|
+
|
|
185
|
+
expect(state?.clientState.queries[0]?.state.data).toBe('updated')
|
|
186
|
+
})
|
|
187
|
+
|
|
124
188
|
test('should also put useQueries into idle state', async () => {
|
|
125
189
|
const key = queryKey()
|
|
126
190
|
const states: UseQueryResult[] = []
|
|
@@ -538,4 +602,74 @@ describe('PersistQueryClientProvider', () => {
|
|
|
538
602
|
data: 'queryFn2',
|
|
539
603
|
})
|
|
540
604
|
})
|
|
605
|
+
|
|
606
|
+
test('should only restore once in StrictMode', async () => {
|
|
607
|
+
let restoreCount = 0
|
|
608
|
+
const createPersister = (): Persister => {
|
|
609
|
+
let storedState: PersistedClient | undefined
|
|
610
|
+
|
|
611
|
+
return {
|
|
612
|
+
async persistClient(persistClient) {
|
|
613
|
+
storedState = persistClient
|
|
614
|
+
},
|
|
615
|
+
async restoreClient() {
|
|
616
|
+
restoreCount++
|
|
617
|
+
await sleep(10)
|
|
618
|
+
return storedState
|
|
619
|
+
},
|
|
620
|
+
removeClient() {
|
|
621
|
+
storedState = undefined
|
|
622
|
+
},
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
const key = queryKey()
|
|
627
|
+
|
|
628
|
+
const queryClient = createQueryClient()
|
|
629
|
+
await queryClient.prefetchQuery(key, () => Promise.resolve('hydrated'))
|
|
630
|
+
|
|
631
|
+
const persister = createPersister()
|
|
632
|
+
|
|
633
|
+
const onSuccess = jest.fn()
|
|
634
|
+
|
|
635
|
+
await persistQueryClientSave({ queryClient, persister })
|
|
636
|
+
|
|
637
|
+
queryClient.clear()
|
|
638
|
+
|
|
639
|
+
function Page() {
|
|
640
|
+
const state = useQuery({
|
|
641
|
+
queryKey: key,
|
|
642
|
+
queryFn: async () => {
|
|
643
|
+
await sleep(10)
|
|
644
|
+
return 'fetched'
|
|
645
|
+
},
|
|
646
|
+
})
|
|
647
|
+
|
|
648
|
+
return (
|
|
649
|
+
<div>
|
|
650
|
+
<h1>{state.data}</h1>
|
|
651
|
+
<h2>fetchStatus: {state.fetchStatus}</h2>
|
|
652
|
+
</div>
|
|
653
|
+
)
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
const rendered = render(
|
|
657
|
+
<React.StrictMode>
|
|
658
|
+
<PersistQueryClientProvider
|
|
659
|
+
client={queryClient}
|
|
660
|
+
persistOptions={{ persister }}
|
|
661
|
+
onSuccess={onSuccess}
|
|
662
|
+
>
|
|
663
|
+
<Page />
|
|
664
|
+
</PersistQueryClientProvider>
|
|
665
|
+
</React.StrictMode>,
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
await waitFor(() => rendered.getByText('fetchStatus: idle'))
|
|
669
|
+
await waitFor(() => rendered.getByText('hydrated'))
|
|
670
|
+
await waitFor(() => rendered.getByText('fetched'))
|
|
671
|
+
|
|
672
|
+
expect(onSuccess).toHaveBeenCalledTimes(1)
|
|
673
|
+
expect(restoreCount).toBe(1)
|
|
674
|
+
})
|
|
541
675
|
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.d.ts","sourceRoot":"","sources":["../../src/PersistQueryClientProvider.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AACpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAErE,oBAAY,+BAA+B,GAAG,wBAAwB,GAAG;IACvE,cAAc,EAAE,IAAI,CAAC,yBAAyB,EAAE,aAAa,CAAC,CAAA;IAC9D,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,0BAA0B,8DAMpC,+BAA+B,KAAG,WAkCpC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/PersistQueryClientProvider.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,WAAW,CAGzE;AAED,eAAO,MAAM,UAAU;;;;CAItB,CAAA;AAGD,wBAAgB,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,CAGxC;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpD;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC,EAAE,MAAM,kBAMxD"}
|
package/build/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,qCAAqC,CAAA;AAEnD,cAAc,8BAA8B,CAAA"}
|