@tanstack/react-query-persist-client 5.0.0-alpha.71 → 5.0.0-alpha.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/PersistQueryClientProvider.cjs.map +1 -1
- package/build/lib/PersistQueryClientProvider.d.ts.map +1 -1
- package/build/lib/PersistQueryClientProvider.js.map +1 -1
- package/build/lib/PersistQueryClientProvider.legacy.cjs.map +1 -1
- package/build/lib/PersistQueryClientProvider.legacy.js.map +1 -1
- package/build/lib/__tests__/utils.d.ts +1 -1
- package/build/lib/__tests__/utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/PersistQueryClientProvider.tsx +2 -2
- package/src/__tests__/PersistQueryClientProvider.test.tsx +10 -13
- package/src/__tests__/utils.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.cjs","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.cjs","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?: () => 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 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.d.ts","sourceRoot":"","sources":["../../src/PersistQueryClientProvider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.d.ts","sourceRoot":"","sources":["../../src/PersistQueryClientProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AACpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAErE,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { 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?: () => 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 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.legacy.cjs","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.legacy.cjs","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?: () => 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 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.legacy.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport
|
|
1
|
+
{"version":3,"file":"PersistQueryClientProvider.legacy.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?: () => 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,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { QueryClientConfig } from '@tanstack/react-query';
|
|
3
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import type { QueryClientConfig } 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>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils.ts"],"names":[],"mappings":";AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAE9D,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query-persist-client",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.84",
|
|
4
4
|
"description": "React bindings to work with persisters in TanStack/react-query",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"src"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tanstack/query-persist-client-core": "5.0.0-alpha.
|
|
32
|
+
"@tanstack/query-persist-client-core": "5.0.0-alpha.84"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/react": "^18.2.4",
|
|
36
36
|
"@types/react-dom": "^18.2.4",
|
|
37
37
|
"react": "^18.2.0",
|
|
38
38
|
"react-dom": "^18.2.0",
|
|
39
|
-
"@tanstack/react-query": "5.0.0-alpha.
|
|
39
|
+
"@tanstack/react-query": "5.0.0-alpha.84"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@tanstack/react-query": "5.0.0-alpha.
|
|
42
|
+
"@tanstack/react-query": "5.0.0-alpha.84"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"clean": "rimraf ./build && rimraf ./coverage",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
|
|
5
4
|
import { persistQueryClient } from '@tanstack/query-persist-client-core'
|
|
5
|
+
import { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'
|
|
6
|
+
import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
|
|
6
7
|
import type { QueryClientProviderProps } from '@tanstack/react-query'
|
|
7
|
-
import { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'
|
|
8
8
|
|
|
9
9
|
export type PersistQueryClientProviderProps = QueryClientProviderProps & {
|
|
10
10
|
persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>
|
|
@@ -2,19 +2,19 @@ import * as React from 'react'
|
|
|
2
2
|
import { render, waitFor } from '@testing-library/react'
|
|
3
3
|
import { vi } from 'vitest'
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '
|
|
9
|
-
import {
|
|
5
|
+
import { QueryClient, useQueries, useQuery } from '@tanstack/react-query'
|
|
6
|
+
import { persistQueryClientSave } from '@tanstack/query-persist-client-core'
|
|
7
|
+
|
|
8
|
+
import { PersistQueryClientProvider } from '../PersistQueryClientProvider'
|
|
9
|
+
import { createQueryClient, queryKey, sleep } from './utils'
|
|
10
10
|
import type {
|
|
11
11
|
PersistedClient,
|
|
12
12
|
Persister,
|
|
13
13
|
} from '@tanstack/query-persist-client-core'
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
import type {
|
|
15
|
+
DefinedUseQueryResult,
|
|
16
|
+
UseQueryResult,
|
|
17
|
+
} from '@tanstack/react-query'
|
|
18
18
|
|
|
19
19
|
const createMockPersister = (): Persister => {
|
|
20
20
|
let storedState: PersistedClient | undefined
|
|
@@ -339,7 +339,7 @@ describe('PersistQueryClientProvider', () => {
|
|
|
339
339
|
await waitFor(() => rendered.getByText('data: null'))
|
|
340
340
|
await waitFor(() => rendered.getByText('data: hydrated'))
|
|
341
341
|
|
|
342
|
-
expect(states).toHaveLength(
|
|
342
|
+
expect(states).toHaveLength(2)
|
|
343
343
|
|
|
344
344
|
expect(fetched).toBe(false)
|
|
345
345
|
|
|
@@ -354,9 +354,6 @@ describe('PersistQueryClientProvider', () => {
|
|
|
354
354
|
fetchStatus: 'idle',
|
|
355
355
|
data: 'hydrated',
|
|
356
356
|
})
|
|
357
|
-
|
|
358
|
-
// #5443 seems like we get an extra render now ...
|
|
359
|
-
expect(states[1]).toStrictEqual(states[2])
|
|
360
357
|
})
|
|
361
358
|
|
|
362
359
|
test('should call onSuccess after successful restoring', async () => {
|
package/src/__tests__/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { act } from '@testing-library/react'
|
|
2
2
|
|
|
3
|
-
import type { QueryClientConfig } from '@tanstack/react-query'
|
|
4
3
|
import { QueryClient } from '@tanstack/react-query'
|
|
4
|
+
import type { QueryClientConfig } from '@tanstack/react-query'
|
|
5
5
|
|
|
6
6
|
export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
7
7
|
return new QueryClient(config)
|