@tanstack/react-query 5.102.8 → 5.103.0
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 +44 -1
- 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 +44 -1
- 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 +76 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +77 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +77 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +76 -0
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +173 -0
- package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +173 -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 +55 -0
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +55 -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 +175 -0
- package/build/legacy/queryOptions.d.cts.map +1 -1
- package/build/legacy/queryOptions.d.ts +175 -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 +292 -0
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +292 -0
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +36 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +36 -0
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +36 -0
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +36 -0
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +172 -0
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +172 -0
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +172 -0
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +172 -0
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +94 -0
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +94 -0
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +94 -0
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +94 -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 +130 -0
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +165 -2
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +165 -2
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +130 -0
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +246 -0
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +246 -0
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +86 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +86 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +86 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +86 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +320 -2
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +320 -2
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +67 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +67 -0
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +67 -0
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +67 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/modern/HydrationBoundary.cjs +44 -1
- 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 +44 -1
- 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 +76 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +77 -0
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +77 -0
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +76 -0
- package/build/modern/QueryErrorResetBoundary.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +173 -0
- package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +173 -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 +55 -0
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +55 -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 +175 -0
- package/build/modern/queryOptions.d.cts.map +1 -1
- package/build/modern/queryOptions.d.ts +175 -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 +292 -0
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +292 -0
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +36 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +36 -0
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +36 -0
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +36 -0
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +172 -0
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +172 -0
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +172 -0
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +172 -0
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +94 -0
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +94 -0
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +94 -0
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +94 -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 +130 -0
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +165 -2
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +165 -2
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +130 -0
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +246 -0
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +246 -0
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +86 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +86 -0
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +86 -0
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +86 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +320 -2
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +320 -2
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +67 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +67 -0
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +67 -0
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +67 -0
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/build/query-codemods/eslint.config.js +7 -0
- package/build/query-codemods/root.eslint.config.js +45 -0
- package/package.json +11 -11
- package/src/HydrationBoundary.tsx +61 -1
- package/src/IsRestoringProvider.ts +12 -0
- package/src/QueryClientProvider.tsx +41 -0
- package/src/QueryErrorResetBoundary.tsx +89 -0
- package/src/infiniteQueryOptions.ts +173 -0
- package/src/mutationOptions.ts +55 -0
- package/src/queryOptions.ts +175 -0
- package/src/types.ts +228 -2
- package/src/useInfiniteQuery.ts +292 -0
- package/src/useIsFetching.ts +36 -0
- package/src/useMutation.ts +172 -0
- package/src/useMutationState.ts +94 -0
- package/src/usePrefetchInfiniteQuery.tsx +44 -0
- package/src/usePrefetchQuery.tsx +35 -0
- package/src/useQueries.ts +165 -2
- package/src/useQuery.ts +246 -0
- package/src/useSuspenseInfiniteQuery.ts +86 -0
- package/src/useSuspenseQueries.ts +320 -2
- package/src/useSuspenseQuery.ts +67 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQueries.d.ts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C
|
|
1
|
+
{"version":3,"file":"useSuspenseQueries.d.ts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,2BACN,oBAEE,iBAAiB,YACX,UAAU,2BAA2B,SACzC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,2BAA2B,YACrC,cAEN,uBAAuB,IACrB,IAGA,UAAU,MACN,8BACQ,oBACA,cACA,aACA,cAGV,MACE,wBAAwB,cAAc,QAAQ,OAAO,cAGvD,MAAM;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,0BACN,oBAEE,iBAAiB,YACX,UAAU,0BAA0B,SACxC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,0BAA0B,YACpC,iBAEH,WAAW,IAAI,0BAA0B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwKxC,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBACiB,uBAAuB,sBACpB,WAAW,IAAI,2BAA2B,EAAE;;;;;EAKhE,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0Ha,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBAAsB,uBAAuB;;;;;EAK7C,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQueries.js","names":[],"sources":["../../src/useSuspenseQueries.ts"],"sourcesContent":["'use client'\nimport { skipToken } from '@tanstack/query-core'\nimport { useQueries } from './useQueries'\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport type {\n DefaultError,\n QueryClient,\n QueryFunction,\n ThrowOnError,\n} from '@tanstack/query-core'\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetUseSuspenseQueryOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseSuspenseQueryOptions<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseSuspenseQueryOptions<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseSuspenseQueryOptions<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseSuspenseQueryOptions<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n : T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryOptions<\n TQueryFnData,\n TError,\n TQueryFnData,\n TQueryKey\n >\n : // Fallback\n UseSuspenseQueryOptions\n\ntype GetUseSuspenseQueryResult<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? UseSuspenseQueryResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseSuspenseQueryResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseSuspenseQueryResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? UseSuspenseQueryResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? UseSuspenseQueryResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseSuspenseQueryResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryResult<\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryResult<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n UseSuspenseQueryResult\n\n/**\n * SuspenseQueriesOptions reducer recursively unwraps function arguments to infer/enforce type param\n */\nexport type SuspenseQueriesOptions<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseSuspenseQueryOptions>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseSuspenseQueryOptions<Head>]\n : T extends [infer Head, ...infer Tails]\n ? SuspenseQueriesOptions<\n [...Tails],\n [...TResults, GetUseSuspenseQueryOptions<Head>],\n [...TDepth, 1]\n >\n : Array<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogeneous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n UseSuspenseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n >\n : // Fallback\n Array<UseSuspenseQueryOptions>\n\n/**\n * SuspenseQueriesResults reducer recursively maps type param to results\n */\nexport type SuspenseQueriesResults<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseSuspenseQueryResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseSuspenseQueryResult<Head>]\n : T extends [infer Head, ...infer Tails]\n ? SuspenseQueriesResults<\n [...Tails],\n [...TResults, GetUseSuspenseQueryResult<Head>],\n [...TDepth, 1]\n >\n : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]> }\n\nexport function useSuspenseQueries<\n T extends Array<any>,\n TCombinedResult = SuspenseQueriesResults<T>,\n>(\n options: {\n queries:\n | readonly [...SuspenseQueriesOptions<T>]\n | readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]> }]\n combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult\n\nexport function useSuspenseQueries<\n T extends Array<any>,\n TCombinedResult = SuspenseQueriesResults<T>,\n>(\n options: {\n queries: readonly [...SuspenseQueriesOptions<T>]\n combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult\n\nexport function useSuspenseQueries(options: any, queryClient?: QueryClient) {\n return useQueries(\n {\n ...options,\n queries: options.queries.map((query: any) => {\n if (process.env.NODE_ENV !== 'production') {\n if (query.queryFn === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQueries')\n }\n }\n\n return {\n ...query,\n suspense: true,\n throwOnError: defaultThrowOnError,\n enabled: true,\n placeholderData: undefined,\n }\n }),\n },\n queryClient,\n )\n}\n"],"mappings":";;;;;AA4LA,SAAgB,mBAAmB,SAAc,aAA2B;CAC1E,OAAO,WACL;EACE,GAAG;EACH,SAAS,QAAQ,QAAQ,KAAK,UAAe;GAC3C,IAAI,QAAQ,IAAI,aAAa,cACvB;QAAA,MAAM,YAAY,WACpB,QAAQ,MAAM,iDAAiD;GAAA;GAInE,OAAO;IACL,GAAG;IACH,UAAU;IACV,cAAc;IACd,SAAS;IACT,iBAAiB,KAAA;GACnB;EACF,CAAC;CACH,GACA,WACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useSuspenseQueries.js","names":[],"sources":["../../src/useSuspenseQueries.ts"],"sourcesContent":["'use client'\nimport { skipToken } from '@tanstack/query-core'\nimport { useQueries } from './useQueries'\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport type {\n DefaultError,\n QueryClient,\n QueryFunction,\n ThrowOnError,\n} from '@tanstack/query-core'\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetUseSuspenseQueryOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseSuspenseQueryOptions<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseSuspenseQueryOptions<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseSuspenseQueryOptions<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseSuspenseQueryOptions<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n : T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryOptions<\n TQueryFnData,\n TError,\n TQueryFnData,\n TQueryKey\n >\n : // Fallback\n UseSuspenseQueryOptions\n\ntype GetUseSuspenseQueryResult<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? UseSuspenseQueryResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseSuspenseQueryResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseSuspenseQueryResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? UseSuspenseQueryResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? UseSuspenseQueryResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseSuspenseQueryResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryResult<\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryResult<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n UseSuspenseQueryResult\n\n/**\n * The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every\n * entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)\n * is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a\n * single homogeneous {@link UseSuspenseQueryOptions} type.\n *\n * @template T - The type of the `queries` array as written at the call site.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type SuspenseQueriesOptions<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseSuspenseQueryOptions>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseSuspenseQueryOptions<Head>]\n : T extends [infer Head, ...infer Tails]\n ? SuspenseQueriesOptions<\n [...Tails],\n [...TResults, GetUseSuspenseQueryOptions<Head>],\n [...TDepth, 1]\n >\n : Array<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogeneous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n UseSuspenseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n >\n : // Fallback\n Array<UseSuspenseQueryOptions>\n\n/**\n * The result type returned by `useSuspenseQueries`, when no `combine` is provided. Mirrors\n * {@link SuspenseQueriesOptions}: each tuple element's result type is inferred individually, up to 20 elements.\n * A non-tuple array is mapped per-element instead, still inferring each entry individually; only past 20\n * elements does this fall back to a single homogeneous {@link UseSuspenseQueryResult} type.\n *\n * @template T - The type of the `queries` array, as inferred by {@link SuspenseQueriesOptions}.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type SuspenseQueriesResults<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseSuspenseQueryResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseSuspenseQueryResult<Head>]\n : T extends [infer Head, ...infer Tails]\n ? SuspenseQueriesResults<\n [...Tails],\n [...TResults, GetUseSuspenseQueryResult<Head>],\n [...TDepth, 1]\n >\n : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]> }\n\n/**\n * The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`\n * option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.\n *\n * @param options - The `queries` array to run in Suspense, and an optional `combine` function.\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be\n * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived\n * flags set accordingly).\n *\n * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone\n * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid\n * this, make sure to set a high enough `staleTime`. Cancellation does not work.\n *\n * @example\n * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is\n * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.\n * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/react-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * // Every result is guaranteed to be defined — no per-query `isPending` check needed.\n * const postQueries = useSuspenseQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * })\n *\n * return (\n * <ul>\n * {postQueries.map((query) => (\n * <li key={query.data.id}>{query.data.title}</li>\n * ))}\n * </ul>\n * )\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts ids={[1, 2, 3]} />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n *\n * @example\n * Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so\n * they fetch in parallel rather than suspending one after another:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/react-query'\n *\n * function Dashboard() {\n * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({\n * queries: [\n * { queryKey: ['users'], queryFn: fetchUsers },\n * { queryKey: ['teams'], queryFn: fetchTeams },\n * { queryKey: ['projects'], queryFn: fetchProjects },\n * ],\n * })\n *\n * return (\n * <div>\n * <UserList users={usersQuery.data} />\n * <TeamList teams={teamsQuery.data} />\n * <ProjectList projects={projectsQuery.data} />\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Suspense fallback={<h1>Loading dashboard...</h1>}>\n * <Dashboard />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n *\n * @example\n * `combine`s the results into a single boolean, so `Refresh` only re-renders when that boolean changes,\n * not on every individual query update. This overload is the only one that accepts `combine`:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/react-query'\n *\n * function Refresh() {\n * const anyFetching = useSuspenseQueries({\n * queries: [\n * { queryKey: ['users'], queryFn: fetchUsers },\n * { queryKey: ['teams'], queryFn: fetchTeams },\n * ],\n * combine: (results) => results.some((result) => result.isFetching),\n * })\n *\n * return anyFetching ? <span>Refreshing…</span> : null\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Suspense fallback={<h1>Loading dashboard...</h1>}>\n * <Refresh />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n */\nexport function useSuspenseQueries<\n T extends Array<any>,\n TCombinedResult = SuspenseQueriesResults<T>,\n>(\n options: {\n /**\n * An array with query option objects identical to `useSuspenseQuery`.\n */\n queries:\n | readonly [...SuspenseQueriesOptions<T>]\n | readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]> }]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult\n\n/**\n * The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`\n * option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.\n *\n * @param options - The `queries` array to run in Suspense, and an optional `combine` function.\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be\n * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived\n * flags set accordingly).\n *\n * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone\n * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid\n * this, make sure to set a high enough `staleTime`. Cancellation does not work.\n *\n * @example\n * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is\n * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.\n * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/react-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * // Every result is guaranteed to be defined — no per-query `isPending` check needed.\n * const postQueries = useSuspenseQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * })\n *\n * return (\n * <ul>\n * {postQueries.map((query) => (\n * <li key={query.data.id}>{query.data.title}</li>\n * ))}\n * </ul>\n * )\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts ids={[1, 2, 3]} />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n *\n * @example\n * Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so\n * they fetch in parallel rather than suspending one after another:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/react-query'\n *\n * function Dashboard() {\n * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({\n * queries: [\n * { queryKey: ['users'], queryFn: fetchUsers },\n * { queryKey: ['teams'], queryFn: fetchTeams },\n * { queryKey: ['projects'], queryFn: fetchProjects },\n * ],\n * })\n *\n * return (\n * <div>\n * <UserList users={usersQuery.data} />\n * <TeamList teams={teamsQuery.data} />\n * <ProjectList projects={projectsQuery.data} />\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Suspense fallback={<h1>Loading dashboard...</h1>}>\n * <Dashboard />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n */\nexport function useSuspenseQueries<\n T extends Array<any>,\n TCombinedResult = SuspenseQueriesResults<T>,\n>(\n options: {\n /**\n * An array with query option objects identical to `useSuspenseQuery`.\n */\n queries: readonly [...SuspenseQueriesOptions<T>]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult\n\nexport function useSuspenseQueries(options: any, queryClient?: QueryClient) {\n return useQueries(\n {\n ...options,\n queries: options.queries.map((query: any) => {\n if (process.env.NODE_ENV !== 'production') {\n if (query.queryFn === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQueries')\n }\n }\n\n return {\n ...query,\n suspense: true,\n throwOnError: defaultThrowOnError,\n enabled: true,\n placeholderData: undefined,\n }\n }),\n },\n queryClient,\n )\n}\n"],"mappings":";;;;;AA0fA,SAAgB,mBAAmB,SAAc,aAA2B;CAC1E,OAAO,WACL;EACE,GAAG;EACH,SAAS,QAAQ,QAAQ,KAAK,UAAe;GAC3C,IAAI,QAAQ,IAAI,aAAa,cACvB;QAAA,MAAM,YAAY,WACpB,QAAQ,MAAM,iDAAiD;GAAA;GAInE,OAAO;IACL,GAAG;IACH,UAAU;IACV,cAAc;IACd,SAAS;IACT,iBAAiB,KAAA;GACnB;EACF,CAAC;CACH,GACA,WACF;AACF"}
|
|
@@ -4,6 +4,73 @@ const require_suspense = require("./suspense.cjs");
|
|
|
4
4
|
const require_useBaseQuery = require("./useBaseQuery.cjs");
|
|
5
5
|
let _tanstack_query_core = require("@tanstack/query-core");
|
|
6
6
|
//#region src/useSuspenseQuery.ts
|
|
7
|
+
/**
|
|
8
|
+
* The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and
|
|
9
|
+
* `placeholderData` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a "disabled" state.
|
|
10
|
+
*
|
|
11
|
+
* Caveat: cancellation does not work.
|
|
12
|
+
*
|
|
13
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
14
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
15
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
16
|
+
* fetch in parallel.
|
|
17
|
+
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
18
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
19
|
+
* be used.
|
|
20
|
+
* @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`
|
|
21
|
+
* is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* The query error is thrown if the fetch fails and no cached data exists yet, so an error boundary is
|
|
25
|
+
* required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
|
|
26
|
+
* Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
|
|
27
|
+
* ```tsx
|
|
28
|
+
* import { Suspense } from 'react'
|
|
29
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
30
|
+
* import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-query'
|
|
31
|
+
*
|
|
32
|
+
* function Posts() {
|
|
33
|
+
* // `data` is guaranteed to be defined here — no `isPending` check needed.
|
|
34
|
+
* const { data, isFetching } = useSuspenseQuery({
|
|
35
|
+
* queryKey: ['posts'],
|
|
36
|
+
* queryFn: fetchPosts,
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* return (
|
|
40
|
+
* <div>
|
|
41
|
+
* <h1>Posts {isFetching ? '(refreshing...)' : null}</h1>
|
|
42
|
+
* <ul>
|
|
43
|
+
* {data.map((post) => (
|
|
44
|
+
* <li key={post.id}>{post.title}</li>
|
|
45
|
+
* ))}
|
|
46
|
+
* </ul>
|
|
47
|
+
* </div>
|
|
48
|
+
* )
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* function App() {
|
|
52
|
+
* return (
|
|
53
|
+
* <QueryErrorResetBoundary>
|
|
54
|
+
* {({ reset }) => (
|
|
55
|
+
* <ErrorBoundary
|
|
56
|
+
* onReset={reset}
|
|
57
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
58
|
+
* <div>
|
|
59
|
+
* There was an error!
|
|
60
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
61
|
+
* </div>
|
|
62
|
+
* )}
|
|
63
|
+
* >
|
|
64
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
65
|
+
* <Posts />
|
|
66
|
+
* </Suspense>
|
|
67
|
+
* </ErrorBoundary>
|
|
68
|
+
* )}
|
|
69
|
+
* </QueryErrorResetBoundary>
|
|
70
|
+
* )
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
7
74
|
function useSuspenseQuery(options, queryClient) {
|
|
8
75
|
if (process.env.NODE_ENV !== "production") {
|
|
9
76
|
if (options.queryFn === _tanstack_query_core.skipToken) console.error("skipToken is not allowed for useSuspenseQuery");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.cjs","names":["skipToken","useBaseQuery","defaultThrowOnError","QueryObserver"],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["'use client'\nimport { QueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\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.cjs","names":["skipToken","useBaseQuery","defaultThrowOnError","QueryObserver"],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["'use client'\nimport { QueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\n/**\n * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and\n * `placeholderData` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a \"disabled\" state.\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 * The query error is thrown if the fetch fails and no cached data exists yet, so an error boundary is\n * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.\n * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-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 ? '(refreshing...)' : null}</h1>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,iBAMd,SACA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoBA,qBAAAA,WAC/B,QAAQ,MAAM,+CAA+C;CAAA;CAIjE,OAAOC,qBAAAA,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAcC,iBAAAA;EACd,iBAAiB,KAAA;CACnB,GACAC,qBAAAA,eACA,WACF;AACF"}
|
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
import { UseSuspenseQueryOptions, UseSuspenseQueryResult } from "./types.cjs";
|
|
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` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a "disabled" state.
|
|
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
|
+
* The query error is thrown if the fetch fails and no cached data exists yet, so an error boundary is
|
|
22
|
+
* required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
|
|
23
|
+
* Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
|
|
24
|
+
* ```tsx
|
|
25
|
+
* import { Suspense } from 'react'
|
|
26
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
27
|
+
* import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-query'
|
|
28
|
+
*
|
|
29
|
+
* function Posts() {
|
|
30
|
+
* // `data` is guaranteed to be defined here — no `isPending` check needed.
|
|
31
|
+
* const { data, isFetching } = useSuspenseQuery({
|
|
32
|
+
* queryKey: ['posts'],
|
|
33
|
+
* queryFn: fetchPosts,
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <h1>Posts {isFetching ? '(refreshing...)' : null}</h1>
|
|
39
|
+
* <ul>
|
|
40
|
+
* {data.map((post) => (
|
|
41
|
+
* <li key={post.id}>{post.title}</li>
|
|
42
|
+
* ))}
|
|
43
|
+
* </ul>
|
|
44
|
+
* </div>
|
|
45
|
+
* )
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* function App() {
|
|
49
|
+
* return (
|
|
50
|
+
* <QueryErrorResetBoundary>
|
|
51
|
+
* {({ reset }) => (
|
|
52
|
+
* <ErrorBoundary
|
|
53
|
+
* onReset={reset}
|
|
54
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
55
|
+
* <div>
|
|
56
|
+
* There was an error!
|
|
57
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
58
|
+
* </div>
|
|
59
|
+
* )}
|
|
60
|
+
* >
|
|
61
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
62
|
+
* <Posts />
|
|
63
|
+
* </Suspense>
|
|
64
|
+
* </ErrorBoundary>
|
|
65
|
+
* )}
|
|
66
|
+
* </QueryErrorResetBoundary>
|
|
67
|
+
* )
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
4
71
|
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
72
|
//#endregion
|
|
6
73
|
export { useSuspenseQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.d.cts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.d.cts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0EgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,wBAAwB,cAAc,QAAQ,OAAO,YAC9D,cAAc,cACb,uBAAuB,OAAO"}
|
|
@@ -1,6 +1,73 @@
|
|
|
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` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a "disabled" state.
|
|
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
|
+
* The query error is thrown if the fetch fails and no cached data exists yet, so an error boundary is
|
|
22
|
+
* required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
|
|
23
|
+
* Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
|
|
24
|
+
* ```tsx
|
|
25
|
+
* import { Suspense } from 'react'
|
|
26
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
27
|
+
* import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-query'
|
|
28
|
+
*
|
|
29
|
+
* function Posts() {
|
|
30
|
+
* // `data` is guaranteed to be defined here — no `isPending` check needed.
|
|
31
|
+
* const { data, isFetching } = useSuspenseQuery({
|
|
32
|
+
* queryKey: ['posts'],
|
|
33
|
+
* queryFn: fetchPosts,
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <h1>Posts {isFetching ? '(refreshing...)' : null}</h1>
|
|
39
|
+
* <ul>
|
|
40
|
+
* {data.map((post) => (
|
|
41
|
+
* <li key={post.id}>{post.title}</li>
|
|
42
|
+
* ))}
|
|
43
|
+
* </ul>
|
|
44
|
+
* </div>
|
|
45
|
+
* )
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* function App() {
|
|
49
|
+
* return (
|
|
50
|
+
* <QueryErrorResetBoundary>
|
|
51
|
+
* {({ reset }) => (
|
|
52
|
+
* <ErrorBoundary
|
|
53
|
+
* onReset={reset}
|
|
54
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
55
|
+
* <div>
|
|
56
|
+
* There was an error!
|
|
57
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
58
|
+
* </div>
|
|
59
|
+
* )}
|
|
60
|
+
* >
|
|
61
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
62
|
+
* <Posts />
|
|
63
|
+
* </Suspense>
|
|
64
|
+
* </ErrorBoundary>
|
|
65
|
+
* )}
|
|
66
|
+
* </QueryErrorResetBoundary>
|
|
67
|
+
* )
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
4
71
|
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
72
|
//#endregion
|
|
6
73
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0EgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,wBAAwB,cAAc,QAAQ,OAAO,YAC9D,cAAc,cACb,uBAAuB,OAAO"}
|
|
@@ -3,6 +3,73 @@ import { defaultThrowOnError } from "./suspense.js";
|
|
|
3
3
|
import { useBaseQuery } from "./useBaseQuery.js";
|
|
4
4
|
import { QueryObserver, skipToken } from "@tanstack/query-core";
|
|
5
5
|
//#region src/useSuspenseQuery.ts
|
|
6
|
+
/**
|
|
7
|
+
* The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and
|
|
8
|
+
* `placeholderData` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a "disabled" state.
|
|
9
|
+
*
|
|
10
|
+
* Caveat: cancellation does not work.
|
|
11
|
+
*
|
|
12
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
13
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
14
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
15
|
+
* fetch in parallel.
|
|
16
|
+
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
17
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
18
|
+
* be used.
|
|
19
|
+
* @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`
|
|
20
|
+
* is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* The query error is thrown if the fetch fails and no cached data exists yet, so an error boundary is
|
|
24
|
+
* required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
|
|
25
|
+
* Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { Suspense } from 'react'
|
|
28
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
29
|
+
* import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-query'
|
|
30
|
+
*
|
|
31
|
+
* function Posts() {
|
|
32
|
+
* // `data` is guaranteed to be defined here — no `isPending` check needed.
|
|
33
|
+
* const { data, isFetching } = useSuspenseQuery({
|
|
34
|
+
* queryKey: ['posts'],
|
|
35
|
+
* queryFn: fetchPosts,
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* return (
|
|
39
|
+
* <div>
|
|
40
|
+
* <h1>Posts {isFetching ? '(refreshing...)' : null}</h1>
|
|
41
|
+
* <ul>
|
|
42
|
+
* {data.map((post) => (
|
|
43
|
+
* <li key={post.id}>{post.title}</li>
|
|
44
|
+
* ))}
|
|
45
|
+
* </ul>
|
|
46
|
+
* </div>
|
|
47
|
+
* )
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* function App() {
|
|
51
|
+
* return (
|
|
52
|
+
* <QueryErrorResetBoundary>
|
|
53
|
+
* {({ reset }) => (
|
|
54
|
+
* <ErrorBoundary
|
|
55
|
+
* onReset={reset}
|
|
56
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
57
|
+
* <div>
|
|
58
|
+
* There was an error!
|
|
59
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
60
|
+
* </div>
|
|
61
|
+
* )}
|
|
62
|
+
* >
|
|
63
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
64
|
+
* <Posts />
|
|
65
|
+
* </Suspense>
|
|
66
|
+
* </ErrorBoundary>
|
|
67
|
+
* )}
|
|
68
|
+
* </QueryErrorResetBoundary>
|
|
69
|
+
* )
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
6
73
|
function useSuspenseQuery(options, queryClient) {
|
|
7
74
|
if (process.env.NODE_ENV !== "production") {
|
|
8
75
|
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":["'use client'\nimport { QueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\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":["'use client'\nimport { QueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\n/**\n * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and\n * `placeholderData` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a \"disabled\" state.\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 * The query error is thrown if the fetch fails and no cached data exists yet, so an error boundary is\n * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.\n * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-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 ? '(refreshing...)' : null}</h1>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,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"}
|
|
@@ -6,6 +6,49 @@ let react = require("react");
|
|
|
6
6
|
react = require_rolldown_runtime.__toESM(react, 1);
|
|
7
7
|
let _tanstack_query_core = require("@tanstack/query-core");
|
|
8
8
|
//#region src/HydrationBoundary.tsx
|
|
9
|
+
/**
|
|
10
|
+
* `HydrationBoundary` adds a previously dehydrated state into the `queryClient` that would be returned by
|
|
11
|
+
* `useQueryClient()`. If the client already contains data, the new queries will be intelligently merged based on
|
|
12
|
+
* update timestamp.
|
|
13
|
+
*
|
|
14
|
+
* Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
|
|
15
|
+
*
|
|
16
|
+
* @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
|
|
17
|
+
* cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
|
|
18
|
+
* after commit.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* import { HydrationBoundary } from '@tanstack/react-query'
|
|
23
|
+
*
|
|
24
|
+
* function App() {
|
|
25
|
+
* return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* Server-side prefetch handed off to the client via `dehydrate`:
|
|
31
|
+
* ```tsx
|
|
32
|
+
* import { HydrationBoundary, dehydrate, noop } from '@tanstack/react-query'
|
|
33
|
+
*
|
|
34
|
+
* async function ServerComponent() {
|
|
35
|
+
* const queryClient = getQueryClient()
|
|
36
|
+
*
|
|
37
|
+
* await queryClient
|
|
38
|
+
* .query({
|
|
39
|
+
* queryKey: ['posts'],
|
|
40
|
+
* queryFn: fetchPosts,
|
|
41
|
+
* })
|
|
42
|
+
* .catch(noop)
|
|
43
|
+
*
|
|
44
|
+
* return (
|
|
45
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
46
|
+
* <Posts />
|
|
47
|
+
* </HydrationBoundary>
|
|
48
|
+
* )
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
9
52
|
const HydrationBoundary = ({ children, options = {}, state, queryClient }) => {
|
|
10
53
|
const client = require_QueryClientProvider.useQueryClient(queryClient);
|
|
11
54
|
const optionsRef = react.useRef(options);
|
|
@@ -22,7 +65,7 @@ const HydrationBoundary = ({ children, options = {}, state, queryClient }) => {
|
|
|
22
65
|
for (const dehydratedQuery of queries) {
|
|
23
66
|
const existingQuery = queryCache.get(dehydratedQuery.queryHash);
|
|
24
67
|
if (!existingQuery) newQueries.push(dehydratedQuery);
|
|
25
|
-
else if (dehydratedQuery.state.dataUpdatedAt > existingQuery.state.dataUpdatedAt || dehydratedQuery.promise && existingQuery.state.status !== "pending" && existingQuery.state.fetchStatus !== "fetching" && dehydratedQuery.dehydratedAt
|
|
68
|
+
else if (dehydratedQuery.state.dataUpdatedAt > existingQuery.state.dataUpdatedAt || dehydratedQuery.promise && existingQuery.state.status !== "pending" && existingQuery.state.fetchStatus !== "fetching" && dehydratedQuery.dehydratedAt > existingQuery.state.dataUpdatedAt) existingQueries.push(dehydratedQuery);
|
|
26
69
|
}
|
|
27
70
|
if (newQueries.length > 0) (0, _tanstack_query_core.hydrate)(client, { queries: newQueries }, optionsRef.current);
|
|
28
71
|
if (existingQueries.length > 0) return existingQueries;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HydrationBoundary.cjs","names":["useQueryClient","React"],"sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n DehydratedState,\n HydrateOptions,\n OmitKeyof,\n QueryClient,\n} from '@tanstack/query-core'\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?: React.ReactNode\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 = React.useRef(options)\n React.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 =\n React.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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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
|
|
1
|
+
{"version":3,"file":"HydrationBoundary.cjs","names":["useQueryClient","React"],"sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n DehydratedState,\n HydrateOptions,\n OmitKeyof,\n QueryClient,\n} from '@tanstack/query-core'\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?: React.ReactNode\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/react-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/react-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 = React.useRef(options)\n React.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 =\n React.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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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 >\n 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 // eslint-disable-next-line react-hooks/refs\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 React.useEffect(() => {\n if (hydrationQueue) {\n hydrate(client, { queries: hydrationQueue }, optionsRef.current)\n }\n }, [client, hydrationQueue])\n\n return children as React.ReactElement\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,MAAa,qBAAqB,EAChC,UACA,UAAU,CAAC,GACX,OACA,kBAC4B;CAC5B,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,MAAM,aAAaC,MAAM,OAAO,OAAO;CACvC,MAAM,gBAAgB;EACpB,WAAW,UAAU;CACvB,CAAC;CAiBD,MAAM,iBACJA,MAAM,cAAc;EAClB,IAAI,OAAO;GACT,IAAI,OAAO,UAAU,UACnB;GAGF,MAAM,aAAa,OAAO,cAAc;GAKxC,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,eACd,cAAc,MAAM,eAGxB,gBAAgB,KAAK,eAAe;GAG1C;GAEA,IAAI,WAAW,SAAS,GAItB,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;CAEpB,MAAM,gBAAgB;EACpB,IAAI,gBACF,CAAA,GAAA,qBAAA,QAAA,CAAQ,QAAQ,EAAE,SAAS,eAAe,GAAG,WAAW,OAAO;CAEnE,GAAG,CAAC,QAAQ,cAAc,CAAC;CAE3B,OAAO;AACT"}
|
|
@@ -1,14 +1,75 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { DehydratedState, HydrateOptions, OmitKeyof, QueryClient } from "@tanstack/query-core";
|
|
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?: React.ReactNode;
|
|
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/react-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/react-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) => React.ReactElement;
|
|
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":";;;;;;UAeiB;;;;EAIf,OAAO;;;;EAIP,UAAU,UAAU;IAClB,iBAAiB,UACf,QAAQ;;;;;;;;EAUZ,WAAW,MAAM;;;;EAIjB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8CH,sBAAqB,UAAA,SAAA,OAAA,eAK/B,2BA+EkB,MAAM"}
|