snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
543
packages/react-query-persist-client/CHANGELOG.md
Normal file
543
packages/react-query-persist-client/CHANGELOG.md
Normal file
@@ -0,0 +1,543 @@
|
||||
# @tanstack/react-query-persist-client
|
||||
|
||||
## 5.102.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.102.8
|
||||
- @tanstack/react-query@5.102.8
|
||||
|
||||
## 5.102.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.102.7
|
||||
- @tanstack/react-query@5.102.7
|
||||
|
||||
## 5.102.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`ac2b612`](https://github.com/TanStack/query/commit/ac2b61230ea35b90b177ba35dc030598bac9c9a6)]:
|
||||
- @tanstack/react-query@5.102.6
|
||||
- @tanstack/query-persist-client-core@5.102.6
|
||||
|
||||
## 5.102.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.102.5
|
||||
- @tanstack/react-query@5.102.5
|
||||
|
||||
## 5.102.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.102.4
|
||||
- @tanstack/react-query@5.102.4
|
||||
|
||||
## 5.102.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.102.3
|
||||
- @tanstack/react-query@5.102.3
|
||||
|
||||
## 5.102.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.102.2
|
||||
- @tanstack/react-query@5.102.2
|
||||
|
||||
## 5.102.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.102.1
|
||||
- @tanstack/react-query@5.102.1
|
||||
|
||||
## 5.102.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`37127db`](https://github.com/TanStack/query/commit/37127dbe479a4892dbbe28ac8ceabf8832b5f1a3), [`6e3d521`](https://github.com/TanStack/query/commit/6e3d521fe54f78624e53c1c6f9cadd678504bee8), [`294d4e6`](https://github.com/TanStack/query/commit/294d4e62c4f7d674574a4903eef2a1bc3dd1413b), [`cb6c9d3`](https://github.com/TanStack/query/commit/cb6c9d3725db0fed94fb5133820e41b7c326d2ef), [`2215bb0`](https://github.com/TanStack/query/commit/2215bb031139cdc8a84751b37a485c38ca9d2b6e), [`1ef4208`](https://github.com/TanStack/query/commit/1ef42087c9a266c2137d2ef645cbcc662f60ac93), [`fb6c3fa`](https://github.com/TanStack/query/commit/fb6c3fabda4cb6b291cccc6651ed88a7db901915), [`8834267`](https://github.com/TanStack/query/commit/88342670eca6e4949416aab832b1f81cc7b881f8), [`b866a95`](https://github.com/TanStack/query/commit/b866a95adde7e8465462526df5870ebc12340b36), [`e546d03`](https://github.com/TanStack/query/commit/e546d03bef116c66a05dbf42ccfd70b6d8600a8f), [`e674826`](https://github.com/TanStack/query/commit/e6748265c86294704f6c872e6f435d9ec5a92b28)]:
|
||||
- @tanstack/react-query@5.102.0
|
||||
- @tanstack/query-persist-client-core@5.102.0
|
||||
|
||||
## 5.101.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.101.4
|
||||
- @tanstack/react-query@5.101.4
|
||||
|
||||
## 5.101.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.101.3
|
||||
- @tanstack/react-query@5.101.3
|
||||
|
||||
## 5.101.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.101.2
|
||||
- @tanstack/react-query@5.101.2
|
||||
|
||||
## 5.101.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.101.1
|
||||
- @tanstack/react-query@5.101.1
|
||||
|
||||
## 5.101.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.101.0
|
||||
- @tanstack/react-query@5.101.0
|
||||
|
||||
## 5.100.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`ed20b6d`](https://github.com/TanStack/query/commit/ed20b6d7541c908033acfcad92b0cd112930d1c3)]:
|
||||
- @tanstack/react-query@5.100.14
|
||||
- @tanstack/query-persist-client-core@5.100.14
|
||||
|
||||
## 5.100.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.13
|
||||
- @tanstack/react-query@5.100.13
|
||||
|
||||
## 5.100.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.12
|
||||
- @tanstack/react-query@5.100.12
|
||||
|
||||
## 5.100.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.11
|
||||
- @tanstack/react-query@5.100.11
|
||||
|
||||
## 5.100.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.10
|
||||
- @tanstack/react-query@5.100.10
|
||||
|
||||
## 5.100.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.9
|
||||
- @tanstack/react-query@5.100.9
|
||||
|
||||
## 5.100.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.8
|
||||
- @tanstack/react-query@5.100.8
|
||||
|
||||
## 5.100.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.7
|
||||
- @tanstack/react-query@5.100.7
|
||||
|
||||
## 5.100.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.6
|
||||
- @tanstack/react-query@5.100.6
|
||||
|
||||
## 5.100.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.5
|
||||
- @tanstack/react-query@5.100.5
|
||||
|
||||
## 5.100.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.4
|
||||
- @tanstack/react-query@5.100.4
|
||||
|
||||
## 5.100.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`f85d825`](https://github.com/TanStack/query/commit/f85d825e02efbbff02e2081528ed28f5e5382f7a)]:
|
||||
- @tanstack/react-query@5.100.3
|
||||
- @tanstack/query-persist-client-core@5.100.3
|
||||
|
||||
## 5.100.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.2
|
||||
- @tanstack/react-query@5.100.2
|
||||
|
||||
## 5.100.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.1
|
||||
- @tanstack/react-query@5.100.1
|
||||
|
||||
## 5.100.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.100.0
|
||||
- @tanstack/react-query@5.100.0
|
||||
|
||||
## 5.99.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.99.2
|
||||
- @tanstack/react-query@5.99.2
|
||||
|
||||
## 5.99.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.99.1
|
||||
- @tanstack/react-query@5.99.1
|
||||
|
||||
## 5.99.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.99.0
|
||||
- @tanstack/react-query@5.99.0
|
||||
|
||||
## 5.98.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.98.0
|
||||
- @tanstack/react-query@5.98.0
|
||||
|
||||
## 5.97.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.97.0
|
||||
- @tanstack/react-query@5.97.0
|
||||
|
||||
## 5.96.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.96.2
|
||||
- @tanstack/react-query@5.96.2
|
||||
|
||||
## 5.96.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.96.1
|
||||
- @tanstack/react-query@5.96.1
|
||||
|
||||
## 5.96.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.96.0
|
||||
- @tanstack/react-query@5.96.0
|
||||
|
||||
## 5.95.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.95.2
|
||||
- @tanstack/react-query@5.95.2
|
||||
|
||||
## 5.95.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.95.1
|
||||
- @tanstack/react-query@5.95.1
|
||||
|
||||
## 5.95.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.95.0
|
||||
- @tanstack/react-query@5.95.0
|
||||
|
||||
## 5.94.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- fix(\*): resolve issue about excluded build directory ([#10312](https://github.com/TanStack/query/pull/10312))
|
||||
|
||||
- Updated dependencies [[`4b6536d`](https://github.com/TanStack/query/commit/4b6536dfce99036f4e37f52943c6fed3ad0e0a18)]:
|
||||
- @tanstack/query-persist-client-core@5.94.5
|
||||
- @tanstack/react-query@5.94.5
|
||||
|
||||
## 5.94.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- chore: fixed version ([#10064](https://github.com/TanStack/query/pull/10064))
|
||||
|
||||
- Updated dependencies [[`4c75210`](https://github.com/TanStack/query/commit/4c75210ce8235fe3d39b67e1029eff11278927cc)]:
|
||||
- @tanstack/query-persist-client-core@5.94.4
|
||||
- @tanstack/react-query@5.94.4
|
||||
|
||||
## 5.90.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- fix(streamedQuery): maintain error state on reset refetch with initialData defined ([#10287](https://github.com/TanStack/query/pull/10287))
|
||||
|
||||
- Updated dependencies [[`248975e`](https://github.com/TanStack/query/commit/248975e896f585f6eaa505c796e73fcf7bfd1eec)]:
|
||||
- @tanstack/query-persist-client-core@5.92.4
|
||||
- @tanstack/react-query@5.91.2
|
||||
|
||||
## 5.90.26
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a89aab9`](https://github.com/TanStack/query/commit/a89aab975581c25c113a26c8af486b4cafad272a)]:
|
||||
- @tanstack/react-query@5.91.1
|
||||
- @tanstack/query-persist-client-core@5.92.3
|
||||
|
||||
## 5.90.25
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`6fa901b`](https://github.com/TanStack/query/commit/6fa901b97a22a80d0fca3f6ed86237ff0cbdd13b)]:
|
||||
- @tanstack/react-query@5.91.0
|
||||
- @tanstack/query-persist-client-core@5.92.2
|
||||
|
||||
## 5.90.24
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`e505568`](https://github.com/TanStack/query/commit/e505568f4d51c8281d38e9687091094b7d32a405)]:
|
||||
- @tanstack/query-persist-client-core@5.92.1
|
||||
- @tanstack/react-query@5.90.21
|
||||
|
||||
## 5.90.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`978fc52`](https://github.com/TanStack/query/commit/978fc52728a8b9eb33f0a82f4ddf42a95815bd7f)]:
|
||||
- @tanstack/query-persist-client-core@5.92.0
|
||||
- @tanstack/react-query@5.90.21
|
||||
|
||||
## 5.90.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.19
|
||||
- @tanstack/react-query@5.90.20
|
||||
|
||||
## 5.90.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.18
|
||||
- @tanstack/react-query@5.90.19
|
||||
|
||||
## 5.90.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.17
|
||||
- @tanstack/react-query@5.90.18
|
||||
|
||||
## 5.90.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.16
|
||||
- @tanstack/react-query@5.90.17
|
||||
|
||||
## 5.90.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`4be3ad7`](https://github.com/TanStack/query/commit/4be3ad730c5b8a1e194a91911746be2fce06902a)]:
|
||||
- @tanstack/react-query@5.90.16
|
||||
- @tanstack/query-persist-client-core@5.91.15
|
||||
|
||||
## 5.90.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.14
|
||||
- @tanstack/react-query@5.90.15
|
||||
|
||||
## 5.90.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.13
|
||||
- @tanstack/react-query@5.90.14
|
||||
|
||||
## 5.90.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.12
|
||||
- @tanstack/react-query@5.90.13
|
||||
|
||||
## 5.90.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.11
|
||||
- @tanstack/react-query@5.90.12
|
||||
|
||||
## 5.90.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`c01b150`](https://github.com/TanStack/query/commit/c01b150e3673e11d6533768529a5e6fe3ebee68c)]:
|
||||
- @tanstack/react-query@5.90.11
|
||||
- @tanstack/query-persist-client-core@5.91.10
|
||||
|
||||
## 5.90.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.9
|
||||
- @tanstack/react-query@5.90.10
|
||||
|
||||
## 5.90.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.8
|
||||
- @tanstack/react-query@5.90.9
|
||||
|
||||
## 5.90.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.7
|
||||
- @tanstack/react-query@5.90.8
|
||||
|
||||
## 5.90.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.6
|
||||
- @tanstack/react-query@5.90.7
|
||||
|
||||
## 5.90.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.5
|
||||
- @tanstack/react-query@5.90.6
|
||||
|
||||
## 5.90.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.4
|
||||
- @tanstack/react-query@5.90.5
|
||||
|
||||
## 5.90.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @tanstack/query-persist-client-core@5.91.3
|
||||
- @tanstack/react-query@5.90.4
|
||||
|
||||
## 5.90.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`4e1c433`](https://github.com/TanStack/query/commit/4e1c4338a72f7384600bbda99e44bc1891695df4)]:
|
||||
- @tanstack/react-query@5.90.3
|
||||
- @tanstack/query-persist-client-core@5.91.2
|
||||
|
||||
## 5.90.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`846d53d`](https://github.com/TanStack/query/commit/846d53d98992d50606c40634efa43dea9965b787)]:
|
||||
- @tanstack/query-persist-client-core@5.91.1
|
||||
- @tanstack/react-query@5.90.2
|
||||
|
||||
## 5.90.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`5cd86c6`](https://github.com/TanStack/query/commit/5cd86c6ef1720b87b13e1ab70ee823616f1f029a)]:
|
||||
- @tanstack/query-persist-client-core@5.91.0
|
||||
- @tanstack/react-query@5.90.2
|
||||
22
packages/react-query-persist-client/eslint.config.js
Normal file
22
packages/react-query-persist-client/eslint.config.js
Normal file
@@ -0,0 +1,22 @@
|
||||
// @ts-check
|
||||
|
||||
import pluginReact from '@eslint-react/eslint-plugin'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import rootConfig from './root.eslint.config.js'
|
||||
|
||||
export default [
|
||||
...rootConfig,
|
||||
// @ts-expect-error wtf
|
||||
...reactHooks.configs['recommended-latest'],
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
...pluginReact.configs.recommended,
|
||||
rules: {
|
||||
'@eslint-react/no-context-provider': 'off', // We need to be React 18 compatible
|
||||
'react-hooks/exhaustive-deps': 'error',
|
||||
'react-hooks/rules-of-hooks': 'error',
|
||||
'react-hooks/unsupported-syntax': 'error',
|
||||
'react-hooks/incompatible-library': 'error',
|
||||
},
|
||||
},
|
||||
]
|
||||
74
packages/react-query-persist-client/package.json
Normal file
74
packages/react-query-persist-client/package.json
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"name": "@tanstack/react-query-persist-client",
|
||||
"version": "5.102.8",
|
||||
"description": "React bindings to work with persisters in TanStack/react-query",
|
||||
"author": "tannerlinsley",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/TanStack/query.git",
|
||||
"directory": "packages/react-query-persist-client"
|
||||
},
|
||||
"homepage": "https://tanstack.com/query",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/tannerlinsley"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
|
||||
"compile": "tsc --project tsconfig.json",
|
||||
"test:eslint": "eslint --concurrency=auto ./src",
|
||||
"test:types": "npm-run-all --serial test:types:*",
|
||||
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
|
||||
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
|
||||
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
|
||||
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
|
||||
"test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
|
||||
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
|
||||
"test:lib": "vitest --retry=3",
|
||||
"test:lib:dev": "pnpm run test:lib --watch",
|
||||
"test:build": "publint --strict && attw --pack",
|
||||
"build": "tsdown --tsconfig tsconfig.prod.json"
|
||||
},
|
||||
"type": "module",
|
||||
"types": "build/legacy/index.d.ts",
|
||||
"main": "build/legacy/index.cjs",
|
||||
"module": "build/legacy/index.js",
|
||||
"react-native": "src/index.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"@tanstack/custom-condition": "./src/index.ts",
|
||||
"import": {
|
||||
"types": "./build/modern/index.d.ts",
|
||||
"default": "./build/modern/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./build/modern/index.d.cts",
|
||||
"default": "./build/modern/index.cjs"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"files": [
|
||||
"build",
|
||||
"src",
|
||||
"!src/__tests__"
|
||||
],
|
||||
"dependencies": {
|
||||
"@tanstack/query-persist-client-core": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tanstack/query-test-utils": "workspace:*",
|
||||
"@tanstack/react-query": "workspace:*",
|
||||
"@testing-library/react": "^16.1.0",
|
||||
"@types/react": "^19.2.7",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"npm-run-all2": "^5.0.0",
|
||||
"react": "^19.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@tanstack/react-query": "workspace:^",
|
||||
"react": "^18 || ^19"
|
||||
}
|
||||
}
|
||||
1
packages/react-query-persist-client/root.eslint.config.js
Symbolic link
1
packages/react-query-persist-client/root.eslint.config.js
Symbolic link
@@ -0,0 +1 @@
|
||||
../../eslint.config.js
|
||||
1
packages/react-query-persist-client/root.tsdown.config.js
Symbolic link
1
packages/react-query-persist-client/root.tsdown.config.js
Symbolic link
@@ -0,0 +1 @@
|
||||
../../scripts/getTsdownConfig.js
|
||||
@@ -0,0 +1,55 @@
|
||||
'use client'
|
||||
import * as React from 'react'
|
||||
|
||||
import {
|
||||
persistQueryClientRestore,
|
||||
persistQueryClientSubscribe,
|
||||
} from '@tanstack/query-persist-client-core'
|
||||
import { IsRestoringProvider, QueryClientProvider } from '@tanstack/react-query'
|
||||
import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
|
||||
import type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'
|
||||
|
||||
export type PersistQueryClientProviderProps = QueryClientProviderProps & {
|
||||
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
|
||||
onSuccess?: () => Promise<unknown> | unknown
|
||||
onError?: () => Promise<unknown> | unknown
|
||||
}
|
||||
|
||||
export const PersistQueryClientProvider = ({
|
||||
children,
|
||||
persistOptions,
|
||||
onSuccess,
|
||||
onError,
|
||||
...props
|
||||
}: PersistQueryClientProviderProps): React.JSX.Element => {
|
||||
const [isRestoring, setIsRestoring] = React.useState(true)
|
||||
const refs = React.useRef({ persistOptions, onSuccess, onError })
|
||||
const didRestore = React.useRef(false)
|
||||
|
||||
React.useEffect(() => {
|
||||
refs.current = { persistOptions, onSuccess, onError }
|
||||
})
|
||||
|
||||
React.useEffect(() => {
|
||||
const options = {
|
||||
...refs.current.persistOptions,
|
||||
queryClient: props.client,
|
||||
}
|
||||
if (!didRestore.current) {
|
||||
didRestore.current = true
|
||||
persistQueryClientRestore(options)
|
||||
.then(() => refs.current.onSuccess?.())
|
||||
.catch(() => refs.current.onError?.())
|
||||
.finally(() => {
|
||||
setIsRestoring(false)
|
||||
})
|
||||
}
|
||||
return isRestoring ? undefined : persistQueryClientSubscribe(options)
|
||||
}, [props.client, isRestoring])
|
||||
|
||||
return (
|
||||
<QueryClientProvider {...props}>
|
||||
<IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,816 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import * as React from 'react'
|
||||
import { act, fireEvent, render } from '@testing-library/react'
|
||||
import { QueryClient, noop, useQueries, useQuery } from '@tanstack/react-query'
|
||||
import { persistQueryClientSave } from '@tanstack/query-persist-client-core'
|
||||
import { queryKey, sleep } from '@tanstack/query-test-utils'
|
||||
import { PersistQueryClientProvider } from '../PersistQueryClientProvider'
|
||||
import type {
|
||||
PersistedClient,
|
||||
Persister,
|
||||
} from '@tanstack/query-persist-client-core'
|
||||
import type {
|
||||
DefinedUseQueryResult,
|
||||
UseQueryResult,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
const createMockPersister = (): Persister => {
|
||||
let storedState: PersistedClient | undefined
|
||||
|
||||
return {
|
||||
persistClient(persistClient: PersistedClient) {
|
||||
storedState = persistClient
|
||||
},
|
||||
async restoreClient() {
|
||||
return sleep(10).then(() => storedState)
|
||||
},
|
||||
removeClient() {
|
||||
storedState = undefined
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const createMockErrorPersister = (
|
||||
removeClient: Persister['removeClient'],
|
||||
): [Error, Persister] => {
|
||||
const error = new Error('restore failed')
|
||||
return [
|
||||
error,
|
||||
{
|
||||
async persistClient() {
|
||||
// noop
|
||||
},
|
||||
async restoreClient() {
|
||||
await sleep(10)
|
||||
throw error
|
||||
},
|
||||
removeClient,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
describe('PersistQueryClientProvider', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('restores cache from persister', async () => {
|
||||
const key = queryKey()
|
||||
const states: Array<UseQueryResult<string>> = []
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createMockPersister()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
function Page() {
|
||||
const state = useQuery({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'fetched'),
|
||||
})
|
||||
|
||||
states.push(state)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{state.data}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>,
|
||||
)
|
||||
|
||||
expect(rendered.getByText('fetchStatus: idle')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
expect(rendered.getByText('hydrated')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('fetched')).toBeInTheDocument()
|
||||
|
||||
expect(states).toHaveLength(4)
|
||||
|
||||
expect(states[0]).toMatchObject({
|
||||
status: 'pending',
|
||||
fetchStatus: 'idle',
|
||||
data: undefined,
|
||||
})
|
||||
|
||||
expect(states[1]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'fetching',
|
||||
data: 'hydrated',
|
||||
})
|
||||
|
||||
expect(states[2]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'fetching',
|
||||
data: 'hydrated',
|
||||
})
|
||||
|
||||
expect(states[3]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'idle',
|
||||
data: 'fetched',
|
||||
})
|
||||
})
|
||||
|
||||
it('should subscribe correctly in StrictMode', async () => {
|
||||
const key = queryKey()
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createMockPersister()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
function Page() {
|
||||
const state = useQuery({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'fetched'),
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{state.data}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
<button
|
||||
onClick={() => {
|
||||
queryClient.setQueryData(key, 'updated')
|
||||
}}
|
||||
>
|
||||
update
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(
|
||||
<React.StrictMode>
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>
|
||||
,
|
||||
</React.StrictMode>,
|
||||
)
|
||||
|
||||
expect(rendered.getByText('fetchStatus: idle')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
expect(rendered.getByText('hydrated')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('fetched')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(rendered.getByRole('button', { name: /update/i }))
|
||||
await act(() => vi.advanceTimersByTimeAsync(0))
|
||||
expect(rendered.getByText('updated')).toBeInTheDocument()
|
||||
|
||||
const statePromise = persister.restoreClient()
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
const state = await statePromise
|
||||
|
||||
expect(state?.clientState.queries[0]?.state.data).toBe('updated')
|
||||
})
|
||||
|
||||
it('should also put useQueries into idle state', async () => {
|
||||
const key = queryKey()
|
||||
const states: Array<UseQueryResult> = []
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createMockPersister()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
function Page() {
|
||||
const [state] = useQueries({
|
||||
queries: [
|
||||
{
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'fetched'),
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
states.push(state)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{state.data}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>,
|
||||
)
|
||||
|
||||
expect(rendered.getByText('fetchStatus: idle')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
expect(rendered.getByText('hydrated')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('fetched')).toBeInTheDocument()
|
||||
|
||||
expect(states).toHaveLength(4)
|
||||
|
||||
expect(states[0]).toMatchObject({
|
||||
status: 'pending',
|
||||
fetchStatus: 'idle',
|
||||
data: undefined,
|
||||
})
|
||||
|
||||
expect(states[1]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'fetching',
|
||||
data: 'hydrated',
|
||||
})
|
||||
|
||||
expect(states[2]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'fetching',
|
||||
data: 'hydrated',
|
||||
})
|
||||
|
||||
expect(states[3]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'idle',
|
||||
data: 'fetched',
|
||||
})
|
||||
})
|
||||
|
||||
it('should show initialData while restoring', async () => {
|
||||
const key = queryKey()
|
||||
const states: Array<DefinedUseQueryResult<string>> = []
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createMockPersister()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
function Page() {
|
||||
const state = useQuery({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'fetched'),
|
||||
initialData: 'initial',
|
||||
// make sure that initial data is older than the hydration data
|
||||
// otherwise initialData would be newer and takes precedence
|
||||
initialDataUpdatedAt: 1,
|
||||
})
|
||||
|
||||
states.push(state)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{state.data}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>,
|
||||
)
|
||||
|
||||
expect(rendered.getByText('initial')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
expect(rendered.getByText('hydrated')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('fetched')).toBeInTheDocument()
|
||||
|
||||
expect(states).toHaveLength(4)
|
||||
|
||||
expect(states[0]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'idle',
|
||||
data: 'initial',
|
||||
})
|
||||
|
||||
expect(states[1]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'fetching',
|
||||
data: 'hydrated',
|
||||
})
|
||||
|
||||
expect(states[2]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'fetching',
|
||||
data: 'hydrated',
|
||||
})
|
||||
|
||||
expect(states[3]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'idle',
|
||||
data: 'fetched',
|
||||
})
|
||||
})
|
||||
|
||||
it('should not refetch after restoring when data is fresh', async () => {
|
||||
const key = queryKey()
|
||||
const states: Array<UseQueryResult<string>> = []
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createMockPersister()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
let fetched = false
|
||||
|
||||
function Page() {
|
||||
const state = useQuery({
|
||||
queryKey: key,
|
||||
queryFn: async () => {
|
||||
await sleep(10)
|
||||
fetched = true
|
||||
return 'fetched'
|
||||
},
|
||||
staleTime: Infinity,
|
||||
})
|
||||
|
||||
states.push(state)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>data: {state.data ?? 'null'}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>,
|
||||
)
|
||||
|
||||
expect(rendered.getByText('data: null')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
expect(rendered.getByText('data: hydrated')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('data: hydrated')).toBeInTheDocument()
|
||||
|
||||
expect(states).toHaveLength(2)
|
||||
|
||||
expect(fetched).toBe(false)
|
||||
|
||||
expect(states[0]).toMatchObject({
|
||||
status: 'pending',
|
||||
fetchStatus: 'idle',
|
||||
data: undefined,
|
||||
})
|
||||
|
||||
expect(states[1]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'idle',
|
||||
data: 'hydrated',
|
||||
})
|
||||
})
|
||||
|
||||
it('should call onSuccess after successful restoring', async () => {
|
||||
const key = queryKey()
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createMockPersister()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
function Page() {
|
||||
const state = useQuery({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'fetched'),
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{state.data}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const onSuccess = vi.fn()
|
||||
|
||||
const rendered = render(
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
onSuccess={onSuccess}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>,
|
||||
)
|
||||
|
||||
expect(onSuccess).toHaveBeenCalledTimes(0)
|
||||
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
expect(rendered.getByText('hydrated')).toBeInTheDocument()
|
||||
expect(onSuccess).toHaveBeenCalledTimes(1)
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('fetched')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should await onSuccess after successful restoring', async () => {
|
||||
const key = queryKey()
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createMockPersister()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
const states: Array<string> = []
|
||||
|
||||
function Page() {
|
||||
const { data, fetchStatus } = useQuery({
|
||||
queryKey: key,
|
||||
queryFn: async () => {
|
||||
states.push('fetching')
|
||||
await sleep(10)
|
||||
states.push('fetched')
|
||||
return 'fetched'
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{data}</h1>
|
||||
<h2>fetchStatus: {fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
onSuccess={async () => {
|
||||
states.push('onSuccess')
|
||||
await sleep(20)
|
||||
states.push('onSuccess done')
|
||||
}}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>,
|
||||
)
|
||||
|
||||
await act(() => vi.advanceTimersByTimeAsync(30))
|
||||
expect(rendered.getByText('hydrated')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('fetched')).toBeInTheDocument()
|
||||
|
||||
expect(states).toEqual([
|
||||
'onSuccess',
|
||||
'onSuccess done',
|
||||
'fetching',
|
||||
'fetched',
|
||||
])
|
||||
})
|
||||
|
||||
it('should remove cache after non-successful restoring', async () => {
|
||||
const key = queryKey()
|
||||
const consoleMock = vi.spyOn(console, 'error')
|
||||
const consoleWarn = vi
|
||||
.spyOn(console, 'warn')
|
||||
.mockImplementation(() => undefined)
|
||||
consoleMock.mockImplementation(() => undefined)
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
const removeClient = vi.fn()
|
||||
const onSuccess = vi.fn()
|
||||
const onError = vi.fn()
|
||||
|
||||
const [error, persister] = createMockErrorPersister(removeClient)
|
||||
|
||||
function Page() {
|
||||
const state = useQuery({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'fetched'),
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{state.data}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
onSuccess={onSuccess}
|
||||
onError={onError}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>,
|
||||
)
|
||||
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('fetched')).toBeInTheDocument()
|
||||
expect(removeClient).toHaveBeenCalledTimes(1)
|
||||
expect(onSuccess).toHaveBeenCalledTimes(0)
|
||||
expect(onError).toHaveBeenCalledTimes(1)
|
||||
|
||||
expect(consoleMock).toHaveBeenCalledTimes(1)
|
||||
expect(consoleMock).toHaveBeenNthCalledWith(1, error)
|
||||
consoleMock.mockRestore()
|
||||
consoleWarn.mockRestore()
|
||||
})
|
||||
|
||||
it('should be able to persist into multiple clients', async () => {
|
||||
const key = queryKey()
|
||||
const states: Array<UseQueryResult> = []
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createMockPersister()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
const onSuccess = vi.fn()
|
||||
|
||||
const queryFn1 = vi
|
||||
.fn()
|
||||
.mockImplementation(() => sleep(10).then(() => 'queryFn1'))
|
||||
const queryFn2 = vi
|
||||
.fn()
|
||||
.mockImplementation(() => sleep(10).then(() => 'queryFn2'))
|
||||
|
||||
function App() {
|
||||
const [client, setClient] = React.useState(
|
||||
() =>
|
||||
new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
queryFn: queryFn1,
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
React.useEffect(() => {
|
||||
setClient(
|
||||
new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
queryFn: queryFn2,
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<PersistQueryClientProvider
|
||||
client={client}
|
||||
persistOptions={{ persister }}
|
||||
onSuccess={onSuccess}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function Page() {
|
||||
const state = useQuery({ queryKey: key })
|
||||
|
||||
states.push(state)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{String(state.data)}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(<App />)
|
||||
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
expect(rendered.getByText('hydrated')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('queryFn2')).toBeInTheDocument()
|
||||
|
||||
expect(queryFn1).toHaveBeenCalledTimes(0)
|
||||
expect(queryFn2).toHaveBeenCalledTimes(1)
|
||||
expect(onSuccess).toHaveBeenCalledTimes(1)
|
||||
|
||||
expect(states).toHaveLength(5)
|
||||
|
||||
expect(states[0]).toMatchObject({
|
||||
status: 'pending',
|
||||
fetchStatus: 'idle',
|
||||
data: undefined,
|
||||
})
|
||||
|
||||
expect(states[1]).toMatchObject({
|
||||
status: 'pending',
|
||||
fetchStatus: 'idle',
|
||||
data: undefined,
|
||||
})
|
||||
|
||||
expect(states[2]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'fetching',
|
||||
data: 'hydrated',
|
||||
})
|
||||
|
||||
expect(states[3]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'fetching',
|
||||
data: 'hydrated',
|
||||
})
|
||||
|
||||
expect(states[4]).toMatchObject({
|
||||
status: 'success',
|
||||
fetchStatus: 'idle',
|
||||
data: 'queryFn2',
|
||||
})
|
||||
})
|
||||
|
||||
it('should only restore once in StrictMode', async () => {
|
||||
let restoreCount = 0
|
||||
const createPersister = (): Persister => {
|
||||
let storedState: PersistedClient | undefined
|
||||
|
||||
return {
|
||||
persistClient(persistClient) {
|
||||
storedState = persistClient
|
||||
},
|
||||
async restoreClient() {
|
||||
restoreCount++
|
||||
return sleep(10).then(() => storedState)
|
||||
},
|
||||
removeClient() {
|
||||
storedState = undefined
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const key = queryKey()
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
void queryClient
|
||||
.query({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'hydrated'),
|
||||
})
|
||||
.catch(noop)
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
|
||||
const persister = createPersister()
|
||||
|
||||
const onSuccess = vi.fn()
|
||||
|
||||
persistQueryClientSave({ queryClient, persister })
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
queryClient.clear()
|
||||
|
||||
function Page() {
|
||||
const state = useQuery({
|
||||
queryKey: key,
|
||||
queryFn: () => sleep(10).then(() => 'fetched'),
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{state.data}</h1>
|
||||
<h2>fetchStatus: {state.fetchStatus}</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rendered = render(
|
||||
<React.StrictMode>
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
onSuccess={onSuccess}
|
||||
>
|
||||
<Page />
|
||||
</PersistQueryClientProvider>
|
||||
</React.StrictMode>,
|
||||
)
|
||||
|
||||
expect(rendered.getByText('fetchStatus: idle')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
expect(rendered.getByText('hydrated')).toBeInTheDocument()
|
||||
await act(() => vi.advanceTimersByTimeAsync(11))
|
||||
expect(rendered.getByText('fetched')).toBeInTheDocument()
|
||||
|
||||
expect(onSuccess).toHaveBeenCalledTimes(1)
|
||||
expect(restoreCount).toBe(1)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,137 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { act, render } from '@testing-library/react'
|
||||
import * as React from 'react'
|
||||
import { QueryClient, useQueries } from '@tanstack/react-query'
|
||||
import { sleep } from '@tanstack/query-test-utils'
|
||||
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
|
||||
import type {
|
||||
PersistedClient,
|
||||
Persister,
|
||||
} from '@tanstack/query-persist-client-core'
|
||||
import type { QueryObserverResult } from '@tanstack/react-query'
|
||||
|
||||
describe('useQueries with persist and memoized combine', () => {
|
||||
const storage: { [key: string]: string } = {}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
Object.defineProperty(window, 'localStorage', {
|
||||
value: {
|
||||
getItem: (key: string) => storage[key] || null,
|
||||
setItem: (key: string, value: string) => {
|
||||
storage[key] = value
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
delete storage[key]
|
||||
},
|
||||
clear: () => {
|
||||
Object.keys(storage).forEach((key) => delete storage[key])
|
||||
},
|
||||
},
|
||||
writable: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Object.keys(storage).forEach((key) => delete storage[key])
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('should update UI when combine is memoized with persist', async () => {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 30_000,
|
||||
gcTime: 1000 * 60 * 60 * 24,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const persister: Persister = {
|
||||
persistClient: (client: PersistedClient) => {
|
||||
storage['REACT_QUERY_OFFLINE_CACHE'] = JSON.stringify(client)
|
||||
return Promise.resolve()
|
||||
},
|
||||
restoreClient: async () => {
|
||||
const stored = storage['REACT_QUERY_OFFLINE_CACHE']
|
||||
if (stored)
|
||||
return sleep(10).then(() => JSON.parse(stored) as PersistedClient)
|
||||
|
||||
return undefined
|
||||
},
|
||||
removeClient: () => {
|
||||
delete storage['REACT_QUERY_OFFLINE_CACHE']
|
||||
return Promise.resolve()
|
||||
},
|
||||
}
|
||||
|
||||
const persistedData: PersistedClient = {
|
||||
timestamp: Date.now(),
|
||||
buster: '',
|
||||
clientState: {
|
||||
mutations: [],
|
||||
queries: [1, 2, 3].map((id) => ({
|
||||
queryHash: `["post",${id}]`,
|
||||
queryKey: ['post', id],
|
||||
dehydratedAt: Date.now(),
|
||||
state: {
|
||||
data: id,
|
||||
dataUpdateCount: 1,
|
||||
dataUpdatedAt: Date.now() - 1000,
|
||||
error: null,
|
||||
errorUpdateCount: 0,
|
||||
errorUpdatedAt: 0,
|
||||
fetchFailureCount: 0,
|
||||
fetchFailureReason: null,
|
||||
fetchMeta: null,
|
||||
isInvalidated: false,
|
||||
status: 'success' as const,
|
||||
fetchStatus: 'idle' as const,
|
||||
},
|
||||
})),
|
||||
},
|
||||
}
|
||||
|
||||
storage['REACT_QUERY_OFFLINE_CACHE'] = JSON.stringify(persistedData)
|
||||
|
||||
function TestComponent() {
|
||||
const combinedQueries = useQueries({
|
||||
queries: [1, 2, 3].map((id) => ({
|
||||
queryKey: ['post', id],
|
||||
queryFn: () => sleep(100).then(() => id),
|
||||
staleTime: 30_000,
|
||||
})),
|
||||
combine: React.useCallback(
|
||||
(results: Array<QueryObserverResult<number, Error>>) => ({
|
||||
data: results.map((r) => r.data),
|
||||
isPending: results.some((r) => r.isPending),
|
||||
}),
|
||||
[],
|
||||
),
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div data-testid="pending">{String(combinedQueries.isPending)}</div>
|
||||
<div data-testid="data">
|
||||
{combinedQueries.data.filter((d) => d !== undefined).join(',')}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const { getByTestId } = render(
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister }}
|
||||
>
|
||||
<TestComponent />
|
||||
</PersistQueryClientProvider>,
|
||||
)
|
||||
|
||||
await act(() => vi.advanceTimersByTimeAsync(10))
|
||||
await act(() => vi.advanceTimersByTimeAsync(0))
|
||||
expect(getByTestId('pending').textContent).toBe('false')
|
||||
expect(getByTestId('data').textContent).toBe('1,2,3')
|
||||
})
|
||||
})
|
||||
4
packages/react-query-persist-client/src/index.ts
Normal file
4
packages/react-query-persist-client/src/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// Re-export core
|
||||
export * from '@tanstack/query-persist-client-core'
|
||||
|
||||
export * from './PersistQueryClientProvider'
|
||||
12
packages/react-query-persist-client/test-setup.ts
Normal file
12
packages/react-query-persist-client/test-setup.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
import { act, cleanup } from '@testing-library/react'
|
||||
import { afterEach } from 'vitest'
|
||||
import { notifyManager } from '@tanstack/react-query'
|
||||
|
||||
// https://testing-library.com/docs/react-testing-library/api#cleanup
|
||||
afterEach(() => cleanup())
|
||||
|
||||
// Wrap notifications with act to make sure React knows about React Query updates
|
||||
notifyManager.setNotifyFunction((fn) => {
|
||||
act(fn)
|
||||
})
|
||||
19
packages/react-query-persist-client/tsconfig.json
Normal file
19
packages/react-query-persist-client/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist-ts",
|
||||
"rootDir": ".",
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src",
|
||||
"test-setup.ts",
|
||||
"*.config.ts",
|
||||
"*.config.js",
|
||||
"package.json"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../query-persist-client-core" },
|
||||
{ "path": "../react-query" }
|
||||
]
|
||||
}
|
||||
13
packages/react-query-persist-client/tsconfig.legacy.json
Normal file
13
packages/react-query-persist-client/tsconfig.legacy.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"outDir": "./dist-ts/legacy"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["src/__tests__"],
|
||||
"references": [
|
||||
{ "path": "../query-persist-client-core" },
|
||||
{ "path": "../react-query" }
|
||||
]
|
||||
}
|
||||
10
packages/react-query-persist-client/tsconfig.prod.json
Normal file
10
packages/react-query-persist-client/tsconfig.prod.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"composite": false,
|
||||
"rootDir": "../../"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["src/__tests__"]
|
||||
}
|
||||
7
packages/react-query-persist-client/tsdown.config.ts
Normal file
7
packages/react-query-persist-client/tsdown.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'tsdown'
|
||||
import { legacyConfig, modernConfig } from './root.tsdown.config.js'
|
||||
|
||||
export default defineConfig([
|
||||
modernConfig({ entry: ['src/*.ts', 'src/*.tsx'] }),
|
||||
legacyConfig({ entry: ['src/*.ts', 'src/*.tsx'] }),
|
||||
])
|
||||
34
packages/react-query-persist-client/vite.config.ts
Normal file
34
packages/react-query-persist-client/vite.config.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
import packageJson from './package.json'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
// fix from https://github.com/vitest-dev/vitest/issues/6992#issuecomment-2509408660
|
||||
resolve: {
|
||||
conditions: ['@tanstack/custom-condition'],
|
||||
},
|
||||
environments: {
|
||||
ssr: {
|
||||
resolve: {
|
||||
conditions: ['@tanstack/custom-condition'],
|
||||
},
|
||||
},
|
||||
},
|
||||
test: {
|
||||
name: packageJson.name,
|
||||
dir: './src',
|
||||
watch: false,
|
||||
environment: 'jsdom',
|
||||
setupFiles: ['test-setup.ts'],
|
||||
coverage: {
|
||||
enabled: !!process.env.CI,
|
||||
provider: 'istanbul',
|
||||
include: ['src/**/*'],
|
||||
exclude: ['src/__tests__/**'],
|
||||
},
|
||||
typecheck: { enabled: true },
|
||||
restoreMocks: true,
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user