@suspensive/react-query-4 3.19.5 → 4.0.0-next.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/dist/ClientOnly-BSe1ROuK.cjs +20 -0
- package/dist/ClientOnly-BSe1ROuK.cjs.map +1 -0
- package/dist/ClientOnly-D2JpP9Ba.mjs +15 -0
- package/dist/ClientOnly-D2JpP9Ba.mjs.map +1 -0
- package/dist/IsFetching-BGIRMA6C.cjs +17 -0
- package/dist/IsFetching-BGIRMA6C.cjs.map +1 -0
- package/dist/IsFetching-CJrzs0ET.d.mts +16 -0
- package/dist/IsFetching-CJrzs0ET.d.mts.map +1 -0
- package/dist/IsFetching-Di9jXfRH.mjs +12 -0
- package/dist/IsFetching-Di9jXfRH.mjs.map +1 -0
- package/dist/IsFetching-FFvHWt5I.d.cts +16 -0
- package/dist/IsFetching-FFvHWt5I.d.cts.map +1 -0
- package/dist/IsFetching.cjs +2 -18
- package/dist/IsFetching.d.cts +2 -18
- package/dist/IsFetching.d.mts +2 -18
- package/dist/IsFetching.mjs +2 -17
- package/dist/Mutation-BWER242k.cjs +19 -0
- package/dist/Mutation-BWER242k.cjs.map +1 -0
- package/dist/Mutation-SB8NYSR4.mjs +14 -0
- package/dist/Mutation-SB8NYSR4.mjs.map +1 -0
- package/dist/Mutation-rhItOp02.d.cts +14 -0
- package/dist/Mutation-rhItOp02.d.cts.map +1 -0
- package/dist/Mutation-sfj_v5Fj.d.mts +14 -0
- package/dist/Mutation-sfj_v5Fj.d.mts.map +1 -0
- package/dist/Mutation.cjs +2 -14
- package/dist/Mutation.d.cts +2 -14
- package/dist/Mutation.d.mts +2 -14
- package/dist/Mutation.mjs +2 -13
- package/dist/PrefetchInfiniteQuery-BH6xERH5.mjs +20 -0
- package/dist/PrefetchInfiniteQuery-BH6xERH5.mjs.map +1 -0
- package/dist/PrefetchInfiniteQuery-Bf5JUe7U.cjs +25 -0
- package/dist/PrefetchInfiniteQuery-Bf5JUe7U.cjs.map +1 -0
- package/dist/PrefetchInfiniteQuery-CBl7Fblo.d.cts +17 -0
- package/dist/PrefetchInfiniteQuery-CBl7Fblo.d.cts.map +1 -0
- package/dist/PrefetchInfiniteQuery-CNNJphhx.d.mts +17 -0
- package/dist/PrefetchInfiniteQuery-CNNJphhx.d.mts.map +1 -0
- package/dist/PrefetchInfiniteQuery.cjs +2 -20
- package/dist/PrefetchInfiniteQuery.d.cts +2 -16
- package/dist/PrefetchInfiniteQuery.d.mts +2 -16
- package/dist/PrefetchInfiniteQuery.mjs +2 -19
- package/dist/PrefetchQuery-BmQt_WJk.d.mts +17 -0
- package/dist/PrefetchQuery-BmQt_WJk.d.mts.map +1 -0
- package/dist/PrefetchQuery-CqWzm0Tu.d.cts +17 -0
- package/dist/PrefetchQuery-CqWzm0Tu.d.cts.map +1 -0
- package/dist/PrefetchQuery-DQFTAE7M.mjs +20 -0
- package/dist/PrefetchQuery-DQFTAE7M.mjs.map +1 -0
- package/dist/PrefetchQuery-PBReP6tu.cjs +25 -0
- package/dist/PrefetchQuery-PBReP6tu.cjs.map +1 -0
- package/dist/PrefetchQuery.cjs +2 -20
- package/dist/PrefetchQuery.d.cts +2 -16
- package/dist/PrefetchQuery.d.mts +2 -16
- package/dist/PrefetchQuery.mjs +2 -19
- package/dist/QueriesHydration-B28Xmf0f.d.cts +106 -0
- package/dist/QueriesHydration-B28Xmf0f.d.cts.map +1 -0
- package/dist/QueriesHydration-CbLB0bKz.mjs +143 -0
- package/dist/QueriesHydration-CbLB0bKz.mjs.map +1 -0
- package/dist/QueriesHydration-Cd2lBXvZ.cjs +148 -0
- package/dist/QueriesHydration-Cd2lBXvZ.cjs.map +1 -0
- package/dist/QueriesHydration-D8Kdp7yq.d.mts +106 -0
- package/dist/QueriesHydration-D8Kdp7yq.d.mts.map +1 -0
- package/dist/QueriesHydration.cjs +2 -117
- package/dist/QueriesHydration.d.cts +2 -105
- package/dist/QueriesHydration.d.mts +2 -105
- package/dist/QueriesHydration.mjs +2 -116
- package/dist/QueryClientConsumer-B5vPlxA7.mjs +14 -0
- package/dist/QueryClientConsumer-B5vPlxA7.mjs.map +1 -0
- package/dist/QueryClientConsumer-COVqqi9y.d.cts +18 -0
- package/dist/QueryClientConsumer-COVqqi9y.d.cts.map +1 -0
- package/dist/QueryClientConsumer-CsNJXJGM.cjs +19 -0
- package/dist/QueryClientConsumer-CsNJXJGM.cjs.map +1 -0
- package/dist/QueryClientConsumer-YLHVJlTq.d.mts +18 -0
- package/dist/QueryClientConsumer-YLHVJlTq.d.mts.map +1 -0
- package/dist/QueryClientConsumer.cjs +2 -14
- package/dist/QueryClientConsumer.d.cts +2 -18
- package/dist/QueryClientConsumer.d.mts +2 -18
- package/dist/QueryClientConsumer.mjs +2 -13
- package/dist/SuspenseInfiniteQuery-BZ3SvXkD.mjs +30 -0
- package/dist/SuspenseInfiniteQuery-BZ3SvXkD.mjs.map +1 -0
- package/dist/SuspenseInfiniteQuery-ByTjC7r9.d.cts +31 -0
- package/dist/SuspenseInfiniteQuery-ByTjC7r9.d.cts.map +1 -0
- package/dist/SuspenseInfiniteQuery-asj0bHeh.d.mts +31 -0
- package/dist/SuspenseInfiniteQuery-asj0bHeh.d.mts.map +1 -0
- package/dist/SuspenseInfiniteQuery-qAybH413.cjs +35 -0
- package/dist/SuspenseInfiniteQuery-qAybH413.cjs.map +1 -0
- package/dist/SuspenseInfiniteQuery.cjs +2 -30
- package/dist/SuspenseInfiniteQuery.d.cts +2 -31
- package/dist/SuspenseInfiniteQuery.d.mts +2 -31
- package/dist/SuspenseInfiniteQuery.mjs +2 -29
- package/dist/SuspenseQueries-CZJAU3Eq.d.cts +31 -0
- package/dist/SuspenseQueries-CZJAU3Eq.d.cts.map +1 -0
- package/dist/SuspenseQueries-DlBy4veI.cjs +31 -0
- package/dist/SuspenseQueries-DlBy4veI.cjs.map +1 -0
- package/dist/SuspenseQueries-Dv6SQx-C.mjs +26 -0
- package/dist/SuspenseQueries-Dv6SQx-C.mjs.map +1 -0
- package/dist/SuspenseQueries-Nv07W4mb.d.mts +31 -0
- package/dist/SuspenseQueries-Nv07W4mb.d.mts.map +1 -0
- package/dist/SuspenseQueries.cjs +2 -26
- package/dist/SuspenseQueries.d.cts +2 -30
- package/dist/SuspenseQueries.d.mts +2 -30
- package/dist/SuspenseQueries.mjs +2 -25
- package/dist/SuspenseQuery-BNAZi5mZ.d.cts +31 -0
- package/dist/SuspenseQuery-BNAZi5mZ.d.cts.map +1 -0
- package/dist/SuspenseQuery-CGEFuzI_.cjs +35 -0
- package/dist/SuspenseQuery-CGEFuzI_.cjs.map +1 -0
- package/dist/SuspenseQuery-RbgXq6PC.mjs +30 -0
- package/dist/SuspenseQuery-RbgXq6PC.mjs.map +1 -0
- package/dist/SuspenseQuery-uHIieJ1n.d.mts +31 -0
- package/dist/SuspenseQuery-uHIieJ1n.d.mts.map +1 -0
- package/dist/SuspenseQuery.cjs +2 -30
- package/dist/SuspenseQuery.d.cts +2 -30
- package/dist/SuspenseQuery.d.mts +2 -30
- package/dist/SuspenseQuery.mjs +2 -29
- package/dist/components/ClientOnly.cjs +2 -12
- package/dist/components/ClientOnly.d.cts +13 -0
- package/dist/components/ClientOnly.d.cts.map +1 -0
- package/dist/components/ClientOnly.d.mts +13 -0
- package/dist/components/ClientOnly.d.mts.map +1 -0
- package/dist/components/ClientOnly.mjs +2 -12
- package/dist/createGetQueryClient-Cg34XLqS.cjs +68 -0
- package/dist/createGetQueryClient-Cg34XLqS.cjs.map +1 -0
- package/dist/createGetQueryClient-Cjacpz3C.mjs +63 -0
- package/dist/createGetQueryClient-Cjacpz3C.mjs.map +1 -0
- package/dist/createGetQueryClient-DI5GrATJ.d.cts +54 -0
- package/dist/createGetQueryClient-DI5GrATJ.d.cts.map +1 -0
- package/dist/createGetQueryClient-UFf6keL9.d.mts +54 -0
- package/dist/createGetQueryClient-UFf6keL9.d.mts.map +1 -0
- package/dist/createGetQueryClient.cjs +2 -63
- package/dist/createGetQueryClient.d.cts +2 -53
- package/dist/createGetQueryClient.d.mts +2 -53
- package/dist/createGetQueryClient.mjs +2 -62
- package/dist/index.cjs +12 -27
- package/dist/index.d.cts +12 -19
- package/dist/index.d.mts +12 -19
- package/dist/index.mjs +12 -19
- package/dist/mutationOptions-BdXvKAld.d.mts +7 -0
- package/dist/mutationOptions-BdXvKAld.d.mts.map +1 -0
- package/dist/mutationOptions-CBUqQakM.mjs +8 -0
- package/dist/mutationOptions-CBUqQakM.mjs.map +1 -0
- package/dist/mutationOptions-CzTorL9K.d.cts +7 -0
- package/dist/mutationOptions-CzTorL9K.d.cts.map +1 -0
- package/dist/mutationOptions-DNgLRYqd.cjs +14 -0
- package/dist/mutationOptions-DNgLRYqd.cjs.map +1 -0
- package/dist/mutationOptions.cjs +2 -9
- package/dist/mutationOptions.d.cts +2 -7
- package/dist/mutationOptions.d.mts +2 -7
- package/dist/mutationOptions.mjs +2 -7
- package/dist/objectSpread2-DTjFl4q7.mjs +67 -0
- package/dist/objectSpread2-DUnXKO-7.cjs +73 -0
- package/dist/objectWithoutProperties-BqF6LYLG.cjs +31 -0
- package/dist/objectWithoutProperties-DB_n2qVi.mjs +25 -0
- package/package.json +4 -4
- package/src/IsFetching.tsx +2 -3
- package/src/Mutation.tsx +1 -0
- package/src/PrefetchInfiniteQuery.tsx +8 -3
- package/src/PrefetchQuery.tsx +3 -3
- package/src/QueryClientConsumer.tsx +1 -0
- package/src/SuspenseInfiniteQuery.tsx +23 -2
- package/src/SuspenseQueries.tsx +1 -0
- package/src/SuspenseQuery.tsx +1 -0
- package/src/components/ClientOnly.tsx +1 -0
- package/src/createGetQueryClient.spec.tsx +77 -25
- package/src/index.ts +1 -14
- package/dist/IsFetching.cjs.map +0 -1
- package/dist/IsFetching.d.cts.map +0 -1
- package/dist/IsFetching.d.mts.map +0 -1
- package/dist/IsFetching.mjs.map +0 -1
- package/dist/Mutation.cjs.map +0 -1
- package/dist/Mutation.d.cts.map +0 -1
- package/dist/Mutation.d.mts.map +0 -1
- package/dist/Mutation.mjs.map +0 -1
- package/dist/PrefetchInfiniteQuery.cjs.map +0 -1
- package/dist/PrefetchInfiniteQuery.d.cts.map +0 -1
- package/dist/PrefetchInfiniteQuery.d.mts.map +0 -1
- package/dist/PrefetchInfiniteQuery.mjs.map +0 -1
- package/dist/PrefetchQuery.cjs.map +0 -1
- package/dist/PrefetchQuery.d.cts.map +0 -1
- package/dist/PrefetchQuery.d.mts.map +0 -1
- package/dist/PrefetchQuery.mjs.map +0 -1
- package/dist/QueriesHydration.cjs.map +0 -1
- package/dist/QueriesHydration.d.cts.map +0 -1
- package/dist/QueriesHydration.d.mts.map +0 -1
- package/dist/QueriesHydration.mjs.map +0 -1
- package/dist/QueryClientConsumer.cjs.map +0 -1
- package/dist/QueryClientConsumer.d.cts.map +0 -1
- package/dist/QueryClientConsumer.d.mts.map +0 -1
- package/dist/QueryClientConsumer.mjs.map +0 -1
- package/dist/SuspenseInfiniteQuery.cjs.map +0 -1
- package/dist/SuspenseInfiniteQuery.d.cts.map +0 -1
- package/dist/SuspenseInfiniteQuery.d.mts.map +0 -1
- package/dist/SuspenseInfiniteQuery.mjs.map +0 -1
- package/dist/SuspenseQueries.cjs.map +0 -1
- package/dist/SuspenseQueries.d.cts.map +0 -1
- package/dist/SuspenseQueries.d.mts.map +0 -1
- package/dist/SuspenseQueries.mjs.map +0 -1
- package/dist/SuspenseQuery.cjs.map +0 -1
- package/dist/SuspenseQuery.d.cts.map +0 -1
- package/dist/SuspenseQuery.d.mts.map +0 -1
- package/dist/SuspenseQuery.mjs.map +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.cjs +0 -29
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.mjs +0 -28
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/defineProperty.cjs +0 -14
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/defineProperty.mjs +0 -14
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.cjs +0 -27
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.mjs +0 -27
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.cjs +0 -15
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.mjs +0 -15
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutPropertiesLoose.cjs +0 -14
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutPropertiesLoose.mjs +0 -13
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPrimitive.cjs +0 -16
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPrimitive.mjs +0 -16
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPropertyKey.cjs +0 -11
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPropertyKey.mjs +0 -11
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/typeof.cjs +0 -18
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/typeof.mjs +0 -12
- package/dist/components/ClientOnly.cjs.map +0 -1
- package/dist/components/ClientOnly.mjs.map +0 -1
- package/dist/createGetQueryClient.cjs.map +0 -1
- package/dist/createGetQueryClient.d.cts.map +0 -1
- package/dist/createGetQueryClient.d.mts.map +0 -1
- package/dist/createGetQueryClient.mjs.map +0 -1
- package/dist/infiniteQueryOptions.cjs +0 -18
- package/dist/infiniteQueryOptions.cjs.map +0 -1
- package/dist/infiniteQueryOptions.d.cts +0 -28
- package/dist/infiniteQueryOptions.d.cts.map +0 -1
- package/dist/infiniteQueryOptions.d.mts +0 -28
- package/dist/infiniteQueryOptions.d.mts.map +0 -1
- package/dist/infiniteQueryOptions.mjs +0 -17
- package/dist/infiniteQueryOptions.mjs.map +0 -1
- package/dist/mutationOptions.cjs.map +0 -1
- package/dist/mutationOptions.d.cts.map +0 -1
- package/dist/mutationOptions.d.mts.map +0 -1
- package/dist/mutationOptions.mjs.map +0 -1
- package/dist/queryOptions.cjs +0 -18
- package/dist/queryOptions.cjs.map +0 -1
- package/dist/queryOptions.d.cts +0 -28
- package/dist/queryOptions.d.cts.map +0 -1
- package/dist/queryOptions.d.mts +0 -28
- package/dist/queryOptions.d.mts.map +0 -1
- package/dist/queryOptions.mjs +0 -17
- package/dist/queryOptions.mjs.map +0 -1
- package/dist/usePrefetchInfiniteQuery.cjs +0 -18
- package/dist/usePrefetchInfiniteQuery.cjs.map +0 -1
- package/dist/usePrefetchInfiniteQuery.d.cts +0 -11
- package/dist/usePrefetchInfiniteQuery.d.cts.map +0 -1
- package/dist/usePrefetchInfiniteQuery.d.mts +0 -11
- package/dist/usePrefetchInfiniteQuery.d.mts.map +0 -1
- package/dist/usePrefetchInfiniteQuery.mjs +0 -17
- package/dist/usePrefetchInfiniteQuery.mjs.map +0 -1
- package/dist/usePrefetchQuery.cjs +0 -18
- package/dist/usePrefetchQuery.cjs.map +0 -1
- package/dist/usePrefetchQuery.d.cts +0 -11
- package/dist/usePrefetchQuery.d.cts.map +0 -1
- package/dist/usePrefetchQuery.d.mts +0 -11
- package/dist/usePrefetchQuery.d.mts.map +0 -1
- package/dist/usePrefetchQuery.mjs +0 -17
- package/dist/usePrefetchQuery.mjs.map +0 -1
- package/dist/useSuspenseInfiniteQuery.cjs +0 -20
- package/dist/useSuspenseInfiniteQuery.cjs.map +0 -1
- package/dist/useSuspenseInfiniteQuery.d.cts +0 -17
- package/dist/useSuspenseInfiniteQuery.d.cts.map +0 -1
- package/dist/useSuspenseInfiniteQuery.d.mts +0 -17
- package/dist/useSuspenseInfiniteQuery.d.mts.map +0 -1
- package/dist/useSuspenseInfiniteQuery.mjs +0 -19
- package/dist/useSuspenseInfiniteQuery.mjs.map +0 -1
- package/dist/useSuspenseQueries.cjs +0 -20
- package/dist/useSuspenseQueries.cjs.map +0 -1
- package/dist/useSuspenseQueries.d.cts +0 -36
- package/dist/useSuspenseQueries.d.cts.map +0 -1
- package/dist/useSuspenseQueries.d.mts +0 -36
- package/dist/useSuspenseQueries.d.mts.map +0 -1
- package/dist/useSuspenseQueries.mjs +0 -19
- package/dist/useSuspenseQueries.mjs.map +0 -1
- package/dist/useSuspenseQuery.cjs +0 -20
- package/dist/useSuspenseQuery.cjs.map +0 -1
- package/dist/useSuspenseQuery.d.cts +0 -36
- package/dist/useSuspenseQuery.d.cts.map +0 -1
- package/dist/useSuspenseQuery.d.mts +0 -36
- package/dist/useSuspenseQuery.d.mts.map +0 -1
- package/dist/useSuspenseQuery.mjs +0 -19
- package/dist/useSuspenseQuery.mjs.map +0 -1
- package/src/IsFetching.spec.tsx +0 -34
- package/src/infiniteQueryOptions.ts +0 -77
- package/src/queryOptions.ts +0 -80
- package/src/usePrefetchInfiniteQuery.test-d.tsx +0 -14
- package/src/usePrefetchInfiniteQuery.ts +0 -19
- package/src/usePrefetchQuery.test-d.tsx +0 -14
- package/src/usePrefetchQuery.ts +0 -19
- package/src/useSuspenseInfiniteQuery.ts +0 -34
- package/src/useSuspenseQueries.ts +0 -47
- package/src/useSuspenseQuery.ts +0 -39
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { usePrefetchQuery } from "@tanstack/react-query";
|
|
2
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/PrefetchQuery.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks.
|
|
7
|
+
* @see {@link https://suspensive.org/docs/react-query/PrefetchQuery Suspensive Docs}
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <PrefetchQuery queryKey={['queryKey']} queryFn={queryFn} />
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
function PrefetchQuery(options) {
|
|
14
|
+
usePrefetchQuery(options);
|
|
15
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { PrefetchQuery as t };
|
|
20
|
+
//# sourceMappingURL=PrefetchQuery-DQFTAE7M.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrefetchQuery-DQFTAE7M.mjs","names":[],"sources":["../src/PrefetchQuery.tsx"],"sourcesContent":["'use client'\n\nimport { type FetchQueryOptions, type QueryKey, type WithRequired, usePrefetchQuery } from '@tanstack/react-query'\n\n/**\n * A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks.\n * @see {@link https://suspensive.org/docs/react-query/PrefetchQuery Suspensive Docs}\n * @example\n * ```tsx\n * <PrefetchQuery queryKey={['queryKey']} queryFn={queryFn} />\n * ```\n */\nexport function PrefetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(options: WithRequired<FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey'>) {\n usePrefetchQuery(options)\n return <></>\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,cAKd,SAA8F;AAC9F,kBAAiB,QAAQ;AACzB,QAAO,iCAAK"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
let __tanstack_react_query = require("@tanstack/react-query");
|
|
2
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
+
|
|
4
|
+
//#region src/PrefetchQuery.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks.
|
|
7
|
+
* @see {@link https://suspensive.org/docs/react-query/PrefetchQuery Suspensive Docs}
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <PrefetchQuery queryKey={['queryKey']} queryFn={queryFn} />
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
function PrefetchQuery(options) {
|
|
14
|
+
(0, __tanstack_react_query.usePrefetchQuery)(options);
|
|
15
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
Object.defineProperty(exports, 'PrefetchQuery', {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return PrefetchQuery;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=PrefetchQuery-PBReP6tu.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrefetchQuery-PBReP6tu.cjs","names":[],"sources":["../src/PrefetchQuery.tsx"],"sourcesContent":["'use client'\n\nimport { type FetchQueryOptions, type QueryKey, type WithRequired, usePrefetchQuery } from '@tanstack/react-query'\n\n/**\n * A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks.\n * @see {@link https://suspensive.org/docs/react-query/PrefetchQuery Suspensive Docs}\n * @example\n * ```tsx\n * <PrefetchQuery queryKey={['queryKey']} queryFn={queryFn} />\n * ```\n */\nexport function PrefetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(options: WithRequired<FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey'>) {\n usePrefetchQuery(options)\n return <></>\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,cAKd,SAA8F;AAC9F,8CAAiB,QAAQ;AACzB,QAAO,0EAAK"}
|
package/dist/PrefetchQuery.cjs
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const require_usePrefetchQuery = require('./usePrefetchQuery.cjs');
|
|
5
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
+
const require_PrefetchQuery = require('./PrefetchQuery-PBReP6tu.cjs');
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks.
|
|
10
|
-
* @see {@link https://suspensive.org/docs/react-query/PrefetchQuery Suspensive Docs}
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* <PrefetchQuery queryKey={['queryKey']} queryFn={queryFn} />
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
function PrefetchQuery(options) {
|
|
17
|
-
require_usePrefetchQuery.usePrefetchQuery(options);
|
|
18
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.PrefetchQuery = PrefetchQuery;
|
|
23
|
-
//# sourceMappingURL=PrefetchQuery.cjs.map
|
|
5
|
+
exports.PrefetchQuery = require_PrefetchQuery.PrefetchQuery;
|
package/dist/PrefetchQuery.d.cts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/PrefetchQuery.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks.
|
|
7
|
-
* @see {@link https://suspensive.org/docs/react-query/PrefetchQuery Suspensive Docs}
|
|
8
|
-
* @example
|
|
9
|
-
* ```tsx
|
|
10
|
-
* <PrefetchQuery queryKey={['queryKey']} queryFn={queryFn} />
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
declare function PrefetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>): react_jsx_runtime0.JSX.Element;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { PrefetchQuery };
|
|
16
|
-
//# sourceMappingURL=PrefetchQuery.d.cts.map
|
|
1
|
+
import { t as PrefetchQuery } from "./PrefetchQuery-CqWzm0Tu.cjs";
|
|
2
|
+
export { PrefetchQuery };
|
package/dist/PrefetchQuery.d.mts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/PrefetchQuery.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks.
|
|
7
|
-
* @see {@link https://suspensive.org/docs/react-query/PrefetchQuery Suspensive Docs}
|
|
8
|
-
* @example
|
|
9
|
-
* ```tsx
|
|
10
|
-
* <PrefetchQuery queryKey={['queryKey']} queryFn={queryFn} />
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
declare function PrefetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>): react_jsx_runtime0.JSX.Element;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { PrefetchQuery };
|
|
16
|
-
//# sourceMappingURL=PrefetchQuery.d.mts.map
|
|
1
|
+
import { t as PrefetchQuery } from "./PrefetchQuery-BmQt_WJk.mjs";
|
|
2
|
+
export { PrefetchQuery };
|
package/dist/PrefetchQuery.mjs
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import { t as PrefetchQuery } from "./PrefetchQuery-DQFTAE7M.mjs";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks.
|
|
9
|
-
* @see {@link https://suspensive.org/docs/react-query/PrefetchQuery Suspensive Docs}
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* <PrefetchQuery queryKey={['queryKey']} queryFn={queryFn} />
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
function PrefetchQuery(options) {
|
|
16
|
-
usePrefetchQuery(options);
|
|
17
|
-
return /* @__PURE__ */ jsx(Fragment, {});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { PrefetchQuery };
|
|
22
|
-
//# sourceMappingURL=PrefetchQuery.mjs.map
|
|
5
|
+
export { PrefetchQuery };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
2
|
+
import { HydrateProps, OmitKeyof, QueryClient, QueryOptions, UseInfiniteQueryOptions, WithRequired } from "@tanstack/react-query";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/QueriesHydration.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A server component that fetches multiple queries on the server and hydrates them to the client.
|
|
9
|
+
*
|
|
10
|
+
* @experimental This component is experimental and may be changed or removed in the future.
|
|
11
|
+
*
|
|
12
|
+
* @description
|
|
13
|
+
* QueriesHydration is designed for React Server Components (RSC).
|
|
14
|
+
* It pre-fetches multiple queries on the server side and automatically hydrates
|
|
15
|
+
* the data to the client, enabling seamless data synchronization between server and client.
|
|
16
|
+
*
|
|
17
|
+
* When errors occur during server-side fetching, the component gracefully falls back
|
|
18
|
+
* to client-side rendering, ensuring your application remains resilient.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* // app/page.tsx (Server Component)
|
|
23
|
+
* import { Suspense } from 'react'
|
|
24
|
+
* import { QueriesHydration } from '@suspensive/react-query'
|
|
25
|
+
* import { queryOptions } from '@tanstack/react-query'
|
|
26
|
+
*
|
|
27
|
+
* const userQueryOptions = (userId: string) => queryOptions({
|
|
28
|
+
* queryKey: ['user', userId],
|
|
29
|
+
* queryFn: () => fetchUser(userId)
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* const postsQueryOptions = () => queryOptions({
|
|
33
|
+
* queryKey: ['posts'],
|
|
34
|
+
* queryFn: () => fetchPosts()
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* export default function Page({ userId }: { userId: string }) {
|
|
38
|
+
* return (
|
|
39
|
+
* <>
|
|
40
|
+
* <Suspense fallback={<div>Loading user...</div>}>
|
|
41
|
+
* <QueriesHydration queries={[userQueryOptions(userId)]}>
|
|
42
|
+
* <UserProfile />
|
|
43
|
+
* </QueriesHydration>
|
|
44
|
+
* </Suspense>
|
|
45
|
+
*
|
|
46
|
+
* <Suspense fallback={<div>Loading posts...</div>}>
|
|
47
|
+
* <QueriesHydration queries={[postsQueryOptions()]}>
|
|
48
|
+
* <PostsList />
|
|
49
|
+
* </QueriesHydration>
|
|
50
|
+
* </Suspense>
|
|
51
|
+
* </>
|
|
52
|
+
* )
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* // With custom error fallback
|
|
59
|
+
* <Suspense fallback={<div>Loading user...</div>}>
|
|
60
|
+
* <QueriesHydration
|
|
61
|
+
* queries={[userQueryOptions(userId)]}
|
|
62
|
+
* skipSsrOnError={{ fallback: <div>Fetching on client...</div> }}
|
|
63
|
+
* >
|
|
64
|
+
* <UserProfile />
|
|
65
|
+
* </QueriesHydration>
|
|
66
|
+
* </Suspense>
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @see {@link https://suspensive.org/docs/react-query/QueriesHydration Documentation}
|
|
70
|
+
*/
|
|
71
|
+
declare function QueriesHydration({
|
|
72
|
+
queries,
|
|
73
|
+
children,
|
|
74
|
+
queryClient,
|
|
75
|
+
skipSsrOnError,
|
|
76
|
+
timeout,
|
|
77
|
+
...props
|
|
78
|
+
}: {
|
|
79
|
+
/**
|
|
80
|
+
* The QueryClient instance to use for fetching queries.
|
|
81
|
+
*/
|
|
82
|
+
queryClient?: QueryClient;
|
|
83
|
+
/**
|
|
84
|
+
* An array of query options or infinite query options to be fetched on the server. Each query must include a `queryKey`.
|
|
85
|
+
* You can mix regular queries and infinite queries in the same array.
|
|
86
|
+
*/
|
|
87
|
+
queries: (WithRequired<QueryOptions<any, any, any, any>, 'queryKey'> | WithRequired<UseInfiniteQueryOptions<any, any, any, any, any>, 'queryKey'>)[];
|
|
88
|
+
/**
|
|
89
|
+
* Controls error handling behavior:
|
|
90
|
+
* - `true` (default): Skips SSR and falls back to client-side rendering when server fetch fails
|
|
91
|
+
* - `false`: Proceeds with SSR without hydration (retry fetching on client component server rendering)
|
|
92
|
+
* - `{ fallback: ReactNode }`: Skips SSR with custom fallback UI during client-side rendering
|
|
93
|
+
*/
|
|
94
|
+
skipSsrOnError?: boolean | {
|
|
95
|
+
fallback: ReactNode;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The timeout in milliseconds for the query.
|
|
99
|
+
* If the query takes longer than the timeout, it will be considered as an error.
|
|
100
|
+
* When not set, no timeout is applied.
|
|
101
|
+
*/
|
|
102
|
+
timeout?: number;
|
|
103
|
+
} & OmitKeyof<HydrateProps, 'state'>): Promise<react_jsx_runtime1.JSX.Element>;
|
|
104
|
+
//#endregion
|
|
105
|
+
export { QueriesHydration as t };
|
|
106
|
+
//# sourceMappingURL=QueriesHydration-B28Xmf0f.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueriesHydration-B28Xmf0f.d.cts","names":[],"sources":["../src/QueriesHydration.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;AA6EA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAsB,gBAAA;;;;;;;;;;;gBAWN;;;;;YAMV,aAAa,gDACb,aAAa;;;;;;;;cAWD;;;;;;;;IAQd,UAAU,yBAAsB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { t as _objectWithoutProperties } from "./objectWithoutProperties-DB_n2qVi.mjs";
|
|
2
|
+
import { t as ClientOnly } from "./ClientOnly-D2JpP9Ba.mjs";
|
|
3
|
+
import { t as _objectSpread2 } from "./objectSpread2-DTjFl4q7.mjs";
|
|
4
|
+
import { Hydrate, QueryClient, dehydrate } from "@tanstack/react-query";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/asyncToGenerator.js
|
|
8
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
9
|
+
try {
|
|
10
|
+
var i = n[a](c), u = i.value;
|
|
11
|
+
} catch (n$1) {
|
|
12
|
+
e(n$1);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
16
|
+
}
|
|
17
|
+
function _asyncToGenerator(n) {
|
|
18
|
+
return function() {
|
|
19
|
+
var t = this, e = arguments;
|
|
20
|
+
return new Promise(function(r, o) {
|
|
21
|
+
var a = n.apply(t, e);
|
|
22
|
+
function _next(n$1) {
|
|
23
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n$1);
|
|
24
|
+
}
|
|
25
|
+
function _throw(n$1) {
|
|
26
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n$1);
|
|
27
|
+
}
|
|
28
|
+
_next(void 0);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/QueriesHydration.tsx
|
|
35
|
+
const _excluded = [
|
|
36
|
+
"queries",
|
|
37
|
+
"children",
|
|
38
|
+
"queryClient",
|
|
39
|
+
"skipSsrOnError",
|
|
40
|
+
"timeout"
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* A server component that fetches multiple queries on the server and hydrates them to the client.
|
|
44
|
+
*
|
|
45
|
+
* @experimental This component is experimental and may be changed or removed in the future.
|
|
46
|
+
*
|
|
47
|
+
* @description
|
|
48
|
+
* QueriesHydration is designed for React Server Components (RSC).
|
|
49
|
+
* It pre-fetches multiple queries on the server side and automatically hydrates
|
|
50
|
+
* the data to the client, enabling seamless data synchronization between server and client.
|
|
51
|
+
*
|
|
52
|
+
* When errors occur during server-side fetching, the component gracefully falls back
|
|
53
|
+
* to client-side rendering, ensuring your application remains resilient.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* // app/page.tsx (Server Component)
|
|
58
|
+
* import { Suspense } from 'react'
|
|
59
|
+
* import { QueriesHydration } from '@suspensive/react-query'
|
|
60
|
+
* import { queryOptions } from '@tanstack/react-query'
|
|
61
|
+
*
|
|
62
|
+
* const userQueryOptions = (userId: string) => queryOptions({
|
|
63
|
+
* queryKey: ['user', userId],
|
|
64
|
+
* queryFn: () => fetchUser(userId)
|
|
65
|
+
* })
|
|
66
|
+
*
|
|
67
|
+
* const postsQueryOptions = () => queryOptions({
|
|
68
|
+
* queryKey: ['posts'],
|
|
69
|
+
* queryFn: () => fetchPosts()
|
|
70
|
+
* })
|
|
71
|
+
*
|
|
72
|
+
* export default function Page({ userId }: { userId: string }) {
|
|
73
|
+
* return (
|
|
74
|
+
* <>
|
|
75
|
+
* <Suspense fallback={<div>Loading user...</div>}>
|
|
76
|
+
* <QueriesHydration queries={[userQueryOptions(userId)]}>
|
|
77
|
+
* <UserProfile />
|
|
78
|
+
* </QueriesHydration>
|
|
79
|
+
* </Suspense>
|
|
80
|
+
*
|
|
81
|
+
* <Suspense fallback={<div>Loading posts...</div>}>
|
|
82
|
+
* <QueriesHydration queries={[postsQueryOptions()]}>
|
|
83
|
+
* <PostsList />
|
|
84
|
+
* </QueriesHydration>
|
|
85
|
+
* </Suspense>
|
|
86
|
+
* </>
|
|
87
|
+
* )
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* // With custom error fallback
|
|
94
|
+
* <Suspense fallback={<div>Loading user...</div>}>
|
|
95
|
+
* <QueriesHydration
|
|
96
|
+
* queries={[userQueryOptions(userId)]}
|
|
97
|
+
* skipSsrOnError={{ fallback: <div>Fetching on client...</div> }}
|
|
98
|
+
* >
|
|
99
|
+
* <UserProfile />
|
|
100
|
+
* </QueriesHydration>
|
|
101
|
+
* </Suspense>
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @see {@link https://suspensive.org/docs/react-query/QueriesHydration Documentation}
|
|
105
|
+
*/
|
|
106
|
+
function QueriesHydration(_x) {
|
|
107
|
+
return _QueriesHydration.apply(this, arguments);
|
|
108
|
+
}
|
|
109
|
+
function _QueriesHydration() {
|
|
110
|
+
_QueriesHydration = _asyncToGenerator(function* (_ref) {
|
|
111
|
+
let { queries, children, queryClient = new QueryClient(), skipSsrOnError = true, timeout } = _ref, props = _objectWithoutProperties(_ref, _excluded);
|
|
112
|
+
const timeoutController = timeout != null && timeout >= 0 ? createTimeoutController(timeout, `QueriesHydration: timeout after ${timeout} ms)`) : void 0;
|
|
113
|
+
try {
|
|
114
|
+
const queriesPromise = Promise.all(queries.map((query) => "getNextPageParam" in query ? queryClient.fetchInfiniteQuery(query) : queryClient.fetchQuery(query)));
|
|
115
|
+
yield timeoutController != null ? Promise.race([queriesPromise, timeoutController.promise]) : queriesPromise;
|
|
116
|
+
timeoutController === null || timeoutController === void 0 || timeoutController.clear();
|
|
117
|
+
} catch (_unused) {
|
|
118
|
+
timeoutController === null || timeoutController === void 0 || timeoutController.clear();
|
|
119
|
+
if (skipSsrOnError) return /* @__PURE__ */ jsx(ClientOnly, {
|
|
120
|
+
fallback: skipSsrOnError === true ? void 0 : skipSsrOnError.fallback,
|
|
121
|
+
children
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return /* @__PURE__ */ jsx(Hydrate, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
125
|
+
state: dehydrate(queryClient),
|
|
126
|
+
children
|
|
127
|
+
}));
|
|
128
|
+
});
|
|
129
|
+
return _QueriesHydration.apply(this, arguments);
|
|
130
|
+
}
|
|
131
|
+
const createTimeoutController = (ms, errorMessage) => {
|
|
132
|
+
let timerId;
|
|
133
|
+
return {
|
|
134
|
+
promise: new Promise((_, reject) => {
|
|
135
|
+
timerId = setTimeout(() => reject(new Error(errorMessage)), ms);
|
|
136
|
+
}),
|
|
137
|
+
clear: () => timerId != null && clearTimeout(timerId)
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
export { QueriesHydration as t };
|
|
143
|
+
//# sourceMappingURL=QueriesHydration-CbLB0bKz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueriesHydration-CbLB0bKz.mjs","names":["timerId: ReturnType<typeof setTimeout> | undefined"],"sources":["../src/QueriesHydration.tsx"],"sourcesContent":["import {\n Hydrate,\n type HydrateProps,\n type OmitKeyof,\n QueryClient,\n type QueryOptions,\n type UseInfiniteQueryOptions,\n type WithRequired,\n dehydrate,\n} from '@tanstack/react-query'\nimport type { ReactNode } from 'react'\nimport { ClientOnly } from './components/ClientOnly'\n\n/**\n * A server component that fetches multiple queries on the server and hydrates them to the client.\n *\n * @experimental This component is experimental and may be changed or removed in the future.\n *\n * @description\n * QueriesHydration is designed for React Server Components (RSC).\n * It pre-fetches multiple queries on the server side and automatically hydrates\n * the data to the client, enabling seamless data synchronization between server and client.\n *\n * When errors occur during server-side fetching, the component gracefully falls back\n * to client-side rendering, ensuring your application remains resilient.\n *\n * @example\n * ```tsx\n * // app/page.tsx (Server Component)\n * import { Suspense } from 'react'\n * import { QueriesHydration } from '@suspensive/react-query'\n * import { queryOptions } from '@tanstack/react-query'\n *\n * const userQueryOptions = (userId: string) => queryOptions({\n * queryKey: ['user', userId],\n * queryFn: () => fetchUser(userId)\n * })\n *\n * const postsQueryOptions = () => queryOptions({\n * queryKey: ['posts'],\n * queryFn: () => fetchPosts()\n * })\n *\n * export default function Page({ userId }: { userId: string }) {\n * return (\n * <>\n * <Suspense fallback={<div>Loading user...</div>}>\n * <QueriesHydration queries={[userQueryOptions(userId)]}>\n * <UserProfile />\n * </QueriesHydration>\n * </Suspense>\n *\n * <Suspense fallback={<div>Loading posts...</div>}>\n * <QueriesHydration queries={[postsQueryOptions()]}>\n * <PostsList />\n * </QueriesHydration>\n * </Suspense>\n * </>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom error fallback\n * <Suspense fallback={<div>Loading user...</div>}>\n * <QueriesHydration\n * queries={[userQueryOptions(userId)]}\n * skipSsrOnError={{ fallback: <div>Fetching on client...</div> }}\n * >\n * <UserProfile />\n * </QueriesHydration>\n * </Suspense>\n * ```\n *\n * @see {@link https://suspensive.org/docs/react-query/QueriesHydration Documentation}\n */\nexport async function QueriesHydration({\n queries,\n children,\n queryClient = new QueryClient(),\n skipSsrOnError = true,\n timeout,\n ...props\n}: {\n /**\n * The QueryClient instance to use for fetching queries.\n */\n queryClient?: QueryClient\n /**\n * An array of query options or infinite query options to be fetched on the server. Each query must include a `queryKey`.\n * You can mix regular queries and infinite queries in the same array.\n */\n queries: (\n | WithRequired<QueryOptions<any, any, any, any>, 'queryKey'>\n | WithRequired<UseInfiniteQueryOptions<any, any, any, any, any>, 'queryKey'>\n )[]\n /**\n * Controls error handling behavior:\n * - `true` (default): Skips SSR and falls back to client-side rendering when server fetch fails\n * - `false`: Proceeds with SSR without hydration (retry fetching on client component server rendering)\n * - `{ fallback: ReactNode }`: Skips SSR with custom fallback UI during client-side rendering\n */\n skipSsrOnError?:\n | boolean\n | {\n fallback: ReactNode\n }\n /**\n * The timeout in milliseconds for the query.\n * If the query takes longer than the timeout, it will be considered as an error.\n * When not set, no timeout is applied.\n */\n timeout?: number\n} & OmitKeyof<HydrateProps, 'state'>) {\n const timeoutController =\n timeout != null && timeout >= 0\n ? createTimeoutController(timeout, `QueriesHydration: timeout after ${timeout} ms)`)\n : undefined\n try {\n const queriesPromise = Promise.all(\n queries.map((query) =>\n 'getNextPageParam' in query ? queryClient.fetchInfiniteQuery(query) : queryClient.fetchQuery(query)\n )\n )\n await (timeoutController != null ? Promise.race([queriesPromise, timeoutController.promise]) : queriesPromise)\n timeoutController?.clear()\n } catch {\n timeoutController?.clear()\n if (skipSsrOnError) {\n return (\n <ClientOnly fallback={skipSsrOnError === true ? undefined : skipSsrOnError.fallback}>{children}</ClientOnly>\n )\n }\n }\n return (\n <Hydrate {...props} state={dehydrate(queryClient)}>\n {children}\n </Hydrate>\n )\n}\n\nconst createTimeoutController = (ms: number, errorMessage: string) => {\n let timerId: ReturnType<typeof setTimeout> | undefined\n return {\n promise: new Promise<never>((_, reject) => {\n timerId = setTimeout(() => reject(new Error(errorMessage)), ms)\n }),\n clear: () => timerId != null && clearTimeout(timerId),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8EE;CACA;CACA;CACA;CACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALF,SAAsB,iBAAiB;;;;wDAqCD;MArCC,EACrC,SACA,UACA,cAAc,IAAI,aAAa,EAC/B,iBAAiB,MACjB,kBACG;EAgCH,MAAM,oBACJ,WAAW,QAAQ,WAAW,IAC1B,wBAAwB,SAAS,mCAAmC,QAAQ,MAAM,GAClF;AACN,MAAI;GACF,MAAM,iBAAiB,QAAQ,IAC7B,QAAQ,KAAK,UACX,sBAAsB,QAAQ,YAAY,mBAAmB,MAAM,GAAG,YAAY,WAAW,MAAM,CACpG,CACF;AACD,SAAO,qBAAqB,OAAO,QAAQ,KAAK,CAAC,gBAAgB,kBAAkB,QAAQ,CAAC,GAAG;AAC/F,mFAAmB,OAAO;oBACpB;AACN,mFAAmB,OAAO;AAC1B,OAAI,eACF,QACE,oBAAC;IAAW,UAAU,mBAAmB,OAAO,SAAY,eAAe;IAAW;KAAsB;;AAIlH,SACE,oBAAC,2CAAY;GAAO,OAAO,UAAU,YAAY;GAC9C;KACO;;;;AAId,MAAM,2BAA2B,IAAY,iBAAyB;CACpE,IAAIA;AACJ,QAAO;EACL,SAAS,IAAI,SAAgB,GAAG,WAAW;AACzC,aAAU,iBAAiB,OAAO,IAAI,MAAM,aAAa,CAAC,EAAE,GAAG;IAC/D;EACF,aAAa,WAAW,QAAQ,aAAa,QAAQ;EACtD"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const require_objectWithoutProperties = require('./objectWithoutProperties-BqF6LYLG.cjs');
|
|
2
|
+
const require_ClientOnly = require('./ClientOnly-BSe1ROuK.cjs');
|
|
3
|
+
const require_objectSpread2 = require('./objectSpread2-DUnXKO-7.cjs');
|
|
4
|
+
let __tanstack_react_query = require("@tanstack/react-query");
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/asyncToGenerator.js
|
|
8
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
9
|
+
try {
|
|
10
|
+
var i = n[a](c), u = i.value;
|
|
11
|
+
} catch (n$1) {
|
|
12
|
+
e(n$1);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
16
|
+
}
|
|
17
|
+
function _asyncToGenerator(n) {
|
|
18
|
+
return function() {
|
|
19
|
+
var t = this, e = arguments;
|
|
20
|
+
return new Promise(function(r, o) {
|
|
21
|
+
var a = n.apply(t, e);
|
|
22
|
+
function _next(n$1) {
|
|
23
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n$1);
|
|
24
|
+
}
|
|
25
|
+
function _throw(n$1) {
|
|
26
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n$1);
|
|
27
|
+
}
|
|
28
|
+
_next(void 0);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/QueriesHydration.tsx
|
|
35
|
+
const _excluded = [
|
|
36
|
+
"queries",
|
|
37
|
+
"children",
|
|
38
|
+
"queryClient",
|
|
39
|
+
"skipSsrOnError",
|
|
40
|
+
"timeout"
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* A server component that fetches multiple queries on the server and hydrates them to the client.
|
|
44
|
+
*
|
|
45
|
+
* @experimental This component is experimental and may be changed or removed in the future.
|
|
46
|
+
*
|
|
47
|
+
* @description
|
|
48
|
+
* QueriesHydration is designed for React Server Components (RSC).
|
|
49
|
+
* It pre-fetches multiple queries on the server side and automatically hydrates
|
|
50
|
+
* the data to the client, enabling seamless data synchronization between server and client.
|
|
51
|
+
*
|
|
52
|
+
* When errors occur during server-side fetching, the component gracefully falls back
|
|
53
|
+
* to client-side rendering, ensuring your application remains resilient.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* // app/page.tsx (Server Component)
|
|
58
|
+
* import { Suspense } from 'react'
|
|
59
|
+
* import { QueriesHydration } from '@suspensive/react-query'
|
|
60
|
+
* import { queryOptions } from '@tanstack/react-query'
|
|
61
|
+
*
|
|
62
|
+
* const userQueryOptions = (userId: string) => queryOptions({
|
|
63
|
+
* queryKey: ['user', userId],
|
|
64
|
+
* queryFn: () => fetchUser(userId)
|
|
65
|
+
* })
|
|
66
|
+
*
|
|
67
|
+
* const postsQueryOptions = () => queryOptions({
|
|
68
|
+
* queryKey: ['posts'],
|
|
69
|
+
* queryFn: () => fetchPosts()
|
|
70
|
+
* })
|
|
71
|
+
*
|
|
72
|
+
* export default function Page({ userId }: { userId: string }) {
|
|
73
|
+
* return (
|
|
74
|
+
* <>
|
|
75
|
+
* <Suspense fallback={<div>Loading user...</div>}>
|
|
76
|
+
* <QueriesHydration queries={[userQueryOptions(userId)]}>
|
|
77
|
+
* <UserProfile />
|
|
78
|
+
* </QueriesHydration>
|
|
79
|
+
* </Suspense>
|
|
80
|
+
*
|
|
81
|
+
* <Suspense fallback={<div>Loading posts...</div>}>
|
|
82
|
+
* <QueriesHydration queries={[postsQueryOptions()]}>
|
|
83
|
+
* <PostsList />
|
|
84
|
+
* </QueriesHydration>
|
|
85
|
+
* </Suspense>
|
|
86
|
+
* </>
|
|
87
|
+
* )
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* // With custom error fallback
|
|
94
|
+
* <Suspense fallback={<div>Loading user...</div>}>
|
|
95
|
+
* <QueriesHydration
|
|
96
|
+
* queries={[userQueryOptions(userId)]}
|
|
97
|
+
* skipSsrOnError={{ fallback: <div>Fetching on client...</div> }}
|
|
98
|
+
* >
|
|
99
|
+
* <UserProfile />
|
|
100
|
+
* </QueriesHydration>
|
|
101
|
+
* </Suspense>
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @see {@link https://suspensive.org/docs/react-query/QueriesHydration Documentation}
|
|
105
|
+
*/
|
|
106
|
+
function QueriesHydration(_x) {
|
|
107
|
+
return _QueriesHydration.apply(this, arguments);
|
|
108
|
+
}
|
|
109
|
+
function _QueriesHydration() {
|
|
110
|
+
_QueriesHydration = _asyncToGenerator(function* (_ref) {
|
|
111
|
+
let { queries, children, queryClient = new __tanstack_react_query.QueryClient(), skipSsrOnError = true, timeout } = _ref, props = require_objectWithoutProperties._objectWithoutProperties(_ref, _excluded);
|
|
112
|
+
const timeoutController = timeout != null && timeout >= 0 ? createTimeoutController(timeout, `QueriesHydration: timeout after ${timeout} ms)`) : void 0;
|
|
113
|
+
try {
|
|
114
|
+
const queriesPromise = Promise.all(queries.map((query) => "getNextPageParam" in query ? queryClient.fetchInfiniteQuery(query) : queryClient.fetchQuery(query)));
|
|
115
|
+
yield timeoutController != null ? Promise.race([queriesPromise, timeoutController.promise]) : queriesPromise;
|
|
116
|
+
timeoutController === null || timeoutController === void 0 || timeoutController.clear();
|
|
117
|
+
} catch (_unused) {
|
|
118
|
+
timeoutController === null || timeoutController === void 0 || timeoutController.clear();
|
|
119
|
+
if (skipSsrOnError) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ClientOnly.ClientOnly, {
|
|
120
|
+
fallback: skipSsrOnError === true ? void 0 : skipSsrOnError.fallback,
|
|
121
|
+
children
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__tanstack_react_query.Hydrate, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, {
|
|
125
|
+
state: (0, __tanstack_react_query.dehydrate)(queryClient),
|
|
126
|
+
children
|
|
127
|
+
}));
|
|
128
|
+
});
|
|
129
|
+
return _QueriesHydration.apply(this, arguments);
|
|
130
|
+
}
|
|
131
|
+
const createTimeoutController = (ms, errorMessage) => {
|
|
132
|
+
let timerId;
|
|
133
|
+
return {
|
|
134
|
+
promise: new Promise((_, reject) => {
|
|
135
|
+
timerId = setTimeout(() => reject(new Error(errorMessage)), ms);
|
|
136
|
+
}),
|
|
137
|
+
clear: () => timerId != null && clearTimeout(timerId)
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
Object.defineProperty(exports, 'QueriesHydration', {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () {
|
|
145
|
+
return QueriesHydration;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
//# sourceMappingURL=QueriesHydration-Cd2lBXvZ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueriesHydration-Cd2lBXvZ.cjs","names":["QueryClient","ClientOnly","Hydrate","timerId: ReturnType<typeof setTimeout> | undefined"],"sources":["../src/QueriesHydration.tsx"],"sourcesContent":["import {\n Hydrate,\n type HydrateProps,\n type OmitKeyof,\n QueryClient,\n type QueryOptions,\n type UseInfiniteQueryOptions,\n type WithRequired,\n dehydrate,\n} from '@tanstack/react-query'\nimport type { ReactNode } from 'react'\nimport { ClientOnly } from './components/ClientOnly'\n\n/**\n * A server component that fetches multiple queries on the server and hydrates them to the client.\n *\n * @experimental This component is experimental and may be changed or removed in the future.\n *\n * @description\n * QueriesHydration is designed for React Server Components (RSC).\n * It pre-fetches multiple queries on the server side and automatically hydrates\n * the data to the client, enabling seamless data synchronization between server and client.\n *\n * When errors occur during server-side fetching, the component gracefully falls back\n * to client-side rendering, ensuring your application remains resilient.\n *\n * @example\n * ```tsx\n * // app/page.tsx (Server Component)\n * import { Suspense } from 'react'\n * import { QueriesHydration } from '@suspensive/react-query'\n * import { queryOptions } from '@tanstack/react-query'\n *\n * const userQueryOptions = (userId: string) => queryOptions({\n * queryKey: ['user', userId],\n * queryFn: () => fetchUser(userId)\n * })\n *\n * const postsQueryOptions = () => queryOptions({\n * queryKey: ['posts'],\n * queryFn: () => fetchPosts()\n * })\n *\n * export default function Page({ userId }: { userId: string }) {\n * return (\n * <>\n * <Suspense fallback={<div>Loading user...</div>}>\n * <QueriesHydration queries={[userQueryOptions(userId)]}>\n * <UserProfile />\n * </QueriesHydration>\n * </Suspense>\n *\n * <Suspense fallback={<div>Loading posts...</div>}>\n * <QueriesHydration queries={[postsQueryOptions()]}>\n * <PostsList />\n * </QueriesHydration>\n * </Suspense>\n * </>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom error fallback\n * <Suspense fallback={<div>Loading user...</div>}>\n * <QueriesHydration\n * queries={[userQueryOptions(userId)]}\n * skipSsrOnError={{ fallback: <div>Fetching on client...</div> }}\n * >\n * <UserProfile />\n * </QueriesHydration>\n * </Suspense>\n * ```\n *\n * @see {@link https://suspensive.org/docs/react-query/QueriesHydration Documentation}\n */\nexport async function QueriesHydration({\n queries,\n children,\n queryClient = new QueryClient(),\n skipSsrOnError = true,\n timeout,\n ...props\n}: {\n /**\n * The QueryClient instance to use for fetching queries.\n */\n queryClient?: QueryClient\n /**\n * An array of query options or infinite query options to be fetched on the server. Each query must include a `queryKey`.\n * You can mix regular queries and infinite queries in the same array.\n */\n queries: (\n | WithRequired<QueryOptions<any, any, any, any>, 'queryKey'>\n | WithRequired<UseInfiniteQueryOptions<any, any, any, any, any>, 'queryKey'>\n )[]\n /**\n * Controls error handling behavior:\n * - `true` (default): Skips SSR and falls back to client-side rendering when server fetch fails\n * - `false`: Proceeds with SSR without hydration (retry fetching on client component server rendering)\n * - `{ fallback: ReactNode }`: Skips SSR with custom fallback UI during client-side rendering\n */\n skipSsrOnError?:\n | boolean\n | {\n fallback: ReactNode\n }\n /**\n * The timeout in milliseconds for the query.\n * If the query takes longer than the timeout, it will be considered as an error.\n * When not set, no timeout is applied.\n */\n timeout?: number\n} & OmitKeyof<HydrateProps, 'state'>) {\n const timeoutController =\n timeout != null && timeout >= 0\n ? createTimeoutController(timeout, `QueriesHydration: timeout after ${timeout} ms)`)\n : undefined\n try {\n const queriesPromise = Promise.all(\n queries.map((query) =>\n 'getNextPageParam' in query ? queryClient.fetchInfiniteQuery(query) : queryClient.fetchQuery(query)\n )\n )\n await (timeoutController != null ? Promise.race([queriesPromise, timeoutController.promise]) : queriesPromise)\n timeoutController?.clear()\n } catch {\n timeoutController?.clear()\n if (skipSsrOnError) {\n return (\n <ClientOnly fallback={skipSsrOnError === true ? undefined : skipSsrOnError.fallback}>{children}</ClientOnly>\n )\n }\n }\n return (\n <Hydrate {...props} state={dehydrate(queryClient)}>\n {children}\n </Hydrate>\n )\n}\n\nconst createTimeoutController = (ms: number, errorMessage: string) => {\n let timerId: ReturnType<typeof setTimeout> | undefined\n return {\n promise: new Promise<never>((_, reject) => {\n timerId = setTimeout(() => reject(new Error(errorMessage)), ms)\n }),\n clear: () => timerId != null && clearTimeout(timerId),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8EE;CACA;CACA;CACA;CACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALF,SAAsB,iBAAiB;;;;wDAqCD;MArCC,EACrC,SACA,UACA,cAAc,IAAIA,oCAAa,EAC/B,iBAAiB,MACjB,kBACG;EAgCH,MAAM,oBACJ,WAAW,QAAQ,WAAW,IAC1B,wBAAwB,SAAS,mCAAmC,QAAQ,MAAM,GAClF;AACN,MAAI;GACF,MAAM,iBAAiB,QAAQ,IAC7B,QAAQ,KAAK,UACX,sBAAsB,QAAQ,YAAY,mBAAmB,MAAM,GAAG,YAAY,WAAW,MAAM,CACpG,CACF;AACD,SAAO,qBAAqB,OAAO,QAAQ,KAAK,CAAC,gBAAgB,kBAAkB,QAAQ,CAAC,GAAG;AAC/F,mFAAmB,OAAO;oBACpB;AACN,mFAAmB,OAAO;AAC1B,OAAI,eACF,QACE,2CAACC;IAAW,UAAU,mBAAmB,OAAO,SAAY,eAAe;IAAW;KAAsB;;AAIlH,SACE,2CAACC,8GAAY;GAAO,6CAAiB,YAAY;GAC9C;KACO;;;;AAId,MAAM,2BAA2B,IAAY,iBAAyB;CACpE,IAAIC;AACJ,QAAO;EACL,SAAS,IAAI,SAAgB,GAAG,WAAW;AACzC,aAAU,iBAAiB,OAAO,IAAI,MAAM,aAAa,CAAC,EAAE,GAAG;IAC/D;EACF,aAAa,WAAW,QAAQ,aAAa,QAAQ;EACtD"}
|