@tanstack/preact-query 5.102.3 → 5.102.5
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/legacy/HydrationBoundary.cjs +43 -0
- package/build/legacy/HydrationBoundary.cjs.map +1 -1
- package/build/legacy/HydrationBoundary.d.cts +61 -0
- package/build/legacy/HydrationBoundary.d.cts.map +1 -1
- package/build/legacy/HydrationBoundary.d.ts +61 -0
- package/build/legacy/HydrationBoundary.d.ts.map +1 -1
- package/build/legacy/HydrationBoundary.js +43 -0
- package/build/legacy/HydrationBoundary.js.map +1 -1
- package/build/legacy/IsRestoringProvider.cjs +11 -0
- package/build/legacy/IsRestoringProvider.cjs.map +1 -1
- package/build/legacy/IsRestoringProvider.d.cts +11 -0
- package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
- package/build/legacy/IsRestoringProvider.d.ts +11 -0
- package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
- package/build/legacy/IsRestoringProvider.js +11 -0
- package/build/legacy/IsRestoringProvider.js.map +1 -1
- package/build/legacy/QueryClientProvider.cjs +30 -0
- package/build/legacy/QueryClientProvider.cjs.map +1 -1
- package/build/legacy/QueryClientProvider.d.cts +41 -0
- package/build/legacy/QueryClientProvider.d.cts.map +1 -1
- package/build/legacy/QueryClientProvider.d.ts +41 -0
- package/build/legacy/QueryClientProvider.d.ts.map +1 -1
- package/build/legacy/QueryClientProvider.js +30 -0
- package/build/legacy/QueryClientProvider.js.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.cjs +77 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +108 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +108 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +77 -0
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +187 -0
- package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +187 -0
- package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
- package/build/legacy/infiniteQueryOptions.js.map +1 -1
- package/build/legacy/mutationOptions.cjs.map +1 -1
- package/build/legacy/mutationOptions.d.cts +68 -0
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +68 -0
- package/build/legacy/mutationOptions.d.ts.map +1 -1
- package/build/legacy/mutationOptions.js.map +1 -1
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +198 -0
- package/build/legacy/queryOptions.d.cts.map +1 -1
- package/build/legacy/queryOptions.d.ts +198 -0
- package/build/legacy/queryOptions.d.ts.map +1 -1
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +228 -2
- package/build/legacy/types.d.cts.map +1 -1
- package/build/legacy/types.d.ts +228 -2
- package/build/legacy/types.d.ts.map +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +120 -0
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +120 -0
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +34 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +34 -0
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +34 -0
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +34 -0
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +170 -0
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +170 -0
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +170 -0
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +170 -0
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +74 -0
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +74 -0
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +74 -0
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +74 -0
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.cjs +44 -0
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +44 -0
- package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +44 -0
- package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.js +44 -0
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/legacy/usePrefetchQuery.cjs +35 -0
- package/build/legacy/usePrefetchQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +35 -0
- package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +35 -0
- package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchQuery.js +35 -0
- package/build/legacy/usePrefetchQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs +50 -0
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +85 -2
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +85 -2
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +50 -0
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +186 -0
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +186 -0
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +56 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +56 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +56 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +56 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +196 -2
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +196 -2
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +47 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +47 -0
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +47 -0
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +47 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/modern/HydrationBoundary.cjs +43 -0
- package/build/modern/HydrationBoundary.cjs.map +1 -1
- package/build/modern/HydrationBoundary.d.cts +61 -0
- package/build/modern/HydrationBoundary.d.cts.map +1 -1
- package/build/modern/HydrationBoundary.d.ts +61 -0
- package/build/modern/HydrationBoundary.d.ts.map +1 -1
- package/build/modern/HydrationBoundary.js +43 -0
- package/build/modern/HydrationBoundary.js.map +1 -1
- package/build/modern/IsRestoringProvider.cjs +11 -0
- package/build/modern/IsRestoringProvider.cjs.map +1 -1
- package/build/modern/IsRestoringProvider.d.cts +11 -0
- package/build/modern/IsRestoringProvider.d.cts.map +1 -1
- package/build/modern/IsRestoringProvider.d.ts +11 -0
- package/build/modern/IsRestoringProvider.d.ts.map +1 -1
- package/build/modern/IsRestoringProvider.js +11 -0
- package/build/modern/IsRestoringProvider.js.map +1 -1
- package/build/modern/QueryClientProvider.cjs +30 -0
- package/build/modern/QueryClientProvider.cjs.map +1 -1
- package/build/modern/QueryClientProvider.d.cts +41 -0
- package/build/modern/QueryClientProvider.d.cts.map +1 -1
- package/build/modern/QueryClientProvider.d.ts +41 -0
- package/build/modern/QueryClientProvider.d.ts.map +1 -1
- package/build/modern/QueryClientProvider.js +30 -0
- package/build/modern/QueryClientProvider.js.map +1 -1
- package/build/modern/QueryErrorResetBoundary.cjs +77 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +108 -0
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +108 -0
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +77 -0
- package/build/modern/QueryErrorResetBoundary.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +187 -0
- package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +187 -0
- package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
- package/build/modern/infiniteQueryOptions.js.map +1 -1
- package/build/modern/mutationOptions.cjs.map +1 -1
- package/build/modern/mutationOptions.d.cts +68 -0
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +68 -0
- package/build/modern/mutationOptions.d.ts.map +1 -1
- package/build/modern/mutationOptions.js.map +1 -1
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +198 -0
- package/build/modern/queryOptions.d.cts.map +1 -1
- package/build/modern/queryOptions.d.ts +198 -0
- package/build/modern/queryOptions.d.ts.map +1 -1
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +228 -2
- package/build/modern/types.d.cts.map +1 -1
- package/build/modern/types.d.ts +228 -2
- package/build/modern/types.d.ts.map +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +120 -0
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +120 -0
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +34 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +34 -0
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +34 -0
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +34 -0
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +170 -0
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +170 -0
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +170 -0
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +170 -0
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +74 -0
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +74 -0
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +74 -0
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +74 -0
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.cjs +44 -0
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +44 -0
- package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +44 -0
- package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.js +44 -0
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/modern/usePrefetchQuery.cjs +35 -0
- package/build/modern/usePrefetchQuery.cjs.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +35 -0
- package/build/modern/usePrefetchQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchQuery.d.ts +35 -0
- package/build/modern/usePrefetchQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchQuery.js +35 -0
- package/build/modern/usePrefetchQuery.js.map +1 -1
- package/build/modern/useQueries.cjs +50 -0
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +85 -2
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +85 -2
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +50 -0
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +186 -0
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +186 -0
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +56 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +56 -0
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +56 -0
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +56 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +196 -2
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +196 -2
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +47 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +47 -0
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +47 -0
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +47 -0
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/package.json +3 -3
- package/src/HydrationBoundary.tsx +61 -0
- package/src/IsRestoringProvider.ts +12 -0
- package/src/QueryClientProvider.tsx +41 -0
- package/src/QueryErrorResetBoundary.tsx +111 -0
- package/src/infiniteQueryOptions.ts +187 -0
- package/src/mutationOptions.ts +68 -0
- package/src/queryOptions.ts +198 -0
- package/src/types.ts +228 -2
- package/src/useInfiniteQuery.ts +120 -0
- package/src/useIsFetching.ts +34 -0
- package/src/useMutation.ts +170 -0
- package/src/useMutationState.ts +74 -0
- package/src/usePrefetchInfiniteQuery.tsx +44 -0
- package/src/usePrefetchQuery.tsx +35 -0
- package/src/useQueries.ts +85 -2
- package/src/useQuery.ts +186 -0
- package/src/useSuspenseInfiniteQuery.ts +56 -0
- package/src/useSuspenseQueries.ts +196 -2
- package/src/useSuspenseQuery.ts +47 -0
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
import { UseSuspenseQueryOptions, UseSuspenseQueryResult } from "./types.js";
|
|
2
2
|
import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
|
|
3
3
|
//#region src/useSuspenseQuery.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and
|
|
6
|
+
* `placeholderData`.
|
|
7
|
+
*
|
|
8
|
+
* Caveat: cancellation does not work.
|
|
9
|
+
*
|
|
10
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
11
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
12
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
13
|
+
* fetch in parallel.
|
|
14
|
+
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
15
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
16
|
+
* be used.
|
|
17
|
+
* @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`
|
|
18
|
+
* is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* import { Suspense } from 'preact/compat'
|
|
23
|
+
* import { useSuspenseQuery } from '@tanstack/preact-query'
|
|
24
|
+
*
|
|
25
|
+
* function Posts() {
|
|
26
|
+
* // `data` is guaranteed to be defined here — no `isPending` check needed.
|
|
27
|
+
* const { data, isFetching } = useSuspenseQuery({
|
|
28
|
+
* queryKey: ['posts'],
|
|
29
|
+
* queryFn: fetchPosts,
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* return (
|
|
33
|
+
* <div>
|
|
34
|
+
* <h1>Posts {isFetching ? <Spinner /> : null}</h1>
|
|
35
|
+
* {data.map((post) => (
|
|
36
|
+
* <p key={post.id}>{post.title}</p>
|
|
37
|
+
* ))}
|
|
38
|
+
* </div>
|
|
39
|
+
* )
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* function App() {
|
|
43
|
+
* return (
|
|
44
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
45
|
+
* <Posts />
|
|
46
|
+
* </Suspense>
|
|
47
|
+
* )
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
4
51
|
declare function useSuspenseQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseSuspenseQueryResult<TData, TError>;
|
|
5
52
|
//#endregion
|
|
6
53
|
export { useSuspenseQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.d.ts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.d.ts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsDgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,wBAAwB,cAAc,QAAQ,OAAO,YAC9D,cAAc,cACb,uBAAuB,OAAO"}
|
|
@@ -2,6 +2,53 @@ import { defaultThrowOnError } from "./suspense.js";
|
|
|
2
2
|
import { useBaseQuery } from "./useBaseQuery.js";
|
|
3
3
|
import { QueryObserver, skipToken } from "@tanstack/query-core";
|
|
4
4
|
//#region src/useSuspenseQuery.ts
|
|
5
|
+
/**
|
|
6
|
+
* The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and
|
|
7
|
+
* `placeholderData`.
|
|
8
|
+
*
|
|
9
|
+
* Caveat: cancellation does not work.
|
|
10
|
+
*
|
|
11
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
12
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
13
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
14
|
+
* fetch in parallel.
|
|
15
|
+
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
16
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
17
|
+
* be used.
|
|
18
|
+
* @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`
|
|
19
|
+
* is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* import { Suspense } from 'preact/compat'
|
|
24
|
+
* import { useSuspenseQuery } from '@tanstack/preact-query'
|
|
25
|
+
*
|
|
26
|
+
* function Posts() {
|
|
27
|
+
* // `data` is guaranteed to be defined here — no `isPending` check needed.
|
|
28
|
+
* const { data, isFetching } = useSuspenseQuery({
|
|
29
|
+
* queryKey: ['posts'],
|
|
30
|
+
* queryFn: fetchPosts,
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* return (
|
|
34
|
+
* <div>
|
|
35
|
+
* <h1>Posts {isFetching ? <Spinner /> : null}</h1>
|
|
36
|
+
* {data.map((post) => (
|
|
37
|
+
* <p key={post.id}>{post.title}</p>
|
|
38
|
+
* ))}
|
|
39
|
+
* </div>
|
|
40
|
+
* )
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* function App() {
|
|
44
|
+
* return (
|
|
45
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
46
|
+
* <Posts />
|
|
47
|
+
* </Suspense>
|
|
48
|
+
* )
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
5
52
|
function useSuspenseQuery(options, queryClient) {
|
|
6
53
|
if (process.env.NODE_ENV !== "production") {
|
|
7
54
|
if (options.queryFn === skipToken) console.error("skipToken is not allowed for useSuspenseQuery");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.js","names":[],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["import { QueryObserver, skipToken } from '@tanstack/query-core'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\nexport function useSuspenseQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseSuspenseQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n QueryObserver,\n queryClient,\n ) as UseSuspenseQueryResult<TData, TError>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.js","names":[],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["import { QueryObserver, skipToken } from '@tanstack/query-core'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and\n * `placeholderData`.\n *\n * Caveat: cancellation does not work.\n *\n * @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request\n * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.\n * Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they\n * fetch in parallel.\n * @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`\n * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * // `data` is guaranteed to be defined here — no `isPending` check needed.\n * const { data, isFetching } = useSuspenseQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * return (\n * <div>\n * <h1>Posts {isFetching ? <Spinner /> : null}</h1>\n * {data.map((post) => (\n * <p key={post.id}>{post.title}</p>\n * ))}\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseSuspenseQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n QueryObserver,\n queryClient,\n ) as UseSuspenseQueryResult<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,iBAMd,SACA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoB,WAC/B,QAAQ,MAAM,+CAA+C;CAAA;CAIjE,OAAO,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAc;EACd,iBAAiB,KAAA;CACnB,GACA,eACA,WACF;AACF"}
|
|
@@ -5,6 +5,49 @@ let preact = require("preact");
|
|
|
5
5
|
let preact_hooks = require("preact/hooks");
|
|
6
6
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
7
7
|
//#region src/HydrationBoundary.tsx
|
|
8
|
+
/**
|
|
9
|
+
* `HydrationBoundary` adds a previously dehydrated state into the `queryClient` that would be returned by
|
|
10
|
+
* `useQueryClient()`. If the client already contains data, the new queries will be intelligently merged based on
|
|
11
|
+
* update timestamp.
|
|
12
|
+
*
|
|
13
|
+
* Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
|
|
14
|
+
*
|
|
15
|
+
* @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
|
|
16
|
+
* cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
|
|
17
|
+
* after commit.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { HydrationBoundary } from '@tanstack/preact-query'
|
|
22
|
+
*
|
|
23
|
+
* function App() {
|
|
24
|
+
* return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* Server-side prefetch handed off to the client via `dehydrate`:
|
|
30
|
+
* ```tsx
|
|
31
|
+
* import { HydrationBoundary, dehydrate, noop } from '@tanstack/preact-query'
|
|
32
|
+
*
|
|
33
|
+
* async function ServerComponent() {
|
|
34
|
+
* const queryClient = getQueryClient()
|
|
35
|
+
*
|
|
36
|
+
* await queryClient
|
|
37
|
+
* .query({
|
|
38
|
+
* queryKey: ['posts'],
|
|
39
|
+
* queryFn: fetchPosts,
|
|
40
|
+
* })
|
|
41
|
+
* .catch(noop)
|
|
42
|
+
*
|
|
43
|
+
* return (
|
|
44
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
45
|
+
* <Posts />
|
|
46
|
+
* </HydrationBoundary>
|
|
47
|
+
* )
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
8
51
|
const HydrationBoundary = ({ children, options = {}, state, queryClient }) => {
|
|
9
52
|
const client = require_QueryClientProvider.useQueryClient(queryClient);
|
|
10
53
|
const optionsRef = (0, preact_hooks.useRef)(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HydrationBoundary.cjs","names":["useQueryClient","useRef","useMemo","Fragment"],"sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["import { hydrate } from '@tanstack/query-core'\nimport type {\n DehydratedState,\n HydrateOptions,\n OmitKeyof,\n QueryClient,\n} from '@tanstack/query-core'\nimport { Fragment } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useEffect, useMemo, useRef } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\n\nexport interface HydrationBoundaryProps {\n state: DehydratedState | null | undefined\n options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {\n defaultOptions?: OmitKeyof<\n Exclude<HydrateOptions['defaultOptions'], undefined>,\n 'mutations'\n >\n }\n children?: ComponentChildren\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = useRef(options)\n useEffect(() => {\n optionsRef.current = options\n })\n\n // This useMemo is for performance reasons only, everything inside it must\n // be safe to run in every render and code here should be read as \"in render\".\n //\n // This code needs to happen during the render phase, because after initial\n // SSR, hydration needs to happen _before_ children render. Also, if hydrating\n // during a transition, we want to hydrate as much as is safe in render so\n // we can prerender as much as possible.\n //\n // For any queries that already exist in the cache, we want to hold back on\n // hydrating until _after_ the render phase. The reason for this is that during\n // transitions, we don't want the existing queries and observers to update to\n // the new data on the current page, only _after_ the transition is committed.\n // If the transition is aborted, we will have hydrated any _new_ queries, but\n // we throw away the fresh data for any existing ones to avoid unexpectedly\n // updating the UI.\n const hydrationQueue: DehydratedState['queries'] | undefined = useMemo(() => {\n if (state) {\n if (typeof state !== 'object') {\n return\n }\n\n const queryCache = client.getQueryCache()\n // State is supplied from the outside and we might as well fail\n // gracefully if it has the wrong shape, so while we type `queries`\n // as required, we still provide a fallback.\n const queries = state.queries || []\n\n const newQueries: DehydratedState['queries'] = []\n const existingQueries: DehydratedState['queries'] = []\n for (const dehydratedQuery of queries) {\n const existingQuery = queryCache.get(dehydratedQuery.queryHash)\n\n if (!existingQuery) {\n newQueries.push(dehydratedQuery)\n } else {\n const hydrationIsNewer =\n dehydratedQuery.state.dataUpdatedAt >\n existingQuery.state.dataUpdatedAt ||\n (dehydratedQuery.promise &&\n existingQuery.state.status !== 'pending' &&\n existingQuery.state.fetchStatus !== 'fetching' &&\n dehydratedQuery.dehydratedAt !== undefined &&\n dehydratedQuery.dehydratedAt > existingQuery.state.dataUpdatedAt)\n\n if (hydrationIsNewer) {\n existingQueries.push(dehydratedQuery)\n }\n }\n }\n\n if (newQueries.length > 0) {\n // It's actually fine to call this with queries/state that already exists\n // in the cache, or is older. hydrate() is idempotent for queries.\n hydrate(client, { queries: newQueries }, optionsRef.current)\n }\n if (existingQueries.length > 0) {\n return existingQueries\n }\n }\n return undefined\n }, [client, state])\n\n useEffect(() => {\n if (hydrationQueue) {\n hydrate(client, { queries: hydrationQueue }, optionsRef.current)\n }\n }, [client, hydrationQueue])\n\n return <Fragment>{children}</Fragment>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HydrationBoundary.cjs","names":["useQueryClient","useRef","useMemo","Fragment"],"sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["import { hydrate } from '@tanstack/query-core'\nimport type {\n DehydratedState,\n HydrateOptions,\n OmitKeyof,\n QueryClient,\n} from '@tanstack/query-core'\nimport { Fragment } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useEffect, useMemo, useRef } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\n\n/**\n * The props accepted by `HydrationBoundary`.\n */\nexport interface HydrationBoundaryProps {\n /**\n * The state to hydrate.\n */\n state: DehydratedState | null | undefined\n /**\n * Optional. Note: unlike `hydrate`, `mutations` cannot be set here.\n */\n options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {\n defaultOptions?: OmitKeyof<\n Exclude<HydrateOptions['defaultOptions'], undefined>,\n 'mutations'\n >\n }\n /**\n * The components to render — always rendered unconditionally, not gated on hydration. New queries are\n * hydrated into the cache during render; for queries that already exist in the cache, only newer dehydrated\n * data is hydrated, and that happens in an effect after commit, so `children` may render briefly before it\n * lands.\n */\n children?: ComponentChildren\n /**\n * Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will be used.\n */\n queryClient?: QueryClient\n}\n\n/**\n * `HydrationBoundary` adds a previously dehydrated state into the `queryClient` that would be returned by\n * `useQueryClient()`. If the client already contains data, the new queries will be intelligently merged based on\n * update timestamp.\n *\n * Note: Only `queries` can be dehydrated with an `HydrationBoundary`.\n *\n * @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the\n * cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect\n * after commit.\n *\n * @example\n * ```tsx\n * import { HydrationBoundary } from '@tanstack/preact-query'\n *\n * function App() {\n * return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>\n * }\n * ```\n *\n * @example\n * Server-side prefetch handed off to the client via `dehydrate`:\n * ```tsx\n * import { HydrationBoundary, dehydrate, noop } from '@tanstack/preact-query'\n *\n * async function ServerComponent() {\n * const queryClient = getQueryClient()\n *\n * await queryClient\n * .query({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * .catch(noop)\n *\n * return (\n * <HydrationBoundary state={dehydrate(queryClient)}>\n * <Posts />\n * </HydrationBoundary>\n * )\n * }\n * ```\n */\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = useRef(options)\n useEffect(() => {\n optionsRef.current = options\n })\n\n // This useMemo is for performance reasons only, everything inside it must\n // be safe to run in every render and code here should be read as \"in render\".\n //\n // This code needs to happen during the render phase, because after initial\n // SSR, hydration needs to happen _before_ children render. Also, if hydrating\n // during a transition, we want to hydrate as much as is safe in render so\n // we can prerender as much as possible.\n //\n // For any queries that already exist in the cache, we want to hold back on\n // hydrating until _after_ the render phase. The reason for this is that during\n // transitions, we don't want the existing queries and observers to update to\n // the new data on the current page, only _after_ the transition is committed.\n // If the transition is aborted, we will have hydrated any _new_ queries, but\n // we throw away the fresh data for any existing ones to avoid unexpectedly\n // updating the UI.\n const hydrationQueue: DehydratedState['queries'] | undefined = useMemo(() => {\n if (state) {\n if (typeof state !== 'object') {\n return\n }\n\n const queryCache = client.getQueryCache()\n // State is supplied from the outside and we might as well fail\n // gracefully if it has the wrong shape, so while we type `queries`\n // as required, we still provide a fallback.\n const queries = state.queries || []\n\n const newQueries: DehydratedState['queries'] = []\n const existingQueries: DehydratedState['queries'] = []\n for (const dehydratedQuery of queries) {\n const existingQuery = queryCache.get(dehydratedQuery.queryHash)\n\n if (!existingQuery) {\n newQueries.push(dehydratedQuery)\n } else {\n const hydrationIsNewer =\n dehydratedQuery.state.dataUpdatedAt >\n existingQuery.state.dataUpdatedAt ||\n (dehydratedQuery.promise &&\n existingQuery.state.status !== 'pending' &&\n existingQuery.state.fetchStatus !== 'fetching' &&\n dehydratedQuery.dehydratedAt !== undefined &&\n dehydratedQuery.dehydratedAt > existingQuery.state.dataUpdatedAt)\n\n if (hydrationIsNewer) {\n existingQueries.push(dehydratedQuery)\n }\n }\n }\n\n if (newQueries.length > 0) {\n // It's actually fine to call this with queries/state that already exists\n // in the cache, or is older. hydrate() is idempotent for queries.\n hydrate(client, { queries: newQueries }, optionsRef.current)\n }\n if (existingQueries.length > 0) {\n return existingQueries\n }\n }\n return undefined\n }, [client, state])\n\n useEffect(() => {\n if (hydrationQueue) {\n hydrate(client, { queries: hydrationQueue }, optionsRef.current)\n }\n }, [client, hydrationQueue])\n\n return <Fragment>{children}</Fragment>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,MAAa,qBAAqB,EAChC,UACA,UAAU,CAAC,GACX,OACA,kBAC4B;CAC5B,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,MAAM,cAAA,GAAaC,aAAAA,OAAAA,CAAO,OAAO;CACjC,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,WAAW,UAAU;CACvB,CAAC;CAiBD,MAAM,kBAAA,GAAyDC,aAAAA,QAAAA,OAAc;EAC3E,IAAI,OAAO;GACT,IAAI,OAAO,UAAU,UACnB;GAGF,MAAM,aAAa,OAAO,cAAc;GAIxC,MAAM,UAAU,MAAM,WAAW,CAAC;GAElC,MAAM,aAAyC,CAAC;GAChD,MAAM,kBAA8C,CAAC;GACrD,KAAK,MAAM,mBAAmB,SAAS;IACrC,MAAM,gBAAgB,WAAW,IAAI,gBAAgB,SAAS;IAE9D,IAAI,CAAC,eACH,WAAW,KAAK,eAAe;SAW/B,IARE,gBAAgB,MAAM,gBACpB,cAAc,MAAM,iBACrB,gBAAgB,WACf,cAAc,MAAM,WAAW,aAC/B,cAAc,MAAM,gBAAgB,cACpC,gBAAgB,iBAAiB,KAAA,KACjC,gBAAgB,eAAe,cAAc,MAAM,eAGrD,gBAAgB,KAAK,eAAe;GAG1C;GAEA,IAAI,WAAW,SAAS,GAGtB,CAAA,GAAA,qBAAA,QAAA,CAAQ,QAAQ,EAAE,SAAS,WAAW,GAAG,WAAW,OAAO;GAE7D,IAAI,gBAAgB,SAAS,GAC3B,OAAO;EAEX;CAEF,GAAG,CAAC,QAAQ,KAAK,CAAC;CAElB,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,IAAI,gBACF,CAAA,GAAA,qBAAA,QAAA,CAAQ,QAAQ,EAAE,SAAS,eAAe,GAAG,WAAW,OAAO;CAEnE,GAAG,CAAC,QAAQ,cAAc,CAAC;CAE3B,OAAO,iBAAA,GAAA,mBAAA,IAAA,CAACC,OAAAA,UAAD,EAAW,SAAmB,CAAA;AACvC"}
|
|
@@ -1,14 +1,75 @@
|
|
|
1
1
|
import { DehydratedState, HydrateOptions, OmitKeyof, QueryClient } from "@tanstack/query-core";
|
|
2
2
|
import { ComponentChildren } from "preact";
|
|
3
3
|
//#region src/HydrationBoundary.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The props accepted by `HydrationBoundary`.
|
|
6
|
+
*/
|
|
4
7
|
interface HydrationBoundaryProps {
|
|
8
|
+
/**
|
|
9
|
+
* The state to hydrate.
|
|
10
|
+
*/
|
|
5
11
|
state: DehydratedState | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Optional. Note: unlike `hydrate`, `mutations` cannot be set here.
|
|
14
|
+
*/
|
|
6
15
|
options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {
|
|
7
16
|
defaultOptions?: OmitKeyof<Exclude<HydrateOptions['defaultOptions'], undefined>, 'mutations'>;
|
|
8
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* The components to render — always rendered unconditionally, not gated on hydration. New queries are
|
|
20
|
+
* hydrated into the cache during render; for queries that already exist in the cache, only newer dehydrated
|
|
21
|
+
* data is hydrated, and that happens in an effect after commit, so `children` may render briefly before it
|
|
22
|
+
* lands.
|
|
23
|
+
*/
|
|
9
24
|
children?: ComponentChildren;
|
|
25
|
+
/**
|
|
26
|
+
* Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will be used.
|
|
27
|
+
*/
|
|
10
28
|
queryClient?: QueryClient;
|
|
11
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* `HydrationBoundary` adds a previously dehydrated state into the `queryClient` that would be returned by
|
|
32
|
+
* `useQueryClient()`. If the client already contains data, the new queries will be intelligently merged based on
|
|
33
|
+
* update timestamp.
|
|
34
|
+
*
|
|
35
|
+
* Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
|
|
36
|
+
*
|
|
37
|
+
* @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
|
|
38
|
+
* cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
|
|
39
|
+
* after commit.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* import { HydrationBoundary } from '@tanstack/preact-query'
|
|
44
|
+
*
|
|
45
|
+
* function App() {
|
|
46
|
+
* return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* Server-side prefetch handed off to the client via `dehydrate`:
|
|
52
|
+
* ```tsx
|
|
53
|
+
* import { HydrationBoundary, dehydrate, noop } from '@tanstack/preact-query'
|
|
54
|
+
*
|
|
55
|
+
* async function ServerComponent() {
|
|
56
|
+
* const queryClient = getQueryClient()
|
|
57
|
+
*
|
|
58
|
+
* await queryClient
|
|
59
|
+
* .query({
|
|
60
|
+
* queryKey: ['posts'],
|
|
61
|
+
* queryFn: fetchPosts,
|
|
62
|
+
* })
|
|
63
|
+
* .catch(noop)
|
|
64
|
+
*
|
|
65
|
+
* return (
|
|
66
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
67
|
+
* <Posts />
|
|
68
|
+
* </HydrationBoundary>
|
|
69
|
+
* )
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
12
73
|
declare const HydrationBoundary: ({ children, options, state, queryClient }: HydrationBoundaryProps) => import("preact").JSX.Element;
|
|
13
74
|
//#endregion
|
|
14
75
|
export { HydrationBoundary, HydrationBoundaryProps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HydrationBoundary.d.cts","names":[],"sources":["../../src/HydrationBoundary.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HydrationBoundary.d.cts","names":[],"sources":["../../src/HydrationBoundary.tsx"],"mappings":";;;;;;UAgBiB;;;;EAIf,OAAO;;;;EAIP,UAAU,UAAU;IAClB,iBAAiB,UACf,QAAQ;;;;;;;;EAUZ,WAAW;;;;EAIX,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8CH,sBAAqB,UAAA,SAAA,OAAA,eAK/B,4CAAsB,IAAA"}
|
|
@@ -1,14 +1,75 @@
|
|
|
1
1
|
import { DehydratedState, HydrateOptions, OmitKeyof, QueryClient } from "@tanstack/query-core";
|
|
2
2
|
import { ComponentChildren } from "preact";
|
|
3
3
|
//#region src/HydrationBoundary.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The props accepted by `HydrationBoundary`.
|
|
6
|
+
*/
|
|
4
7
|
interface HydrationBoundaryProps {
|
|
8
|
+
/**
|
|
9
|
+
* The state to hydrate.
|
|
10
|
+
*/
|
|
5
11
|
state: DehydratedState | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Optional. Note: unlike `hydrate`, `mutations` cannot be set here.
|
|
14
|
+
*/
|
|
6
15
|
options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {
|
|
7
16
|
defaultOptions?: OmitKeyof<Exclude<HydrateOptions['defaultOptions'], undefined>, 'mutations'>;
|
|
8
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* The components to render — always rendered unconditionally, not gated on hydration. New queries are
|
|
20
|
+
* hydrated into the cache during render; for queries that already exist in the cache, only newer dehydrated
|
|
21
|
+
* data is hydrated, and that happens in an effect after commit, so `children` may render briefly before it
|
|
22
|
+
* lands.
|
|
23
|
+
*/
|
|
9
24
|
children?: ComponentChildren;
|
|
25
|
+
/**
|
|
26
|
+
* Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will be used.
|
|
27
|
+
*/
|
|
10
28
|
queryClient?: QueryClient;
|
|
11
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* `HydrationBoundary` adds a previously dehydrated state into the `queryClient` that would be returned by
|
|
32
|
+
* `useQueryClient()`. If the client already contains data, the new queries will be intelligently merged based on
|
|
33
|
+
* update timestamp.
|
|
34
|
+
*
|
|
35
|
+
* Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
|
|
36
|
+
*
|
|
37
|
+
* @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
|
|
38
|
+
* cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
|
|
39
|
+
* after commit.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* import { HydrationBoundary } from '@tanstack/preact-query'
|
|
44
|
+
*
|
|
45
|
+
* function App() {
|
|
46
|
+
* return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* Server-side prefetch handed off to the client via `dehydrate`:
|
|
52
|
+
* ```tsx
|
|
53
|
+
* import { HydrationBoundary, dehydrate, noop } from '@tanstack/preact-query'
|
|
54
|
+
*
|
|
55
|
+
* async function ServerComponent() {
|
|
56
|
+
* const queryClient = getQueryClient()
|
|
57
|
+
*
|
|
58
|
+
* await queryClient
|
|
59
|
+
* .query({
|
|
60
|
+
* queryKey: ['posts'],
|
|
61
|
+
* queryFn: fetchPosts,
|
|
62
|
+
* })
|
|
63
|
+
* .catch(noop)
|
|
64
|
+
*
|
|
65
|
+
* return (
|
|
66
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
67
|
+
* <Posts />
|
|
68
|
+
* </HydrationBoundary>
|
|
69
|
+
* )
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
12
73
|
declare const HydrationBoundary: ({ children, options, state, queryClient }: HydrationBoundaryProps) => import("preact").JSX.Element;
|
|
13
74
|
//#endregion
|
|
14
75
|
export { HydrationBoundary, HydrationBoundaryProps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HydrationBoundary.d.ts","names":[],"sources":["../../src/HydrationBoundary.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HydrationBoundary.d.ts","names":[],"sources":["../../src/HydrationBoundary.tsx"],"mappings":";;;;;;UAgBiB;;;;EAIf,OAAO;;;;EAIP,UAAU,UAAU;IAClB,iBAAiB,UACf,QAAQ;;;;;;;;EAUZ,WAAW;;;;EAIX,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8CH,sBAAqB,UAAA,SAAA,OAAA,eAK/B,4CAAsB,IAAA"}
|
|
@@ -4,6 +4,49 @@ import { Fragment } from "preact";
|
|
|
4
4
|
import { useEffect, useMemo, useRef } from "preact/hooks";
|
|
5
5
|
import { jsx } from "preact/jsx-runtime";
|
|
6
6
|
//#region src/HydrationBoundary.tsx
|
|
7
|
+
/**
|
|
8
|
+
* `HydrationBoundary` adds a previously dehydrated state into the `queryClient` that would be returned by
|
|
9
|
+
* `useQueryClient()`. If the client already contains data, the new queries will be intelligently merged based on
|
|
10
|
+
* update timestamp.
|
|
11
|
+
*
|
|
12
|
+
* Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
|
|
13
|
+
*
|
|
14
|
+
* @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
|
|
15
|
+
* cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
|
|
16
|
+
* after commit.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { HydrationBoundary } from '@tanstack/preact-query'
|
|
21
|
+
*
|
|
22
|
+
* function App() {
|
|
23
|
+
* return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* Server-side prefetch handed off to the client via `dehydrate`:
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { HydrationBoundary, dehydrate, noop } from '@tanstack/preact-query'
|
|
31
|
+
*
|
|
32
|
+
* async function ServerComponent() {
|
|
33
|
+
* const queryClient = getQueryClient()
|
|
34
|
+
*
|
|
35
|
+
* await queryClient
|
|
36
|
+
* .query({
|
|
37
|
+
* queryKey: ['posts'],
|
|
38
|
+
* queryFn: fetchPosts,
|
|
39
|
+
* })
|
|
40
|
+
* .catch(noop)
|
|
41
|
+
*
|
|
42
|
+
* return (
|
|
43
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
44
|
+
* <Posts />
|
|
45
|
+
* </HydrationBoundary>
|
|
46
|
+
* )
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
7
50
|
const HydrationBoundary = ({ children, options = {}, state, queryClient }) => {
|
|
8
51
|
const client = useQueryClient(queryClient);
|
|
9
52
|
const optionsRef = useRef(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HydrationBoundary.js","names":[],"sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["import { hydrate } from '@tanstack/query-core'\nimport type {\n DehydratedState,\n HydrateOptions,\n OmitKeyof,\n QueryClient,\n} from '@tanstack/query-core'\nimport { Fragment } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useEffect, useMemo, useRef } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\n\nexport interface HydrationBoundaryProps {\n state: DehydratedState | null | undefined\n options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {\n defaultOptions?: OmitKeyof<\n Exclude<HydrateOptions['defaultOptions'], undefined>,\n 'mutations'\n >\n }\n children?: ComponentChildren\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = useRef(options)\n useEffect(() => {\n optionsRef.current = options\n })\n\n // This useMemo is for performance reasons only, everything inside it must\n // be safe to run in every render and code here should be read as \"in render\".\n //\n // This code needs to happen during the render phase, because after initial\n // SSR, hydration needs to happen _before_ children render. Also, if hydrating\n // during a transition, we want to hydrate as much as is safe in render so\n // we can prerender as much as possible.\n //\n // For any queries that already exist in the cache, we want to hold back on\n // hydrating until _after_ the render phase. The reason for this is that during\n // transitions, we don't want the existing queries and observers to update to\n // the new data on the current page, only _after_ the transition is committed.\n // If the transition is aborted, we will have hydrated any _new_ queries, but\n // we throw away the fresh data for any existing ones to avoid unexpectedly\n // updating the UI.\n const hydrationQueue: DehydratedState['queries'] | undefined = useMemo(() => {\n if (state) {\n if (typeof state !== 'object') {\n return\n }\n\n const queryCache = client.getQueryCache()\n // State is supplied from the outside and we might as well fail\n // gracefully if it has the wrong shape, so while we type `queries`\n // as required, we still provide a fallback.\n const queries = state.queries || []\n\n const newQueries: DehydratedState['queries'] = []\n const existingQueries: DehydratedState['queries'] = []\n for (const dehydratedQuery of queries) {\n const existingQuery = queryCache.get(dehydratedQuery.queryHash)\n\n if (!existingQuery) {\n newQueries.push(dehydratedQuery)\n } else {\n const hydrationIsNewer =\n dehydratedQuery.state.dataUpdatedAt >\n existingQuery.state.dataUpdatedAt ||\n (dehydratedQuery.promise &&\n existingQuery.state.status !== 'pending' &&\n existingQuery.state.fetchStatus !== 'fetching' &&\n dehydratedQuery.dehydratedAt !== undefined &&\n dehydratedQuery.dehydratedAt > existingQuery.state.dataUpdatedAt)\n\n if (hydrationIsNewer) {\n existingQueries.push(dehydratedQuery)\n }\n }\n }\n\n if (newQueries.length > 0) {\n // It's actually fine to call this with queries/state that already exists\n // in the cache, or is older. hydrate() is idempotent for queries.\n hydrate(client, { queries: newQueries }, optionsRef.current)\n }\n if (existingQueries.length > 0) {\n return existingQueries\n }\n }\n return undefined\n }, [client, state])\n\n useEffect(() => {\n if (hydrationQueue) {\n hydrate(client, { queries: hydrationQueue }, optionsRef.current)\n }\n }, [client, hydrationQueue])\n\n return <Fragment>{children}</Fragment>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HydrationBoundary.js","names":[],"sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["import { hydrate } from '@tanstack/query-core'\nimport type {\n DehydratedState,\n HydrateOptions,\n OmitKeyof,\n QueryClient,\n} from '@tanstack/query-core'\nimport { Fragment } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useEffect, useMemo, useRef } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\n\n/**\n * The props accepted by `HydrationBoundary`.\n */\nexport interface HydrationBoundaryProps {\n /**\n * The state to hydrate.\n */\n state: DehydratedState | null | undefined\n /**\n * Optional. Note: unlike `hydrate`, `mutations` cannot be set here.\n */\n options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {\n defaultOptions?: OmitKeyof<\n Exclude<HydrateOptions['defaultOptions'], undefined>,\n 'mutations'\n >\n }\n /**\n * The components to render — always rendered unconditionally, not gated on hydration. New queries are\n * hydrated into the cache during render; for queries that already exist in the cache, only newer dehydrated\n * data is hydrated, and that happens in an effect after commit, so `children` may render briefly before it\n * lands.\n */\n children?: ComponentChildren\n /**\n * Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will be used.\n */\n queryClient?: QueryClient\n}\n\n/**\n * `HydrationBoundary` adds a previously dehydrated state into the `queryClient` that would be returned by\n * `useQueryClient()`. If the client already contains data, the new queries will be intelligently merged based on\n * update timestamp.\n *\n * Note: Only `queries` can be dehydrated with an `HydrationBoundary`.\n *\n * @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the\n * cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect\n * after commit.\n *\n * @example\n * ```tsx\n * import { HydrationBoundary } from '@tanstack/preact-query'\n *\n * function App() {\n * return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>\n * }\n * ```\n *\n * @example\n * Server-side prefetch handed off to the client via `dehydrate`:\n * ```tsx\n * import { HydrationBoundary, dehydrate, noop } from '@tanstack/preact-query'\n *\n * async function ServerComponent() {\n * const queryClient = getQueryClient()\n *\n * await queryClient\n * .query({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * .catch(noop)\n *\n * return (\n * <HydrationBoundary state={dehydrate(queryClient)}>\n * <Posts />\n * </HydrationBoundary>\n * )\n * }\n * ```\n */\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = useRef(options)\n useEffect(() => {\n optionsRef.current = options\n })\n\n // This useMemo is for performance reasons only, everything inside it must\n // be safe to run in every render and code here should be read as \"in render\".\n //\n // This code needs to happen during the render phase, because after initial\n // SSR, hydration needs to happen _before_ children render. Also, if hydrating\n // during a transition, we want to hydrate as much as is safe in render so\n // we can prerender as much as possible.\n //\n // For any queries that already exist in the cache, we want to hold back on\n // hydrating until _after_ the render phase. The reason for this is that during\n // transitions, we don't want the existing queries and observers to update to\n // the new data on the current page, only _after_ the transition is committed.\n // If the transition is aborted, we will have hydrated any _new_ queries, but\n // we throw away the fresh data for any existing ones to avoid unexpectedly\n // updating the UI.\n const hydrationQueue: DehydratedState['queries'] | undefined = useMemo(() => {\n if (state) {\n if (typeof state !== 'object') {\n return\n }\n\n const queryCache = client.getQueryCache()\n // State is supplied from the outside and we might as well fail\n // gracefully if it has the wrong shape, so while we type `queries`\n // as required, we still provide a fallback.\n const queries = state.queries || []\n\n const newQueries: DehydratedState['queries'] = []\n const existingQueries: DehydratedState['queries'] = []\n for (const dehydratedQuery of queries) {\n const existingQuery = queryCache.get(dehydratedQuery.queryHash)\n\n if (!existingQuery) {\n newQueries.push(dehydratedQuery)\n } else {\n const hydrationIsNewer =\n dehydratedQuery.state.dataUpdatedAt >\n existingQuery.state.dataUpdatedAt ||\n (dehydratedQuery.promise &&\n existingQuery.state.status !== 'pending' &&\n existingQuery.state.fetchStatus !== 'fetching' &&\n dehydratedQuery.dehydratedAt !== undefined &&\n dehydratedQuery.dehydratedAt > existingQuery.state.dataUpdatedAt)\n\n if (hydrationIsNewer) {\n existingQueries.push(dehydratedQuery)\n }\n }\n }\n\n if (newQueries.length > 0) {\n // It's actually fine to call this with queries/state that already exists\n // in the cache, or is older. hydrate() is idempotent for queries.\n hydrate(client, { queries: newQueries }, optionsRef.current)\n }\n if (existingQueries.length > 0) {\n return existingQueries\n }\n }\n return undefined\n }, [client, state])\n\n useEffect(() => {\n if (hydrationQueue) {\n hydrate(client, { queries: hydrationQueue }, optionsRef.current)\n }\n }, [client, hydrationQueue])\n\n return <Fragment>{children}</Fragment>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,MAAa,qBAAqB,EAChC,UACA,UAAU,CAAC,GACX,OACA,kBAC4B;CAC5B,MAAM,SAAS,eAAe,WAAW;CAEzC,MAAM,aAAa,OAAO,OAAO;CACjC,gBAAgB;EACd,WAAW,UAAU;CACvB,CAAC;CAiBD,MAAM,iBAAyD,cAAc;EAC3E,IAAI,OAAO;GACT,IAAI,OAAO,UAAU,UACnB;GAGF,MAAM,aAAa,OAAO,cAAc;GAIxC,MAAM,UAAU,MAAM,WAAW,CAAC;GAElC,MAAM,aAAyC,CAAC;GAChD,MAAM,kBAA8C,CAAC;GACrD,KAAK,MAAM,mBAAmB,SAAS;IACrC,MAAM,gBAAgB,WAAW,IAAI,gBAAgB,SAAS;IAE9D,IAAI,CAAC,eACH,WAAW,KAAK,eAAe;SAW/B,IARE,gBAAgB,MAAM,gBACpB,cAAc,MAAM,iBACrB,gBAAgB,WACf,cAAc,MAAM,WAAW,aAC/B,cAAc,MAAM,gBAAgB,cACpC,gBAAgB,iBAAiB,KAAA,KACjC,gBAAgB,eAAe,cAAc,MAAM,eAGrD,gBAAgB,KAAK,eAAe;GAG1C;GAEA,IAAI,WAAW,SAAS,GAGtB,QAAQ,QAAQ,EAAE,SAAS,WAAW,GAAG,WAAW,OAAO;GAE7D,IAAI,gBAAgB,SAAS,GAC3B,OAAO;EAEX;CAEF,GAAG,CAAC,QAAQ,KAAK,CAAC;CAElB,gBAAgB;EACd,IAAI,gBACF,QAAQ,QAAQ,EAAE,SAAS,eAAe,GAAG,WAAW,OAAO;CAEnE,GAAG,CAAC,QAAQ,cAAc,CAAC;CAE3B,OAAO,oBAAC,UAAD,EAAW,SAAmB,CAAA;AACvC"}
|
|
@@ -3,7 +3,18 @@ let preact = require("preact");
|
|
|
3
3
|
let preact_hooks = require("preact/hooks");
|
|
4
4
|
//#region src/IsRestoringProvider.ts
|
|
5
5
|
const IsRestoringContext = (0, preact.createContext)(false);
|
|
6
|
+
/**
|
|
7
|
+
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
|
|
8
|
+
* check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
|
|
9
|
+
* race conditions between the restore and mounting queries.
|
|
10
|
+
*
|
|
11
|
+
* @returns `true` while a persisted client is being restored, `false` otherwise.
|
|
12
|
+
*/
|
|
6
13
|
const useIsRestoring = () => (0, preact_hooks.useContext)(IsRestoringContext);
|
|
14
|
+
/**
|
|
15
|
+
* The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
|
|
16
|
+
* being restored, read by `useIsRestoring`.
|
|
17
|
+
*/
|
|
7
18
|
const IsRestoringProvider = IsRestoringContext.Provider;
|
|
8
19
|
//#endregion
|
|
9
20
|
exports.IsRestoringProvider = IsRestoringProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IsRestoringProvider.cjs","names":["createContext","useContext"],"sources":["../../src/IsRestoringProvider.ts"],"sourcesContent":["import { createContext } from 'preact'\nimport { useContext } from 'preact/hooks'\n\nconst IsRestoringContext = createContext(false)\n\nexport const useIsRestoring = () => useContext(IsRestoringContext)\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"mappings":";;;;AAGA,MAAM,sBAAA,GAAqBA,OAAAA,cAAAA,CAAc,KAAK
|
|
1
|
+
{"version":3,"file":"IsRestoringProvider.cjs","names":["createContext","useContext"],"sources":["../../src/IsRestoringProvider.ts"],"sourcesContent":["import { createContext } from 'preact'\nimport { useContext } from 'preact/hooks'\n\nconst IsRestoringContext = createContext(false)\n\n/**\n * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to\n * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid\n * race conditions between the restore and mounting queries.\n *\n * @returns `true` while a persisted client is being restored, `false` otherwise.\n */\nexport const useIsRestoring = () => useContext(IsRestoringContext)\n\n/**\n * The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently\n * being restored, read by `useIsRestoring`.\n */\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"mappings":";;;;AAGA,MAAM,sBAAA,GAAqBA,OAAAA,cAAAA,CAAc,KAAK;;;;;;;;AAS9C,MAAa,wBAAA,GAAuBC,aAAAA,WAAAA,CAAW,kBAAkB;;;;;AAMjE,MAAa,sBAAsB,mBAAmB"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
//#region src/IsRestoringProvider.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
|
|
4
|
+
* check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
|
|
5
|
+
* race conditions between the restore and mounting queries.
|
|
6
|
+
*
|
|
7
|
+
* @returns `true` while a persisted client is being restored, `false` otherwise.
|
|
8
|
+
*/
|
|
2
9
|
declare const useIsRestoring: () => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
|
|
12
|
+
* being restored, read by `useIsRestoring`.
|
|
13
|
+
*/
|
|
3
14
|
declare const IsRestoringProvider: import("preact").Provider<boolean>;
|
|
4
15
|
//#endregion
|
|
5
16
|
export { IsRestoringProvider, useIsRestoring };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IsRestoringProvider.d.cts","names":[],"sources":["../../src/IsRestoringProvider.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IsRestoringProvider.d.cts","names":[],"sources":["../../src/IsRestoringProvider.ts"],"mappings":";;;;;;;;cAYa;;;;;cAMA,sCAAmB"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
//#region src/IsRestoringProvider.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
|
|
4
|
+
* check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
|
|
5
|
+
* race conditions between the restore and mounting queries.
|
|
6
|
+
*
|
|
7
|
+
* @returns `true` while a persisted client is being restored, `false` otherwise.
|
|
8
|
+
*/
|
|
2
9
|
declare const useIsRestoring: () => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
|
|
12
|
+
* being restored, read by `useIsRestoring`.
|
|
13
|
+
*/
|
|
3
14
|
declare const IsRestoringProvider: import("preact").Provider<boolean>;
|
|
4
15
|
//#endregion
|
|
5
16
|
export { IsRestoringProvider, useIsRestoring };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IsRestoringProvider.d.ts","names":[],"sources":["../../src/IsRestoringProvider.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IsRestoringProvider.d.ts","names":[],"sources":["../../src/IsRestoringProvider.ts"],"mappings":";;;;;;;;cAYa;;;;;cAMA,sCAAmB"}
|
|
@@ -2,7 +2,18 @@ import { createContext } from "preact";
|
|
|
2
2
|
import { useContext } from "preact/hooks";
|
|
3
3
|
//#region src/IsRestoringProvider.ts
|
|
4
4
|
const IsRestoringContext = createContext(false);
|
|
5
|
+
/**
|
|
6
|
+
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
|
|
7
|
+
* check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
|
|
8
|
+
* race conditions between the restore and mounting queries.
|
|
9
|
+
*
|
|
10
|
+
* @returns `true` while a persisted client is being restored, `false` otherwise.
|
|
11
|
+
*/
|
|
5
12
|
const useIsRestoring = () => useContext(IsRestoringContext);
|
|
13
|
+
/**
|
|
14
|
+
* The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
|
|
15
|
+
* being restored, read by `useIsRestoring`.
|
|
16
|
+
*/
|
|
6
17
|
const IsRestoringProvider = IsRestoringContext.Provider;
|
|
7
18
|
//#endregion
|
|
8
19
|
export { IsRestoringProvider, useIsRestoring };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IsRestoringProvider.js","names":[],"sources":["../../src/IsRestoringProvider.ts"],"sourcesContent":["import { createContext } from 'preact'\nimport { useContext } from 'preact/hooks'\n\nconst IsRestoringContext = createContext(false)\n\nexport const useIsRestoring = () => useContext(IsRestoringContext)\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"mappings":";;;AAGA,MAAM,qBAAqB,cAAc,KAAK
|
|
1
|
+
{"version":3,"file":"IsRestoringProvider.js","names":[],"sources":["../../src/IsRestoringProvider.ts"],"sourcesContent":["import { createContext } from 'preact'\nimport { useContext } from 'preact/hooks'\n\nconst IsRestoringContext = createContext(false)\n\n/**\n * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to\n * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid\n * race conditions between the restore and mounting queries.\n *\n * @returns `true` while a persisted client is being restored, `false` otherwise.\n */\nexport const useIsRestoring = () => useContext(IsRestoringContext)\n\n/**\n * The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently\n * being restored, read by `useIsRestoring`.\n */\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"mappings":";;;AAGA,MAAM,qBAAqB,cAAc,KAAK;;;;;;;;AAS9C,MAAa,uBAAuB,WAAW,kBAAkB;;;;;AAMjE,MAAa,sBAAsB,mBAAmB"}
|
|
@@ -3,13 +3,43 @@ let preact = require("preact");
|
|
|
3
3
|
let preact_hooks = require("preact/hooks");
|
|
4
4
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
5
5
|
//#region src/QueryClientProvider.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.
|
|
8
|
+
*/
|
|
6
9
|
const QueryClientContext = (0, preact.createContext)(void 0);
|
|
10
|
+
/**
|
|
11
|
+
* The `useQueryClient` hook returns the current `QueryClient` instance.
|
|
12
|
+
*
|
|
13
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
14
|
+
* be used.
|
|
15
|
+
* @returns The current `QueryClient` instance.
|
|
16
|
+
* @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
|
|
17
|
+
*/
|
|
7
18
|
const useQueryClient = (queryClient) => {
|
|
8
19
|
const client = (0, preact_hooks.useContext)(QueryClientContext);
|
|
9
20
|
if (queryClient) return queryClient;
|
|
10
21
|
if (!client) throw new Error("No QueryClient set, use QueryClientProvider to set one");
|
|
11
22
|
return client;
|
|
12
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also
|
|
26
|
+
* calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
|
|
27
|
+
* focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
|
|
28
|
+
* comes back online).
|
|
29
|
+
*
|
|
30
|
+
* @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* import { QueryClient, QueryClientProvider } from '@tanstack/preact-query'
|
|
35
|
+
*
|
|
36
|
+
* const queryClient = new QueryClient()
|
|
37
|
+
*
|
|
38
|
+
* function App() {
|
|
39
|
+
* return <QueryClientProvider client={queryClient}>...</QueryClientProvider>
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
13
43
|
const QueryClientProvider = ({ client, children }) => {
|
|
14
44
|
(0, preact_hooks.useEffect)(() => {
|
|
15
45
|
client.mount();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryClientProvider.cjs","names":["createContext","useContext"],"sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["import type { QueryClient } from '@tanstack/query-core'\nimport { createContext } from 'preact'\nimport type { ComponentChildren, VNode } from 'preact'\nimport { useContext, useEffect } from 'preact/hooks'\n\nexport const QueryClientContext = createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: ComponentChildren\n}\n\nexport const QueryClientProvider = ({\n client,\n children,\n}: QueryClientProviderProps): VNode => {\n useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n return (\n <QueryClientContext.Provider value={client}>\n {children}\n </QueryClientContext.Provider>\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryClientProvider.cjs","names":["createContext","useContext"],"sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["import type { QueryClient } from '@tanstack/query-core'\nimport { createContext } from 'preact'\nimport type { ComponentChildren, VNode } from 'preact'\nimport { useContext, useEffect } from 'preact/hooks'\n\n/**\n * The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.\n */\nexport const QueryClientContext = createContext<QueryClient | undefined>(\n undefined,\n)\n\n/**\n * The `useQueryClient` hook returns the current `QueryClient` instance.\n *\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current `QueryClient` instance.\n * @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.\n */\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\n/**\n * The props accepted by `QueryClientProvider`.\n */\nexport type QueryClientProviderProps = {\n /**\n * **Required**\n *\n * The `QueryClient` instance to provide.\n */\n client: QueryClient\n /**\n * The components that get access to the provided `QueryClient`.\n */\n children?: ComponentChildren\n}\n\n/**\n * Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also\n * calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to\n * focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or\n * comes back online).\n *\n * @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.\n *\n * @example\n * ```tsx\n * import { QueryClient, QueryClientProvider } from '@tanstack/preact-query'\n *\n * const queryClient = new QueryClient()\n *\n * function App() {\n * return <QueryClientProvider client={queryClient}>...</QueryClientProvider>\n * }\n * ```\n */\nexport const QueryClientProvider = ({\n client,\n children,\n}: QueryClientProviderProps): VNode => {\n useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n return (\n <QueryClientContext.Provider value={client}>\n {children}\n </QueryClientContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;AAQA,MAAa,sBAAA,GAAqBA,OAAAA,cAAAA,CAChC,KAAA,CACF;;;;;;;;;AAUA,MAAa,kBAAkB,gBAA8B;CAC3D,MAAM,UAAA,GAASC,aAAAA,WAAAA,CAAW,kBAAkB;CAE5C,IAAI,aACF,OAAO;CAGT,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,wDAAwD;CAG1E,OAAO;AACT;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,uBAAuB,EAClC,QACA,eACqC;CACrC,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,OAAO,MAAM;EACb,aAAa;GACX,OAAO,QAAQ;EACjB;CACF,GAAG,CAAC,MAAM,CAAC;CAEX,OACE,iBAAA,GAAA,mBAAA,IAAA,CAAC,mBAAmB,UAApB;EAA6B,OAAO;EACjC;CAC0B,CAAA;AAEjC"}
|