snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
autofix.ci / autofix (push) Failing after 4s
Release / Release (push) Has been skipped
GitHub Actions Security Analysis / Run zizmor (push) Failing after 2s

This commit is contained in:
upstream-mirror
2026-09-16 01:13:08 +05:00
commit 3a013ccdfe
3570 changed files with 490194 additions and 0 deletions

View File

@@ -0,0 +1,378 @@
# @tanstack/preact-query-persist-client
## 5.102.8
### Patch Changes
- Updated dependencies [[`6c27607`](https://github.com/TanStack/query/commit/6c27607d7ffc87612a8f1222a95f28bf5f9a045e)]:
- @tanstack/preact-query@5.102.8
- @tanstack/query-persist-client-core@5.102.8
## 5.102.7
### Patch Changes
- Updated dependencies [[`67fddee`](https://github.com/TanStack/query/commit/67fddee6310ca0dd87749ed7a1b4a7178c6e6aae)]:
- @tanstack/preact-query@5.102.7
- @tanstack/query-persist-client-core@5.102.7
## 5.102.6
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.102.6
- @tanstack/query-persist-client-core@5.102.6
## 5.102.5
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.102.5
- @tanstack/query-persist-client-core@5.102.5
## 5.102.4
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.102.4
- @tanstack/query-persist-client-core@5.102.4
## 5.102.3
### Patch Changes
- Updated dependencies [[`714c285`](https://github.com/TanStack/query/commit/714c2856e09bbaf7448ccc02364887e36c18b37c)]:
- @tanstack/preact-query@5.102.3
- @tanstack/query-persist-client-core@5.102.3
## 5.102.2
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.102.2
- @tanstack/query-persist-client-core@5.102.2
## 5.102.1
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.102.1
- @tanstack/query-persist-client-core@5.102.1
## 5.102.0
### Patch Changes
- Updated dependencies [[`4e48c58`](https://github.com/TanStack/query/commit/4e48c581b70216e9c66a72cc328b61789194db4f), [`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), [`4913802`](https://github.com/TanStack/query/commit/49138028953f38097cfac4a6e9843c987705325f), [`1ef4208`](https://github.com/TanStack/query/commit/1ef42087c9a266c2137d2ef645cbcc662f60ac93), [`b866a95`](https://github.com/TanStack/query/commit/b866a95adde7e8465462526df5870ebc12340b36), [`e546d03`](https://github.com/TanStack/query/commit/e546d03bef116c66a05dbf42ccfd70b6d8600a8f)]:
- @tanstack/preact-query@5.102.0
- @tanstack/query-persist-client-core@5.102.0
## 5.101.4
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.101.4
- @tanstack/query-persist-client-core@5.101.4
## 5.101.3
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.101.3
- @tanstack/query-persist-client-core@5.101.3
## 5.101.2
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.101.2
- @tanstack/query-persist-client-core@5.101.2
## 5.101.1
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.101.1
- @tanstack/query-persist-client-core@5.101.1
## 5.101.0
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.101.0
- @tanstack/query-persist-client-core@5.101.0
## 5.100.14
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.14
- @tanstack/query-persist-client-core@5.100.14
## 5.100.13
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.13
- @tanstack/query-persist-client-core@5.100.13
## 5.100.12
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.12
- @tanstack/query-persist-client-core@5.100.12
## 5.100.11
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.11
- @tanstack/query-persist-client-core@5.100.11
## 5.100.10
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.10
- @tanstack/query-persist-client-core@5.100.10
## 5.100.9
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.9
- @tanstack/query-persist-client-core@5.100.9
## 5.100.8
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.8
- @tanstack/query-persist-client-core@5.100.8
## 5.100.7
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.7
- @tanstack/query-persist-client-core@5.100.7
## 5.100.6
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.6
- @tanstack/query-persist-client-core@5.100.6
## 5.100.5
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.5
- @tanstack/query-persist-client-core@5.100.5
## 5.100.4
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.4
- @tanstack/query-persist-client-core@5.100.4
## 5.100.3
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.3
- @tanstack/query-persist-client-core@5.100.3
## 5.100.2
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.2
- @tanstack/query-persist-client-core@5.100.2
## 5.100.1
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.1
- @tanstack/query-persist-client-core@5.100.1
## 5.100.0
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.100.0
- @tanstack/query-persist-client-core@5.100.0
## 5.99.2
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.99.2
- @tanstack/query-persist-client-core@5.99.2
## 5.99.1
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.99.1
- @tanstack/query-persist-client-core@5.99.1
## 5.99.0
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.99.0
- @tanstack/query-persist-client-core@5.99.0
## 5.98.0
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.98.0
- @tanstack/query-persist-client-core@5.98.0
## 5.97.0
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.97.0
- @tanstack/query-persist-client-core@5.97.0
## 5.96.2
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.96.2
- @tanstack/query-persist-client-core@5.96.2
## 5.96.1
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.96.1
- @tanstack/query-persist-client-core@5.96.1
## 5.96.0
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.96.0
- @tanstack/query-persist-client-core@5.96.0
## 5.95.2
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.95.2
- @tanstack/query-persist-client-core@5.95.2
## 5.95.1
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.95.1
- @tanstack/query-persist-client-core@5.95.1
## 5.95.0
### Patch Changes
- Updated dependencies []:
- @tanstack/preact-query@5.95.0
- @tanstack/query-persist-client-core@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/preact-query@5.94.5
- @tanstack/query-persist-client-core@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/preact-query@5.94.4
## 5.92.3
### 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/preact-query@5.94.2
## 5.92.2
### Patch Changes
- Updated dependencies [[`a89aab9`](https://github.com/TanStack/query/commit/a89aab975581c25c113a26c8af486b4cafad272a)]:
- @tanstack/preact-query@5.94.1
- @tanstack/query-persist-client-core@5.92.3
## 5.92.1
### Patch Changes
- Updated dependencies [[`6fa901b`](https://github.com/TanStack/query/commit/6fa901b97a22a80d0fca3f6ed86237ff0cbdd13b)]:
- @tanstack/preact-query@5.94.0
- @tanstack/query-persist-client-core@5.92.2
## 5.92.0
### Minor Changes
- feat: Add preact persist plugin ([#10120](https://github.com/TanStack/query/pull/10120))
### Patch Changes
- Updated dependencies [[`887541a`](https://github.com/TanStack/query/commit/887541a2fa5eec801e53cc93c2831a55325ea44a)]:
- @tanstack/preact-query@5.93.0

View File

@@ -0,0 +1,38 @@
// @ts-check
// @ts-ignore: no types for eslint-config-preact
import preact from 'eslint-config-preact'
// eslint-config-preact uses typescript-eslint under the hood
import tseslint from 'typescript-eslint'
import rootConfig from './root.eslint.config.js'
export default [
...rootConfig,
...preact,
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: true,
},
},
plugins: {
'typescript-eslint': tseslint.plugin,
},
rules: {
// Disable base rule to prevent overload false positives
'no-redeclare': 'off',
'no-duplicate-imports': 'off',
'no-unused-vars': 'off',
'import/order': 'off',
'sort-imports': 'off',
'no-import-assign': 'off',
// TS-aware version handles overloads correctly
'@typescript-eslint/no-redeclare': 'error',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
},
},
]

View File

@@ -0,0 +1,75 @@
{
"name": "@tanstack/preact-query-persist-client",
"version": "5.102.8",
"description": "Preact bindings to work with persisters in TanStack/preact-query",
"author": "tannerlinsley",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/TanStack/query.git",
"directory": "packages/preact-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.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",
"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": {
"@preact/preset-vite": "^2.10.2",
"@tanstack/preact-query": "workspace:*",
"@tanstack/query-test-utils": "workspace:*",
"@testing-library/preact": "^3.2.4",
"eslint-config-preact": "^2.0.0",
"npm-run-all2": "^5.0.0",
"preact": "^10.28.0",
"typescript": "6.0.3",
"typescript-eslint": "^8.54.0"
},
"peerDependencies": {
"@tanstack/preact-query": "workspace:^",
"preact": "^10.0.0"
}
}

View File

@@ -0,0 +1 @@
../../eslint.config.js

View File

@@ -0,0 +1 @@
../../scripts/getTsdownConfig.js

View File

@@ -0,0 +1,61 @@
import { useEffect, useRef, useState } from 'preact/hooks'
import type { VNode } from 'preact'
import {
persistQueryClientRestore,
persistQueryClientSubscribe,
} from '@tanstack/query-persist-client-core'
import {
IsRestoringProvider,
QueryClientProvider,
} from '@tanstack/preact-query'
import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
import type {
OmitKeyof,
QueryClientProviderProps,
} from '@tanstack/preact-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): VNode => {
const [isRestoring, setIsRestoring] = useState(true)
const refs = useRef({ persistOptions, onSuccess, onError })
const didRestore = useRef(false)
useEffect(() => {
refs.current = { persistOptions, onSuccess, onError }
})
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>
)
}

View File

@@ -0,0 +1,128 @@
/** @jsxRuntime automatic */
/** @jsxImportSource preact */
import '@testing-library/jest-dom/vitest'
import type {
PersistedClient,
Persister,
} from '../../../query-persist-client-core/src'
import { persistQueryClientSave } from '../../../query-persist-client-core/src'
import { notifyManager, noop } from '../../../query-core/src'
import { act, cleanup, render } from '@testing-library/preact'
import type { UseQueryResult } from '../../../preact-query/src'
import { QueryClient, useQuery } from '../../../preact-query/src'
import { afterEach, beforeEach, describe, expect, vi, it } from 'vitest'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { PersistQueryClientProvider } from './testPersistProvider'
notifyManager.setNotifyFunction((fn) => {
act(fn)
})
const createMockPersister = (): Persister => {
let storedState: PersistedClient | undefined
return {
persistClient(persistClient: PersistedClient) {
storedState = persistClient
return Promise.resolve()
},
async restoreClient() {
return sleep(10).then(() => storedState)
},
removeClient() {
storedState = undefined
return Promise.resolve()
},
}
}
describe('PersistQueryClientProvider (preact)', () => {
beforeEach(() => {
vi.useFakeTimers()
})
afterEach(() => {
cleanup()
vi.useRealTimers()
})
it('restores cache from persister and refetches', 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(async () => {
await vi.advanceTimersByTimeAsync(10)
})
expect(rendered.getByText('hydrated')).toBeInTheDocument()
await act(async () => {
await vi.advanceTimersByTimeAsync(11)
})
expect(rendered.getByText('fetched')).toBeInTheDocument()
expect(states.length).toBeGreaterThanOrEqual(3)
expect(states[0]).toMatchObject({
status: 'pending',
fetchStatus: 'idle',
data: undefined,
})
expect(
states.some(
(state) =>
state.fetchStatus === 'fetching' && state.data === 'hydrated',
),
).toBe(true)
expect(states.at(-1)).toMatchObject({
status: 'success',
fetchStatus: 'idle',
data: 'fetched',
})
})
})

View File

@@ -0,0 +1,61 @@
/** @jsxRuntime automatic */
/** @jsxImportSource preact */
import {
persistQueryClientRestore,
persistQueryClientSubscribe,
} from '../../../query-persist-client-core/src'
import {
IsRestoringProvider,
QueryClientProvider,
} from '../../../preact-query/src'
import type { ComponentChildren } from 'preact'
import { useEffect, useRef, useState } from 'preact/hooks'
type Props = {
children?: ComponentChildren
client: any
persistOptions: any
onSuccess?: () => void | Promise<void>
onError?: () => void
}
export function PersistQueryClientProvider({
children,
persistOptions,
onSuccess,
onError,
...props
}: Props) {
const [isRestoring, setIsRestoring] = useState(true)
const refs = useRef({ persistOptions, onSuccess, onError })
const didRestore = useRef(false)
useEffect(() => {
refs.current = { persistOptions, onSuccess, onError }
})
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>
)
}

View File

@@ -0,0 +1,156 @@
/** @jsxRuntime automatic */
/** @jsxImportSource preact */
import '@testing-library/jest-dom/vitest'
import type { QueryObserverResult } from '../../../query-core/src'
import { notifyManager } from '../../../query-core/src'
import type {
PersistedClient,
Persister,
} from '../../../query-persist-client-core/src'
import { act, cleanup, render } from '@testing-library/preact'
import { QueryClient, useQueries } from '../../../preact-query/src'
import { useCallback } from 'preact/hooks'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { sleep } from '@tanstack/query-test-utils'
import { PersistQueryClientProvider } from './testPersistProvider'
notifyManager.setNotifyFunction((fn) => {
act(fn)
})
describe('useQueries with persist and memoized combine (preact)', () => {
const storage: Record<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(() => {
cleanup()
Object.keys(storage).forEach((key) => delete storage[key])
vi.useRealTimers()
})
it('updates UI when combine is memoized with persisted results', 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: useCallback(
(results: Array<QueryObserverResult<number, Error>>) => ({
data: results.map((result) => result.data),
isPending: results.some((result) => result.isPending),
}),
[],
),
})
return (
<div>
<div data-testid="pending">{String(combinedQueries.isPending)}</div>
<div data-testid="data">
{combinedQueries.data
.filter((value) => value !== undefined)
.join(',')}
</div>
</div>
)
}
const rendered = render(
<PersistQueryClientProvider
client={queryClient}
persistOptions={{ persister }}
>
<TestComponent />
</PersistQueryClientProvider>,
)
await act(async () => {
await vi.advanceTimersByTimeAsync(10)
})
await act(async () => {
await vi.advanceTimersByTimeAsync(0)
})
expect(rendered.getByTestId('pending').textContent).toBe('false')
expect(rendered.getByTestId('data').textContent).toBe('1,2,3')
})
})

View File

@@ -0,0 +1,4 @@
// Re-export core
export * from '@tanstack/query-persist-client-core'
export * from './PersistQueryClientProvider'

View File

@@ -0,0 +1,14 @@
import '@testing-library/jest-dom/vitest'
import { act, cleanup as cleanupRTL } from '@testing-library/preact'
import { afterEach } from 'vitest'
import { notifyManager } from '@tanstack/preact-query'
// https://testing-library.com/docs/preact-testing-library/api#cleanup
afterEach(() => {
cleanupRTL()
})
// Wrap notifications with act to make sure Preact knows about Query updates
notifyManager.setNotifyFunction((fn) => {
act(fn)
})

View File

@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist-ts",
"rootDir": ".",
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"include": [
"src",
"test-setup.ts",
"*.config.ts",
"*.config.js",
"package.json"
],
"references": [
{ "path": "../query-persist-client-core" },
{ "path": "../preact-query" }
]
}

View File

@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact",
"outDir": "./dist-ts/legacy"
},
"include": ["src"],
"exclude": ["src/__tests__"],
"references": [
{ "path": "../query-persist-client-core" },
{ "path": "../preact-query" }
]
}

View File

@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"incremental": false,
"composite": false,
"rootDir": "../../"
},
"include": ["src"],
"exclude": ["src/__tests__"]
}

View 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'] }),
])

View File

@@ -0,0 +1,34 @@
import preact from '@preact/preset-vite'
import { defineConfig } from 'vitest/config'
import packageJson from './package.json'
import type { UserConfig as ViteUserConfig } from 'vite'
export default defineConfig({
plugins: [preact() as ViteUserConfig['plugins']],
// 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,
},
})