@tanstack/react-query-persist-client 5.0.0-alpha.5 → 5.0.0-alpha.50

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,8 @@
1
1
  import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core';
2
2
  import type { QueryClientProviderProps } from '@tanstack/react-query';
3
- export declare type PersistQueryClientProviderProps = QueryClientProviderProps & {
3
+ export type PersistQueryClientProviderProps = QueryClientProviderProps & {
4
4
  persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>;
5
- onSuccess?: () => void;
5
+ onSuccess?: () => Promise<unknown> | unknown;
6
6
  };
7
7
  export declare const PersistQueryClientProvider: ({ client, children, persistOptions, onSuccess, ...props }: PersistQueryClientProviderProps) => JSX.Element;
8
+ //# sourceMappingURL=PersistQueryClientProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersistQueryClientProvider.d.ts","sourceRoot":"","sources":["../../src/PersistQueryClientProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AAEpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAGrE,MAAM,MAAM,+BAA+B,GAAG,wBAAwB,GAAG;IACvE,cAAc,EAAE,IAAI,CAAC,yBAAyB,EAAE,aAAa,CAAC,CAAA;IAC9D,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;CAC7C,CAAA;AAED,eAAO,MAAM,0BAA0B,8DAMpC,+BAA+B,KAAG,WAqCpC,CAAA"}
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  'use strict';
2
3
 
3
4
  var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
@@ -49,10 +50,13 @@ const PersistQueryClientProvider = ({
49
50
  ...refs.current.persistOptions,
50
51
  queryClient: client
51
52
  });
52
- promise.then(() => {
53
+ promise.then(async () => {
53
54
  if (!isStale) {
54
- refs.current.onSuccess?.();
55
- setIsRestoring(false);
55
+ try {
56
+ await refs.current.onSuccess?.();
57
+ } finally {
58
+ setIsRestoring(false);
59
+ }
56
60
  }
57
61
  });
58
62
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","_extends","IsRestoringProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaO,MA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AAG,gBAAA,CAAA,aAAA,CAACc,8BAAmB,EAAA;AAAC,IAAA,KAAK,EAAEhB,WAAAA;GAAcJ,EAAAA,QAAQ,CAAuB,CACrD,CAAA;AAE1B;;;;"}
1
+ {"version":3,"file":"PersistQueryClientProvider.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\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(async () => {\n if (!isStale) {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\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":["onSuccess","queryClient","isStale","unsubscribe","client","value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAaO;;;;;;AAM0B;;AAE/B;;AAA4CA;AAAU;;;;AAGnBA;;AACnC;;;;AAKE;AACE;AACAC;AACF;;;;AAKM;AACF;;AAEA;AACF;AACF;AAEA;AACEC;AACAC;;AAEJ;AAEA;AACuBC;AAAe;AACbC;;AAG3B;;"}
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { extends as _extends } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
3
  import * as React from 'react';
3
4
  import { persistQueryClient } from '@tanstack/query-persist-client-core';
@@ -28,10 +29,13 @@ const PersistQueryClientProvider = ({
28
29
  ...refs.current.persistOptions,
29
30
  queryClient: client
30
31
  });
31
- promise.then(() => {
32
+ promise.then(async () => {
32
33
  if (!isStale) {
33
- refs.current.onSuccess?.();
34
- setIsRestoring(false);
34
+ try {
35
+ await refs.current.onSuccess?.();
36
+ } finally {
37
+ setIsRestoring(false);
38
+ }
35
39
  }
36
40
  });
37
41
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.mjs","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then"],"mappings":";;;;;AAaO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,MAAM;EACNC,QAAQ;EACRC,cAAc;EACdC,SAAS;EACT,GAAGC,KAAAA;AAC4B,CAAC,KAAkB;EAClD,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAC1D,EAAA,MAAMC,IAAI,GAAGF,KAAK,CAACG,MAAM,CAAC;IAAER,cAAc;AAAEC,IAAAA,SAAAA;AAAU,GAAC,CAAC,CAAA;EAExDI,KAAK,CAACI,SAAS,CAAC,MAAM;IACpBF,IAAI,CAACG,OAAO,GAAG;MAAEV,cAAc;AAAEC,MAAAA,SAAAA;KAAW,CAAA;AAC9C,GAAC,CAAC,CAAA;EAEFI,KAAK,CAACI,SAAS,CAAC,MAAM;IACpB,IAAIE,OAAO,GAAG,KAAK,CAAA;IACnBP,cAAc,CAAC,IAAI,CAAC,CAAA;AACpB,IAAA,MAAM,CAACQ,WAAW,EAAEC,OAAO,CAAC,GAAGC,kBAAkB,CAAC;AAChD,MAAA,GAAGP,IAAI,CAACG,OAAO,CAACV,cAAc;AAC9Be,MAAAA,WAAW,EAAEjB,MAAAA;AACf,KAAC,CAAC,CAAA;IAEFe,OAAO,CAACG,IAAI,CAAC,MAAM;MACjB,IAAI,CAACL,OAAO,EAAE;AACZJ,QAAAA,IAAI,CAACG,OAAO,CAACT,SAAS,IAAI,CAAA;QAC1BG,cAAc,CAAC,KAAK,CAAC,CAAA;AACvB,OAAA;AACF,KAAC,CAAC,CAAA;AAEF,IAAA,OAAO,MAAM;AACXO,MAAAA,OAAO,GAAG,IAAI,CAAA;AACdC,MAAAA,WAAW,EAAE,CAAA;KACd,CAAA;AACH,GAAC,EAAE,CAACd,MAAM,CAAC,CAAC,CAAA;AAEZ,EAAA,oBACE,oBAAC,mBAAmB,EAAA,QAAA,CAAA;AAAC,IAAA,MAAM,EAAEA,MAAAA;GAAYI,EAAAA,KAAK,CAC5C,eAAA,KAAA,CAAA,aAAA,CAAC,mBAAmB,EAAA;AAAC,IAAA,KAAK,EAAEC,WAAAA;GAAcJ,EAAAA,QAAQ,CAAuB,CACrD,CAAA;AAE1B;;;;"}
1
+ {"version":3,"file":"PersistQueryClientProvider.mjs","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\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(async () => {\n if (!isStale) {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\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":["onSuccess","queryClient","isStale","unsubscribe","client","value"],"mappings":";;;;;;AAaO;;;;;;AAM0B;;AAE/B;;AAA4CA;AAAU;;;;AAGnBA;;AACnC;;;;AAKE;AACE;AACAC;AACF;;;;AAKM;AACF;;AAEA;AACF;AACF;AAEA;AACEC;AACAC;;AAEJ;AAEA;AACuBC;AAAe;AACbC;;AAG3B;;"}
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=PersistQueryClientProvider.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersistQueryClientProvider.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/PersistQueryClientProvider.test.tsx"],"names":[],"mappings":""}
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
- import type { QueryClientConfig } from '@tanstack/query-core';
3
- import { QueryClient } from '@tanstack/query-core';
2
+ import type { QueryClientConfig } from '@tanstack/react-query';
3
+ import { QueryClient } from '@tanstack/react-query';
4
4
  export declare function createQueryClient(config?: QueryClientConfig): QueryClient;
5
5
  export declare function queryKey(): Array<string>;
6
6
  export declare function sleep(timeout: number): Promise<void>;
7
7
  export declare function setActTimeout(fn: () => void, ms?: number): NodeJS.Timeout;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,WAAW,CAEzE;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"}
@@ -1,2 +1,3 @@
1
1
  export * from '@tanstack/query-persist-client-core';
2
2
  export * from './PersistQueryClientProvider';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,qCAAqC,CAAA;AAEnD,cAAc,8BAA8B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query-persist-client",
3
- "version": "5.0.0-alpha.5",
3
+ "version": "5.0.0-alpha.50",
4
4
  "description": "React bindings to work with persisters in TanStack/react-query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -10,9 +10,10 @@
10
10
  "type": "github",
11
11
  "url": "https://github.com/sponsors/tannerlinsley"
12
12
  },
13
+ "type": "commonjs",
13
14
  "types": "build/lib/index.d.ts",
14
15
  "main": "build/lib/index.js",
15
- "module": "build/lib/index.esm.js",
16
+ "module": "build/lib/index.mjs",
16
17
  "exports": {
17
18
  ".": {
18
19
  "types": "./build/lib/index.d.ts",
@@ -24,28 +25,29 @@
24
25
  "sideEffects": false,
25
26
  "files": [
26
27
  "build/lib/*",
27
- "build/umd/*",
28
28
  "src"
29
29
  ],
30
+ "dependencies": {
31
+ "@tanstack/query-persist-client-core": "^5.0.0-alpha.43"
32
+ },
30
33
  "devDependencies": {
31
- "@types/react": "^18.0.14",
32
- "@types/react-dom": "^18.0.5",
34
+ "@tanstack/react-query": "^5.0.0-alpha.43",
35
+ "@types/react": "^18.2.4",
36
+ "@types/react-dom": "^18.2.4",
33
37
  "react": "^18.2.0",
34
- "react-dom": "^18.2.0",
35
- "@tanstack/react-query": "5.0.0-alpha.5"
36
- },
37
- "dependencies": {
38
- "@tanstack/query-persist-client-core": "5.0.0-alpha.5"
38
+ "react-dom": "^18.2.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@tanstack/react-query": "5.0.0-alpha.5"
41
+ "@tanstack/react-query": "^5.0.0-alpha.43"
42
42
  },
43
43
  "scripts": {
44
- "clean": "rimraf ./build",
44
+ "clean": "rimraf ./build && rimraf ./coverage",
45
45
  "test:eslint": "eslint --ext .ts,.tsx ./src",
46
- "test:types": "tsc",
46
+ "test:types": "tsc --noEmit",
47
47
  "test:lib": "vitest run --coverage",
48
48
  "test:lib:dev": "pnpm run test:lib --watch",
49
- "build:types": "tsc --build"
49
+ "build": "pnpm build:rollup && pnpm build:types",
50
+ "build:rollup": "rollup --config rollup.config.mjs",
51
+ "build:types": "tsc --emitDeclarationOnly"
50
52
  }
51
53
  }
@@ -8,7 +8,7 @@ import { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'
8
8
 
9
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
10
10
  persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>
11
- onSuccess?: () => void
11
+ onSuccess?: () => Promise<unknown> | unknown
12
12
  }
13
13
 
14
14
  export const PersistQueryClientProvider = ({
@@ -33,10 +33,13 @@ export const PersistQueryClientProvider = ({
33
33
  queryClient: client,
34
34
  })
35
35
 
36
- promise.then(() => {
36
+ promise.then(async () => {
37
37
  if (!isStale) {
38
- refs.current.onSuccess?.()
39
- setIsRestoring(false)
38
+ try {
39
+ await refs.current.onSuccess?.()
40
+ } finally {
41
+ setIsRestoring(false)
42
+ }
40
43
  }
41
44
  })
42
45
 
@@ -401,6 +401,66 @@ describe('PersistQueryClientProvider', () => {
401
401
  await waitFor(() => rendered.getByText('fetched'))
402
402
  })
403
403
 
404
+ test('should await onSuccess after successful restoring', async () => {
405
+ const key = queryKey()
406
+
407
+ const queryClient = createQueryClient()
408
+ await queryClient.prefetchQuery({
409
+ queryKey: key,
410
+ queryFn: () => Promise.resolve('hydrated'),
411
+ })
412
+
413
+ const persister = createMockPersister()
414
+
415
+ await persistQueryClientSave({ queryClient, persister })
416
+
417
+ queryClient.clear()
418
+
419
+ const states: Array<string> = []
420
+
421
+ function Page() {
422
+ const { data, fetchStatus } = useQuery({
423
+ queryKey: key,
424
+ queryFn: async () => {
425
+ states.push('fetching')
426
+ await sleep(10)
427
+ states.push('fetched')
428
+ return 'fetched'
429
+ },
430
+ })
431
+
432
+ return (
433
+ <div>
434
+ <h1>{data}</h1>
435
+ <h2>fetchStatus: {fetchStatus}</h2>
436
+ </div>
437
+ )
438
+ }
439
+
440
+ const rendered = render(
441
+ <PersistQueryClientProvider
442
+ client={queryClient}
443
+ persistOptions={{ persister }}
444
+ onSuccess={async () => {
445
+ states.push('onSuccess')
446
+ await sleep(20)
447
+ states.push('onSuccess done')
448
+ }}
449
+ >
450
+ <Page />
451
+ </PersistQueryClientProvider>,
452
+ )
453
+
454
+ await waitFor(() => rendered.getByText('hydrated'))
455
+ await waitFor(() => rendered.getByText('fetched'))
456
+ expect(states).toEqual([
457
+ 'onSuccess',
458
+ 'onSuccess done',
459
+ 'fetching',
460
+ 'fetched',
461
+ ])
462
+ })
463
+
404
464
  test('should remove cache after non-successful restoring', async () => {
405
465
  const key = queryKey()
406
466
  const consoleMock = vi.spyOn(console, 'error')
@@ -1,7 +1,7 @@
1
1
  import { act } from '@testing-library/react'
2
2
 
3
- import type { QueryClientConfig } from '@tanstack/query-core'
4
- import { QueryClient } from '@tanstack/query-core'
3
+ import type { QueryClientConfig } from '@tanstack/react-query'
4
+ import { QueryClient } from '@tanstack/react-query'
5
5
 
6
6
  export function createQueryClient(config?: QueryClientConfig): QueryClient {
7
7
  return new QueryClient(config)
@@ -1,50 +0,0 @@
1
- import { extends as _extends } from './_virtual/_rollupPluginBabelHelpers.esm.js';
2
- import * as React from 'react';
3
- import { persistQueryClient } from '@tanstack/query-persist-client-core';
4
- import { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query';
5
-
6
- const PersistQueryClientProvider = ({
7
- client,
8
- children,
9
- persistOptions,
10
- onSuccess,
11
- ...props
12
- }) => {
13
- const [isRestoring, setIsRestoring] = React.useState(true);
14
- const refs = React.useRef({
15
- persistOptions,
16
- onSuccess
17
- });
18
- React.useEffect(() => {
19
- refs.current = {
20
- persistOptions,
21
- onSuccess
22
- };
23
- });
24
- React.useEffect(() => {
25
- let isStale = false;
26
- setIsRestoring(true);
27
- const [unsubscribe, promise] = persistQueryClient({
28
- ...refs.current.persistOptions,
29
- queryClient: client
30
- });
31
- promise.then(() => {
32
- if (!isStale) {
33
- refs.current.onSuccess?.();
34
- setIsRestoring(false);
35
- }
36
- });
37
- return () => {
38
- isStale = true;
39
- unsubscribe();
40
- };
41
- }, [client]);
42
- return /*#__PURE__*/React.createElement(QueryClientProvider, _extends({
43
- client: client
44
- }, props), /*#__PURE__*/React.createElement(IsRestoringProvider, {
45
- value: isRestoring
46
- }, children));
47
- };
48
-
49
- export { PersistQueryClientProvider };
50
- //# sourceMappingURL=PersistQueryClientProvider.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersistQueryClientProvider.esm.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then"],"mappings":";;;;;AAaO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,MAAM;EACNC,QAAQ;EACRC,cAAc;EACdC,SAAS;EACT,GAAGC,KAAAA;AAC4B,CAAC,KAAkB;EAClD,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAC1D,EAAA,MAAMC,IAAI,GAAGF,KAAK,CAACG,MAAM,CAAC;IAAER,cAAc;AAAEC,IAAAA,SAAAA;AAAU,GAAC,CAAC,CAAA;EAExDI,KAAK,CAACI,SAAS,CAAC,MAAM;IACpBF,IAAI,CAACG,OAAO,GAAG;MAAEV,cAAc;AAAEC,MAAAA,SAAAA;KAAW,CAAA;AAC9C,GAAC,CAAC,CAAA;EAEFI,KAAK,CAACI,SAAS,CAAC,MAAM;IACpB,IAAIE,OAAO,GAAG,KAAK,CAAA;IACnBP,cAAc,CAAC,IAAI,CAAC,CAAA;AACpB,IAAA,MAAM,CAACQ,WAAW,EAAEC,OAAO,CAAC,GAAGC,kBAAkB,CAAC;AAChD,MAAA,GAAGP,IAAI,CAACG,OAAO,CAACV,cAAc;AAC9Be,MAAAA,WAAW,EAAEjB,MAAAA;AACf,KAAC,CAAC,CAAA;IAEFe,OAAO,CAACG,IAAI,CAAC,MAAM;MACjB,IAAI,CAACL,OAAO,EAAE;AACZJ,QAAAA,IAAI,CAACG,OAAO,CAACT,SAAS,IAAI,CAAA;QAC1BG,cAAc,CAAC,KAAK,CAAC,CAAA;AACvB,OAAA;AACF,KAAC,CAAC,CAAA;AAEF,IAAA,OAAO,MAAM;AACXO,MAAAA,OAAO,GAAG,IAAI,CAAA;AACdC,MAAAA,WAAW,EAAE,CAAA;KACd,CAAA;AACH,GAAC,EAAE,CAACd,MAAM,CAAC,CAAC,CAAA;AAEZ,EAAA,oBACE,oBAAC,mBAAmB,EAAA,QAAA,CAAA;AAAC,IAAA,MAAM,EAAEA,MAAAA;GAAYI,EAAAA,KAAK,CAC5C,eAAA,KAAA,CAAA,aAAA,CAAC,mBAAmB,EAAA;AAAC,IAAA,KAAK,EAAEC,WAAAA;GAAcJ,EAAAA,QAAQ,CAAuB,CACrD,CAAA;AAE1B;;;;"}
@@ -1,17 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign ? Object.assign.bind() : function (target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
- for (var key in source) {
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
-
16
- export { _extends as extends };
17
- //# sourceMappingURL=_rollupPluginBabelHelpers.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -1,3 +0,0 @@
1
- export * from '@tanstack/query-persist-client-core';
2
- export { PersistQueryClientProvider } from './PersistQueryClientProvider.esm.js';
3
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,320 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@tanstack/react-query')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@tanstack/react-query'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQueryPersistClient = {}, global.React, global.ReactQuery));
5
- })(this, (function (exports, React, reactQuery) { 'use strict';
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
25
-
26
- // TYPES
27
-
28
- // FUNCTIONS
29
-
30
- function dehydrateMutation(mutation) {
31
- return {
32
- mutationKey: mutation.options.mutationKey,
33
- state: mutation.state
34
- };
35
- }
36
-
37
- // Most config is not dehydrated but instead meant to configure again when
38
- // consuming the de/rehydrated data, typically with useQuery on the client.
39
- // Sometimes it might make sense to prefetch data on the server and include
40
- // in the html-payload, but not consume it on the initial render.
41
- function dehydrateQuery(query) {
42
- return {
43
- state: query.state,
44
- queryKey: query.queryKey,
45
- queryHash: query.queryHash
46
- };
47
- }
48
- function defaultShouldDehydrateMutation(mutation) {
49
- return mutation.state.isPaused;
50
- }
51
- function defaultShouldDehydrateQuery(query) {
52
- return query.state.status === 'success';
53
- }
54
- function dehydrate(client, options = {}) {
55
- const mutations = [];
56
- const queries = [];
57
- if (options.dehydrateMutations !== false) {
58
- const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
59
- client.getMutationCache().getAll().forEach(mutation => {
60
- if (shouldDehydrateMutation(mutation)) {
61
- mutations.push(dehydrateMutation(mutation));
62
- }
63
- });
64
- }
65
- if (options.dehydrateQueries !== false) {
66
- const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
67
- client.getQueryCache().getAll().forEach(query => {
68
- if (shouldDehydrateQuery(query)) {
69
- queries.push(dehydrateQuery(query));
70
- }
71
- });
72
- }
73
- return {
74
- mutations,
75
- queries
76
- };
77
- }
78
- function hydrate(client, dehydratedState, options) {
79
- if (typeof dehydratedState !== 'object' || dehydratedState === null) {
80
- return;
81
- }
82
- const mutationCache = client.getMutationCache();
83
- const queryCache = client.getQueryCache();
84
-
85
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
86
- const mutations = dehydratedState.mutations || [];
87
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
88
- const queries = dehydratedState.queries || [];
89
- mutations.forEach(dehydratedMutation => {
90
- mutationCache.build(client, {
91
- ...options?.defaultOptions?.mutations,
92
- mutationKey: dehydratedMutation.mutationKey
93
- }, dehydratedMutation.state);
94
- });
95
- queries.forEach(dehydratedQuery => {
96
- const query = queryCache.get(dehydratedQuery.queryHash);
97
-
98
- // Reset fetch status to idle in the dehydrated state to avoid
99
- // query being stuck in fetching state upon hydration
100
- const dehydratedQueryState = {
101
- ...dehydratedQuery.state,
102
- fetchStatus: 'idle'
103
- };
104
-
105
- // Do not hydrate if an existing query exists with newer data
106
- if (query) {
107
- if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
108
- query.setState(dehydratedQueryState);
109
- }
110
- return;
111
- }
112
-
113
- // Restore query
114
- queryCache.build(client, {
115
- ...options?.defaultOptions?.queries,
116
- queryKey: dehydratedQuery.queryKey,
117
- queryHash: dehydratedQuery.queryHash
118
- }, dehydratedQueryState);
119
- });
120
- }
121
-
122
- /**
123
- * Checks if emitted event is about cache change and not about observers.
124
- * Useful for persist, where we only want to trigger save when cache is changed.
125
- */
126
- const cacheableEventTypes = ['added', 'removed', 'updated'];
127
- function isCacheableEventType(eventType) {
128
- return cacheableEventTypes.includes(eventType);
129
- }
130
-
131
- /**
132
- * Restores persisted data to the QueryCache
133
- * - data obtained from persister.restoreClient
134
- * - data is hydrated using hydrateOptions
135
- * If data is expired, busted, empty, or throws, it runs persister.removeClient
136
- */
137
- async function persistQueryClientRestore({
138
- queryClient,
139
- persister,
140
- maxAge = 1000 * 60 * 60 * 24,
141
- buster = '',
142
- hydrateOptions
143
- }) {
144
- try {
145
- const persistedClient = await persister.restoreClient();
146
- if (persistedClient) {
147
- if (persistedClient.timestamp) {
148
- const expired = Date.now() - persistedClient.timestamp > maxAge;
149
- const busted = persistedClient.buster !== buster;
150
- if (expired || busted) {
151
- persister.removeClient();
152
- } else {
153
- hydrate(queryClient, persistedClient.clientState, hydrateOptions);
154
- }
155
- } else {
156
- persister.removeClient();
157
- }
158
- }
159
- } catch (err) {
160
- {
161
- console.error(err);
162
- console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
163
- }
164
- persister.removeClient();
165
- }
166
- }
167
-
168
- /**
169
- * Persists data from the QueryCache
170
- * - data dehydrated using dehydrateOptions
171
- * - data is persisted using persister.persistClient
172
- */
173
- async function persistQueryClientSave({
174
- queryClient,
175
- persister,
176
- buster = '',
177
- dehydrateOptions
178
- }) {
179
- const persistClient = {
180
- buster,
181
- timestamp: Date.now(),
182
- clientState: dehydrate(queryClient, dehydrateOptions)
183
- };
184
- await persister.persistClient(persistClient);
185
- }
186
-
187
- /**
188
- * Subscribe to QueryCache and MutationCache updates (for persisting)
189
- * @returns an unsubscribe function (to discontinue monitoring)
190
- */
191
- function persistQueryClientSubscribe(props) {
192
- const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {
193
- if (isCacheableEventType(event.type)) {
194
- persistQueryClientSave(props);
195
- }
196
- });
197
- const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {
198
- if (isCacheableEventType(event.type)) {
199
- persistQueryClientSave(props);
200
- }
201
- });
202
- return () => {
203
- unsubscribeQueryCache();
204
- unusbscribeMutationCache();
205
- };
206
- }
207
-
208
- /**
209
- * Restores persisted data to QueryCache and persists further changes.
210
- */
211
- function persistQueryClient(props) {
212
- let hasUnsubscribed = false;
213
- let persistQueryClientUnsubscribe;
214
- const unsubscribe = () => {
215
- hasUnsubscribed = true;
216
- persistQueryClientUnsubscribe?.();
217
- };
218
-
219
- // Attempt restore
220
- const restorePromise = persistQueryClientRestore(props).then(() => {
221
- if (!hasUnsubscribed) {
222
- // Subscribe to changes in the query cache to trigger the save
223
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
224
- }
225
- });
226
- return [unsubscribe, restorePromise];
227
- }
228
-
229
- const removeOldestQuery = ({
230
- persistedClient
231
- }) => {
232
- const mutations = [...persistedClient.clientState.mutations];
233
- const queries = [...persistedClient.clientState.queries];
234
- const client = {
235
- ...persistedClient,
236
- clientState: {
237
- mutations,
238
- queries
239
- }
240
- };
241
-
242
- // sort queries by dataUpdatedAt (oldest first)
243
- const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);
244
-
245
- // clean oldest query
246
- if (sortedQueries.length > 0) {
247
- const oldestData = sortedQueries.shift();
248
- client.clientState.queries = queries.filter(q => q !== oldestData);
249
- return client;
250
- }
251
- return undefined;
252
- };
253
-
254
- function _extends() {
255
- _extends = Object.assign ? Object.assign.bind() : function (target) {
256
- for (var i = 1; i < arguments.length; i++) {
257
- var source = arguments[i];
258
- for (var key in source) {
259
- if (Object.prototype.hasOwnProperty.call(source, key)) {
260
- target[key] = source[key];
261
- }
262
- }
263
- }
264
- return target;
265
- };
266
- return _extends.apply(this, arguments);
267
- }
268
-
269
- const PersistQueryClientProvider = ({
270
- client,
271
- children,
272
- persistOptions,
273
- onSuccess,
274
- ...props
275
- }) => {
276
- const [isRestoring, setIsRestoring] = React__namespace.useState(true);
277
- const refs = React__namespace.useRef({
278
- persistOptions,
279
- onSuccess
280
- });
281
- React__namespace.useEffect(() => {
282
- refs.current = {
283
- persistOptions,
284
- onSuccess
285
- };
286
- });
287
- React__namespace.useEffect(() => {
288
- let isStale = false;
289
- setIsRestoring(true);
290
- const [unsubscribe, promise] = persistQueryClient({
291
- ...refs.current.persistOptions,
292
- queryClient: client
293
- });
294
- promise.then(() => {
295
- if (!isStale) {
296
- refs.current.onSuccess?.();
297
- setIsRestoring(false);
298
- }
299
- });
300
- return () => {
301
- isStale = true;
302
- unsubscribe();
303
- };
304
- }, [client]);
305
- return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _extends({
306
- client: client
307
- }, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
308
- value: isRestoring
309
- }, children));
310
- };
311
-
312
- exports.PersistQueryClientProvider = PersistQueryClientProvider;
313
- exports.persistQueryClient = persistQueryClient;
314
- exports.persistQueryClientRestore = persistQueryClientRestore;
315
- exports.persistQueryClientSave = persistQueryClientSave;
316
- exports.persistQueryClientSubscribe = persistQueryClientSubscribe;
317
- exports.removeOldestQuery = removeOldestQuery;
318
-
319
- }));
320
- //# sourceMappingURL=index.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.development.js","sources":["../../../query-core/build/lib/hydration.mjs","../../../query-persist-client-core/build/lib/persist.mjs","../../../query-persist-client-core/build/lib/retryStrategies.mjs","../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["// TYPES\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state\n };\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query) {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash\n };\n}\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === 'success';\n}\nfunction dehydrate(client, options = {}) {\n const mutations = [];\n const queries = [];\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;\n client.getMutationCache().getAll().forEach(mutation => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation));\n }\n });\n }\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;\n client.getQueryCache().getAll().forEach(query => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query));\n }\n });\n }\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return;\n }\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = dehydratedState.mutations || [];\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = dehydratedState.queries || [];\n mutations.forEach(dehydratedMutation => {\n mutationCache.build(client, {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey\n }, dehydratedMutation.state);\n });\n queries.forEach(dehydratedQuery => {\n const query = queryCache.get(dehydratedQuery.queryHash);\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle'\n };\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState);\n }\n return;\n }\n\n // Restore query\n queryCache.build(client, {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash\n }, dehydratedQueryState);\n });\n}\n\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };\n//# sourceMappingURL=hydration.mjs.map\n","import { hydrate, dehydrate } from '@tanstack/query-core';\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheableEventTypes = ['added', 'removed', 'updated'];\nfunction isCacheableEventType(eventType) {\n return cacheableEventTypes.includes(eventType);\n}\n\n/**\n * Restores persisted data to the QueryCache\n * - data obtained from persister.restoreClient\n * - data is hydrated using hydrateOptions\n * If data is expired, busted, empty, or throws, it runs persister.removeClient\n */\nasync function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions\n}) {\n try {\n const persistedClient = await persister.restoreClient();\n if (persistedClient) {\n if (persistedClient.timestamp) {\n const expired = Date.now() - persistedClient.timestamp > maxAge;\n const busted = persistedClient.buster !== buster;\n if (expired || busted) {\n persister.removeClient();\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions);\n }\n } else {\n persister.removeClient();\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(err);\n console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');\n }\n persister.removeClient();\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nasync function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions\n}) {\n const persistClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions)\n };\n await persister.persistClient(persistClient);\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nfunction persistQueryClientSubscribe(props) {\n const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n return () => {\n unsubscribeQueryCache();\n unusbscribeMutationCache();\n };\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nfunction persistQueryClient(props) {\n let hasUnsubscribed = false;\n let persistQueryClientUnsubscribe;\n const unsubscribe = () => {\n hasUnsubscribed = true;\n persistQueryClientUnsubscribe?.();\n };\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);\n }\n });\n return [unsubscribe, restorePromise];\n}\n\nexport { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };\n//# sourceMappingURL=persist.mjs.map\n","const removeOldestQuery = ({\n persistedClient\n}) => {\n const mutations = [...persistedClient.clientState.mutations];\n const queries = [...persistedClient.clientState.queries];\n const client = {\n ...persistedClient,\n clientState: {\n mutations,\n queries\n }\n };\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift();\n client.clientState.queries = queries.filter(q => q !== oldestData);\n return client;\n }\n return undefined;\n};\n\nexport { removeOldestQuery };\n//# sourceMappingURL=retryStrategies.mjs.map\n","'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","IsRestoringProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;EAAA;AACA;EACA;AACA;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;AACD;EACA;EACA;EACA;EACA;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;EACD,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;EACrB,EAAE,IAAI,OAAO,CAAC,kBAAkB,KAAK,KAAK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uB,CACrD,CAAA;EAE1B;;;;;;;;;;;;;"}
@@ -1,2 +0,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){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=n(t);function i(e){return e.state.isPaused}function u(e){return"success"===e.state.status}function a(e,t={}){const r=[],n=[];if(!1!==t.dehydrateMutations){const n=t.shouldDehydrateMutation||i;e.getMutationCache().getAll().forEach((e=>{n(e)&&r.push(function(e){return{mutationKey:e.options.mutationKey,state:e.state}}(e))}))}if(!1!==t.dehydrateQueries){const r=t.shouldDehydrateQuery||u;e.getQueryCache().getAll().forEach((e=>{r(e)&&n.push(function(e){return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash}}(e))}))}return{mutations:r,queries:n}}const o=["added","removed","updated"];function c(e){return o.includes(e)}async function l({queryClient:e,persister:t,maxAge:r=864e5,buster:n="",hydrateOptions:s}){try{const i=await t.restoreClient();if(i)if(i.timestamp){const u=Date.now()-i.timestamp>r,a=i.buster!==n;u||a?t.removeClient():function(e,t,r){if("object"!=typeof t||null===t)return;const n=e.getMutationCache(),s=e.getQueryCache(),i=t.mutations||[],u=t.queries||[];i.forEach((t=>{n.build(e,{...r?.defaultOptions?.mutations,mutationKey:t.mutationKey},t.state)})),u.forEach((t=>{const n=s.get(t.queryHash),i={...t.state,fetchStatus:"idle"};n?n.state.dataUpdatedAt<i.dataUpdatedAt&&n.setState(i):s.build(e,{...r?.defaultOptions?.queries,queryKey:t.queryKey,queryHash:t.queryHash},i)}))}(e,i.clientState,s)}else t.removeClient()}catch(e){t.removeClient()}}async function y({queryClient:e,persister:t,buster:r="",dehydrateOptions:n}){const s={buster:r,timestamp:Date.now(),clientState:a(e,n)};await t.persistClient(s)}function f(e){const t=e.queryClient.getQueryCache().subscribe((t=>{c(t.type)&&y(e)})),r=e.queryClient.getMutationCache().subscribe((t=>{c(t.type)&&y(e)}));return()=>{t(),r()}}function d(e){let t,r=!1;return[()=>{r=!0,t?.()},l(e).then((()=>{r||(t=f(e))}))]}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},p.apply(this,arguments)}e.PersistQueryClientProvider=({client:e,children:t,persistOptions:n,onSuccess:i,...u})=>{const[a,o]=s.useState(!0),c=s.useRef({persistOptions:n,onSuccess:i});return s.useEffect((()=>{c.current={persistOptions:n,onSuccess:i}})),s.useEffect((()=>{let t=!1;o(!0);const[r,n]=d({...c.current.persistOptions,queryClient:e});return n.then((()=>{t||(c.current.onSuccess?.(),o(!1))})),()=>{t=!0,r()}}),[e]),s.createElement(r.QueryClientProvider,p({client:e},u),s.createElement(r.IsRestoringProvider,{value:a},t))},e.persistQueryClient=d,e.persistQueryClientRestore=l,e.persistQueryClientSave=y,e.persistQueryClientSubscribe=f,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],r=[...e.clientState.queries],n={...e,clientState:{mutations:t,queries:r}},s=[...r].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(s.length>0){const e=s.shift();return n.clientState.queries=r.filter((t=>t!==e)),n}}}));
2
- //# sourceMappingURL=index.production.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.production.js","sources":["../../../query-core/build/lib/hydration.mjs","../../../query-persist-client-core/build/lib/persist.mjs","../../src/PersistQueryClientProvider.tsx","../../../query-persist-client-core/build/lib/retryStrategies.mjs"],"sourcesContent":["// TYPES\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state\n };\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query) {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash\n };\n}\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === 'success';\n}\nfunction dehydrate(client, options = {}) {\n const mutations = [];\n const queries = [];\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;\n client.getMutationCache().getAll().forEach(mutation => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation));\n }\n });\n }\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;\n client.getQueryCache().getAll().forEach(query => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query));\n }\n });\n }\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return;\n }\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = dehydratedState.mutations || [];\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = dehydratedState.queries || [];\n mutations.forEach(dehydratedMutation => {\n mutationCache.build(client, {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey\n }, dehydratedMutation.state);\n });\n queries.forEach(dehydratedQuery => {\n const query = queryCache.get(dehydratedQuery.queryHash);\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle'\n };\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState);\n }\n return;\n }\n\n // Restore query\n queryCache.build(client, {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash\n }, dehydratedQueryState);\n });\n}\n\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };\n//# sourceMappingURL=hydration.mjs.map\n","import { hydrate, dehydrate } from '@tanstack/query-core';\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheableEventTypes = ['added', 'removed', 'updated'];\nfunction isCacheableEventType(eventType) {\n return cacheableEventTypes.includes(eventType);\n}\n\n/**\n * Restores persisted data to the QueryCache\n * - data obtained from persister.restoreClient\n * - data is hydrated using hydrateOptions\n * If data is expired, busted, empty, or throws, it runs persister.removeClient\n */\nasync function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions\n}) {\n try {\n const persistedClient = await persister.restoreClient();\n if (persistedClient) {\n if (persistedClient.timestamp) {\n const expired = Date.now() - persistedClient.timestamp > maxAge;\n const busted = persistedClient.buster !== buster;\n if (expired || busted) {\n persister.removeClient();\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions);\n }\n } else {\n persister.removeClient();\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(err);\n console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');\n }\n persister.removeClient();\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nasync function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions\n}) {\n const persistClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions)\n };\n await persister.persistClient(persistClient);\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nfunction persistQueryClientSubscribe(props) {\n const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n return () => {\n unsubscribeQueryCache();\n unusbscribeMutationCache();\n };\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nfunction persistQueryClient(props) {\n let hasUnsubscribed = false;\n let persistQueryClientUnsubscribe;\n const unsubscribe = () => {\n hasUnsubscribed = true;\n persistQueryClientUnsubscribe?.();\n };\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);\n }\n });\n return [unsubscribe, restorePromise];\n}\n\nexport { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };\n//# sourceMappingURL=persist.mjs.map\n","'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n","const removeOldestQuery = ({\n persistedClient\n}) => {\n const mutations = [...persistedClient.clientState.mutations];\n const queries = [...persistedClient.clientState.queries];\n const client = {\n ...persistedClient,\n clientState: {\n mutations,\n queries\n }\n };\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift();\n client.clientState.queries = queries.filter(q => q !== oldestData);\n return client;\n }\n return undefined;\n};\n\nexport { removeOldestQuery };\n//# sourceMappingURL=retryStrategies.mjs.map\n"],"names":["defaultShouldDehydrateMutation","mutation","state","isPaused","defaultShouldDehydrateQuery","query","status","dehydrate","client","options","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","mutationKey","dehydrateMutation","dehydrateQueries","shouldDehydrateQuery","getQueryCache","queryKey","queryHash","dehydrateQuery","cacheableEventTypes","isCacheableEventType","eventType","includes","async","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","dehydratedState","mutationCache","queryCache","dehydratedMutation","build","defaultOptions","dehydratedQuery","get","dehydratedQueryState","fetchStatus","dataUpdatedAt","setState","hydrate","clientState","err","persistQueryClientSave","dehydrateOptions","persistClient","persistQueryClientSubscribe","props","unsubscribeQueryCache","subscribe","event","type","unusbscribeMutationCache","persistQueryClient","persistQueryClientUnsubscribe","hasUnsubscribed","then","children","persistOptions","onSuccess","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","QueryClientProvider","_extends","createElement","IsRestoringProvider","value","sortedQueries","sort","a","b","length","oldestData","shift","filter","q"],"mappings":"wnBAsBA,SAASA,EAA+BC,GACtC,OAAOA,EAASC,MAAMC,SAExB,SAASC,EAA4BC,GACnC,MAA8B,YAAvBA,EAAMH,MAAMI,OAErB,SAASC,EAAUC,EAAQC,EAAU,IACnC,MAAMC,EAAY,GACZC,EAAU,GAChB,IAAmC,IAA/BF,EAAQG,mBAA8B,CACxC,MAAMC,EAA0BJ,EAAQI,yBAA2Bb,EACnEQ,EAAOM,mBAAmBC,SAASC,SAAQf,IACrCY,EAAwBZ,IAC1BS,EAAUO,KA/BlB,SAA2BhB,GACzB,MAAO,CACLiB,YAAajB,EAASQ,QAAQS,YAC9BhB,MAAOD,EAASC,OA4BGiB,CAAkBlB,OAIvC,IAAiC,IAA7BQ,EAAQW,iBAA4B,CACtC,MAAMC,EAAuBZ,EAAQY,sBAAwBjB,EAC7DI,EAAOc,gBAAgBP,SAASC,SAAQX,IAClCgB,EAAqBhB,IACvBM,EAAQM,KA5BhB,SAAwBZ,GACtB,MAAO,CACLH,MAAOG,EAAMH,MACbqB,SAAUlB,EAAMkB,SAChBC,UAAWnB,EAAMmB,WAwBAC,CAAepB,OAIlC,MAAO,CACLK,YACAC,WC3CJ,MAAMe,EAAsB,CAAC,QAAS,UAAW,WACjD,SAASC,EAAqBC,GAC5B,OAAOF,EAAoBG,SAASD,GAStCE,eAAeC,GAA0BC,YACvCA,EAAWC,UACXA,EAASC,OACTA,EAAS,MAAmBC,OAC5BA,EAAS,GAAEC,eACXA,IAEA,IACE,MAAMC,QAAwBJ,EAAUK,gBACxC,GAAID,EACF,GAAIA,EAAgBE,UAAW,CAC7B,MAAMC,EAAUC,KAAKC,MAAQL,EAAgBE,UAAYL,EACnDS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