@tanstack/react-query-persist-client 4.35.4 → 4.35.7

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.
@@ -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 { persistQueryClient } from '@tanstack/query-persist-client-core';
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 = ({
@@ -24,23 +24,24 @@ const PersistQueryClientProvider = ({
24
24
  };
25
25
  });
26
26
  React.useEffect(() => {
27
+ const options = { ...refs.current.persistOptions,
28
+ queryClient: client
29
+ };
30
+
27
31
  if (!didRestore.current) {
28
32
  didRestore.current = true;
29
33
  setIsRestoring(true);
30
- const [unsubscribe, promise] = persistQueryClient({ ...refs.current.persistOptions,
31
- queryClient: client
32
- });
33
- promise.then(() => {
34
- refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
35
- setIsRestoring(false);
34
+ persistQueryClientRestore(options).then(async () => {
35
+ try {
36
+ await (refs.current.onSuccess == null ? void 0 : refs.current.onSuccess());
37
+ } finally {
38
+ setIsRestoring(false);
39
+ }
36
40
  });
37
- return () => {
38
- unsubscribe();
39
- };
40
41
  }
41
42
 
42
- return undefined;
43
- }, [client]);
43
+ return isRestoring ? undefined : persistQueryClientSubscribe(options);
44
+ }, [client, isRestoring]);
44
45
  return /*#__PURE__*/React.createElement(QueryClientProvider, _extends({
45
46
  client: client
46
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 { 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n })\n\n return () => {\n unsubscribe()\n }\n }\n return undefined\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["onSuccess","queryClient"],"mappings":";;;;;;AAaO;;;;;;AAAoC;;AAQzC;;AAA4CA;AAAlB;AAC1B;;;;AAGmCA;;;;AAIjC;;;AAGE;AAEEC;AAFgD;;;;;AAUlD;;;AAGD;;AACD;;AAGF;AACuB;;AACE;;AAG1B;;"}
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;;"}
@@ -48,23 +48,24 @@ const PersistQueryClientProvider = ({
48
48
  };
49
49
  });
50
50
  React__namespace.useEffect(() => {
51
+ const options = { ...refs.current.persistOptions,
52
+ queryClient: client
53
+ };
54
+
51
55
  if (!didRestore.current) {
52
56
  didRestore.current = true;
53
57
  setIsRestoring(true);
54
- const [unsubscribe, promise] = queryPersistClientCore.persistQueryClient({ ...refs.current.persistOptions,
55
- queryClient: client
56
- });
57
- promise.then(() => {
58
- refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
59
- setIsRestoring(false);
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
+ }
60
64
  });
61
- return () => {
62
- unsubscribe();
63
- };
64
65
  }
65
66
 
66
- return undefined;
67
- }, [client]);
67
+ return isRestoring ? undefined : queryPersistClientCore.persistQueryClientSubscribe(options);
68
+ }, [client, isRestoring]);
68
69
  return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _rollupPluginBabelHelpers["extends"]({
69
70
  client: client
70
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 { 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n })\n\n return () => {\n unsubscribe()\n }\n }\n return undefined\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["onSuccess","queryClient"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaO;;;;;;AAAoC;;AAQzC;;AAA4CA;AAAlB;AAC1B;;;;AAGmCA;;;;AAIjC;;;AAGE;AAEEC;AAFgD;;;;;AAUlD;;;AAGD;;AACD;;AAGF;AACuB;;AACE;;AAG1B;;"}
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 { persistQueryClient } from '@tanstack/query-persist-client-core';
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 = ({
@@ -24,23 +24,24 @@ const PersistQueryClientProvider = ({
24
24
  };
25
25
  });
26
26
  React.useEffect(() => {
27
+ const options = { ...refs.current.persistOptions,
28
+ queryClient: client
29
+ };
30
+
27
31
  if (!didRestore.current) {
28
32
  didRestore.current = true;
29
33
  setIsRestoring(true);
30
- const [unsubscribe, promise] = persistQueryClient({ ...refs.current.persistOptions,
31
- queryClient: client
32
- });
33
- promise.then(() => {
34
- refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
35
- setIsRestoring(false);
34
+ persistQueryClientRestore(options).then(async () => {
35
+ try {
36
+ await (refs.current.onSuccess == null ? void 0 : refs.current.onSuccess());
37
+ } finally {
38
+ setIsRestoring(false);
39
+ }
36
40
  });
37
- return () => {
38
- unsubscribe();
39
- };
40
41
  }
41
42
 
42
- return undefined;
43
- }, [client]);
43
+ return isRestoring ? undefined : persistQueryClientSubscribe(options);
44
+ }, [client, isRestoring]);
44
45
  return /*#__PURE__*/React.createElement(QueryClientProvider, _extends({
45
46
  client: client
46
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 { 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n })\n\n return () => {\n unsubscribe()\n }\n }\n return undefined\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["onSuccess","queryClient"],"mappings":";;;;;;AAaO;;;;;;AAAoC;;AAQzC;;AAA4CA;AAAlB;AAC1B;;;;AAGmCA;;;;AAIjC;;;AAGE;AAEEC;AAFgD;;;;;AAUlD;;;AAGD;;AACD;;AAGF;AACuB;;AACE;;AAG1B;;"}
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;;"}
@@ -96,18 +96,23 @@
96
96
  mutationKey: dehydratedMutation.mutationKey
97
97
  }, dehydratedMutation.state);
98
98
  });
99
- queries.forEach(dehydratedQuery => {
99
+ queries.forEach(({
100
+ queryKey,
101
+ state,
102
+ queryHash
103
+ }) => {
100
104
  var _options$defaultOptio2;
101
105
 
102
- const query = queryCache.get(dehydratedQuery.queryHash); // Reset fetch status to idle in the dehydrated state to avoid
103
- // query being stuck in fetching state upon hydration
104
-
105
- const dehydratedQueryState = { ...dehydratedQuery.state,
106
- fetchStatus: 'idle'
107
- }; // Do not hydrate if an existing query exists with newer data
106
+ const query = queryCache.get(queryHash); // Do not hydrate if an existing query exists with newer data
108
107
 
109
108
  if (query) {
110
- if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
109
+ if (query.state.dataUpdatedAt < state.dataUpdatedAt) {
110
+ // omit fetchStatus from dehydrated state
111
+ // so that query stays in its current fetchStatus
112
+ const {
113
+ fetchStatus: _ignored,
114
+ ...dehydratedQueryState
115
+ } = state;
111
116
  query.setState(dehydratedQueryState);
112
117
  }
113
118
 
@@ -116,9 +121,13 @@
116
121
 
117
122
 
118
123
  queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
119
- queryKey: dehydratedQuery.queryKey,
120
- queryHash: dehydratedQuery.queryHash
121
- }, dehydratedQueryState);
124
+ queryKey,
125
+ queryHash
126
+ }, // Reset fetch status to idle to avoid
127
+ // query being stuck in fetching state upon hydration
128
+ { ...state,
129
+ fetchStatus: 'idle'
130
+ });
122
131
  });
123
132
  }
124
133
 
@@ -295,23 +304,24 @@
295
304
  };
296
305
  });
297
306
  React__namespace.useEffect(() => {
307
+ const options = { ...refs.current.persistOptions,
308
+ queryClient: client
309
+ };
310
+
298
311
  if (!didRestore.current) {
299
312
  didRestore.current = true;
300
313
  setIsRestoring(true);
301
- const [unsubscribe, promise] = persistQueryClient({ ...refs.current.persistOptions,
302
- queryClient: client
303
- });
304
- promise.then(() => {
305
- refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
306
- setIsRestoring(false);
314
+ persistQueryClientRestore(options).then(async () => {
315
+ try {
316
+ await (refs.current.onSuccess == null ? void 0 : refs.current.onSuccess());
317
+ } finally {
318
+ setIsRestoring(false);
319
+ }
307
320
  });
308
- return () => {
309
- unsubscribe();
310
- };
311
321
  }
312
322
 
313
- return undefined;
314
- }, [client]);
323
+ return isRestoring ? undefined : persistQueryClientSubscribe(options);
324
+ }, [client, isRestoring]);
315
325
  return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _extends({
316
326
  client: client
317
327
  }, 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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n })\n\n return () => {\n unsubscribe()\n }\n }\n return undefined\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","didRestore","useEffect","current","unsubscribe","promise","persistQueryClient","queryClient","then","undefined","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,CA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A;;EACD,IAAA,OAAOK,SAAP,CAAA;KAlBF,EAmBG,CAACnB,MAAD,CAnBH,CAAA,CAAA;EAqBA,EAAA,oBACEO,+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
+ {"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(({\n queryKey,\n state,\n queryHash\n }) => {\n var _options$defaultOptio2;\n\n const query = queryCache.get(queryHash); // Do not hydrate if an existing query exists with newer data\n\n if (query) {\n if (query.state.dataUpdatedAt < state.dataUpdatedAt) {\n // omit fetchStatus from dehydrated state\n // so that query stays in its current fetchStatus\n const {\n fetchStatus: _ignored,\n ...dehydratedQueryState\n } = state;\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,\n queryHash\n }, // Reset fetch status to idle to avoid\n // query being stuck in fetching state upon hydration\n { ...state,\n fetchStatus: 'idle'\n });\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;E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A;QACAP,cAAc,CAAC,IAAD,CAAd,CAAA;EACAU,MAAAA,yBAAyB,CAACF,OAAD,CAAzB,CAAmCG,IAAnC,CAAwC,YAAY;UAClD,IAAI;YACF,OAAMR,IAAI,CAACI,OAAL,CAAaV,SAAnB,IAAMM,IAAAA,GAAAA,KAAAA,CAAAA,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 f({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)&&f(e)})),r=e.queryClient.getMutationCache().subscribe((t=>{c(t.type)&&f(e)}));return()=>{t(),r()}}function y(e){let t,r=!1;return[()=>{r=!0,null==t||t()},l(e).then((()=>{r||(t=d(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:u,...i})=>{const[a,o]=s.useState(!0),c=s.useRef({persistOptions:n,onSuccess:u}),l=s.useRef(!1);return s.useEffect((()=>{c.current={persistOptions:n,onSuccess:u}})),s.useEffect((()=>{if(!l.current){l.current=!0,o(!0);const[t,r]=y({...c.current.persistOptions,queryClient:e});return r.then((()=>{null==c.current.onSuccess||c.current.onSuccess(),o(!1)})),()=>{t()}}}),[e]),s.createElement(r.QueryClientProvider,p({client:e},i),s.createElement(r.IsRestoringProvider,{value:a},t))},e.persistQueryClient=y,e.persistQueryClientRestore=l,e.persistQueryClientSave=f,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})}));
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 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=>{var s;n.build(e,{...null==r||null==(s=r.defaultOptions)?void 0:s.mutations,mutationKey:t.mutationKey},t.state)})),u.forEach((({queryKey:t,state:n,queryHash:i})=>{var u;const a=s.get(i);if(a){if(a.state.dataUpdatedAt<n.dataUpdatedAt){const{fetchStatus:e,...t}=n;a.setState(t)}}else s.build(e,{...null==r||null==(u=r.defaultOptions)?void 0:u.queries,queryKey:t,queryHash:i},{...n,fetchStatus:"idle"})}))}(e,i.clientState,s)}else t.removeClient()}catch(e){t.removeClient()}}async function f({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)&&f(e)})),r=e.queryClient.getMutationCache().subscribe((t=>{c(t.type)&&f(e)}));return()=>{t(),r()}}function y(){return y=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},y.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}),f=s.useRef(!1);return s.useEffect((()=>{c.current={persistOptions:n,onSuccess:i}})),s.useEffect((()=>{const t={...c.current.persistOptions,queryClient:e};return f.current||(f.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,y({client:e},u),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=f,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 const didRestore = React.useRef(false)\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n if (!didRestore.current) {\n didRestore.current = true\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n })\n\n return () => {\n unsubscribe()\n }\n }\n return undefined\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","didRestore","useEffect","current","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,YAAvB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AC,iBACAC,eACGZ,MAEH,MAAOa,EAAaC,GAAkBC,EAAMC,UAAS,GAC/CC,EAAOF,EAAMG,OAAO,CAAEP,iBAAgBC,cACtCO,EAAaJ,EAAMG,QAAO,GA2BhC,OAzBAH,EAAMK,WAAU,KACdH,EAAKI,QAAU,CAAEV,iBAAgBC,gBAGnCG,EAAMK,WAAU,KACd,IAAKD,EAAWE,QAAS,CACvBF,EAAWE,SAAU,EACrBP,GAAe,GACf,MAAOQ,EAAaC,GAAWjB,EAAmB,IAC7CW,EAAKI,QAAQV,eAChB7C,YAAaxB,IAQf,OALAiF,EAAQd,MAAK,WACXQ,EAAKI,QAAQT,WAAbK,EAAKI,QAAQT,YACbE,GAAe,MAGV,KACLQ,QAIH,CAAChF,IAGFyE,gBAACS,EAADA,oBAAAC,EAAA,CAAqBnF,OAAQA,GAAY0D,GACvCe,EAAAW,cAACC,EAAAA,oBAAD,CAAqBC,MAAOf,GAAcH,yICnDtB,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(({\n queryKey,\n state,\n queryHash\n }) => {\n var _options$defaultOptio2;\n\n const query = queryCache.get(queryHash); // Do not hydrate if an existing query exists with newer data\n\n if (query) {\n if (query.state.dataUpdatedAt < state.dataUpdatedAt) {\n // omit fetchStatus from dehydrated state\n // so that query stays in its current fetchStatus\n const {\n fetchStatus: _ignored,\n ...dehydratedQueryState\n } = state;\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,\n queryHash\n }, // Reset fetch status to idle to avoid\n // query being stuck in fetching state upon hydration\n { ...state,\n fetchStatus: 'idle'\n });\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","_options$defaultOptio2","get","dataUpdatedAt","fetchStatus","_ignored","dehydratedQueryState","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,EAAW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ClBuB,YAAa,CACXlD,YACAC,YAIEkF,EAAgB,IAAIlF,GAASmF,MAAK,CAACC,EAAGC,IAAMD,EAAE7F,MAAMoD,cAAgB0C,EAAE9F,MAAMoD,gBAElF,GAAIuC,EAAcI,OAAS,EAAG,CAC5B,MAAMC,EAAaL,EAAcM,QAEjC,OADA3F,EAAOoD,YAAYjD,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": "4.35.4",
3
+ "version": "4.35.7",
4
4
  "description": "React bindings to work with persisters in TanStack/react-query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -38,13 +38,13 @@
38
38
  "react-17": "npm:react@^17.0.2",
39
39
  "react-dom": "^18.2.0",
40
40
  "react-dom-17": "npm:react-dom@^17.0.2",
41
- "@tanstack/react-query": "4.35.3"
41
+ "@tanstack/react-query": "4.35.7"
42
42
  },
43
43
  "dependencies": {
44
- "@tanstack/query-persist-client-core": "4.35.3"
44
+ "@tanstack/query-persist-client-core": "4.35.7"
45
45
  },
46
46
  "peerDependencies": {
47
- "@tanstack/react-query": "^4.35.3"
47
+ "@tanstack/react-query": "^4.35.7"
48
48
  },
49
49
  "scripts": {
50
50
  "clean": "rimraf ./build",
@@ -1,7 +1,10 @@
1
1
  'use client'
2
2
  import * as React from 'react'
3
3
 
4
- import { persistQueryClient } from '@tanstack/query-persist-client-core'
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'
@@ -27,25 +30,23 @@ export const PersistQueryClientProvider = ({
27
30
  })
28
31
 
29
32
  React.useEffect(() => {
33
+ const options = {
34
+ ...refs.current.persistOptions,
35
+ queryClient: client,
36
+ }
30
37
  if (!didRestore.current) {
31
38
  didRestore.current = true
32
39
  setIsRestoring(true)
33
- const [unsubscribe, promise] = persistQueryClient({
34
- ...refs.current.persistOptions,
35
- queryClient: client,
36
- })
37
-
38
- promise.then(() => {
39
- refs.current.onSuccess?.()
40
- setIsRestoring(false)
40
+ persistQueryClientRestore(options).then(async () => {
41
+ try {
42
+ await refs.current.onSuccess?.()
43
+ } finally {
44
+ setIsRestoring(false)
45
+ }
41
46
  })
42
-
43
- return () => {
44
- unsubscribe()
45
- }
46
47
  }
47
- return undefined
48
- }, [client])
48
+ return isRestoring ? undefined : persistQueryClientSubscribe(options)
49
+ }, [client, isRestoring])
49
50
 
50
51
  return (
51
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[] = []