@suspensive/react-query-4 3.19.3 → 3.19.4

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.
Files changed (46) hide show
  1. package/dist/IsFetching.cjs +1 -1
  2. package/dist/IsFetching.mjs +1 -1
  3. package/dist/Mutation.cjs +1 -1
  4. package/dist/Mutation.mjs +1 -1
  5. package/dist/QueriesHydration.cjs +116 -2
  6. package/dist/QueriesHydration.cjs.map +1 -0
  7. package/dist/QueriesHydration.mjs +116 -2
  8. package/dist/QueriesHydration.mjs.map +1 -0
  9. package/dist/SuspenseInfiniteQuery.cjs +1 -1
  10. package/dist/SuspenseInfiniteQuery.mjs +1 -1
  11. package/dist/SuspenseQuery.cjs +1 -1
  12. package/dist/SuspenseQuery.mjs +1 -1
  13. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.cjs +29 -0
  14. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.mjs +28 -0
  15. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/defineProperty.cjs +14 -0
  16. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/defineProperty.mjs +14 -0
  17. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.cjs +27 -0
  18. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.mjs +27 -0
  19. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.cjs +15 -0
  20. package/dist/{objectWithoutProperties-CZk5Qmfh.mjs → _virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.mjs} +2 -12
  21. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutPropertiesLoose.cjs +14 -0
  22. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutPropertiesLoose.mjs +13 -0
  23. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPrimitive.cjs +16 -0
  24. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPrimitive.mjs +16 -0
  25. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPropertyKey.cjs +11 -0
  26. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPropertyKey.mjs +11 -0
  27. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/typeof.cjs +18 -0
  28. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/typeof.mjs +12 -0
  29. package/dist/components/ClientOnly.cjs +0 -1
  30. package/dist/components/ClientOnly.cjs.map +1 -1
  31. package/dist/createGetQueryClient.cjs +1 -1
  32. package/dist/createGetQueryClient.mjs +1 -1
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.mjs +1 -1
  35. package/package.json +1 -1
  36. package/dist/QueriesHydration-B9tinfWA.cjs +0 -148
  37. package/dist/QueriesHydration-B9tinfWA.cjs.map +0 -1
  38. package/dist/QueriesHydration-MZQ7Oj60.mjs +0 -143
  39. package/dist/QueriesHydration-MZQ7Oj60.mjs.map +0 -1
  40. package/dist/components/ClientOnly.d.cts +0 -13
  41. package/dist/components/ClientOnly.d.cts.map +0 -1
  42. package/dist/components/ClientOnly.d.mts +0 -13
  43. package/dist/components/ClientOnly.d.mts.map +0 -1
  44. package/dist/objectSpread2-9HkiXZY2.cjs +0 -73
  45. package/dist/objectSpread2-BX3M3dlG.mjs +0 -67
  46. package/dist/objectWithoutProperties-CfjOeCpP.cjs +0 -31
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_objectWithoutProperties = require('./objectWithoutProperties-CfjOeCpP.cjs');
4
+ const require_objectWithoutProperties = require('./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.cjs');
5
5
  let _tanstack_react_query = require("@tanstack/react-query");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
7
 
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { t as _objectWithoutProperties } from "./objectWithoutProperties-CZk5Qmfh.mjs";
3
+ import { _objectWithoutProperties } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.mjs";
4
4
  import { useIsFetching } from "@tanstack/react-query";
5
5
  import { Fragment, jsx } from "react/jsx-runtime";
6
6
 
package/dist/Mutation.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_objectWithoutProperties = require('./objectWithoutProperties-CfjOeCpP.cjs');
4
+ const require_objectWithoutProperties = require('./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.cjs');
5
5
  let _tanstack_react_query = require("@tanstack/react-query");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
7
 
package/dist/Mutation.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { t as _objectWithoutProperties } from "./objectWithoutProperties-CZk5Qmfh.mjs";
3
+ import { _objectWithoutProperties } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.mjs";
4
4
  import { useMutation } from "@tanstack/react-query";
5
5
  import { Fragment, jsx } from "react/jsx-runtime";
6
6
 
@@ -1,4 +1,118 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_QueriesHydration = require('./QueriesHydration-B9tinfWA.cjs');
2
+ const require_objectWithoutProperties = require('./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.cjs');
3
+ const require_ClientOnly = require('./components/ClientOnly.cjs');
4
+ const require_objectSpread2 = require('./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.cjs');
5
+ const require_asyncToGenerator = require('./_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.cjs');
6
+ let _tanstack_react_query = require("@tanstack/react-query");
7
+ let react_jsx_runtime = require("react/jsx-runtime");
3
8
 
4
- exports.QueriesHydration = require_QueriesHydration.QueriesHydration;
9
+ //#region src/QueriesHydration.tsx
10
+ const _excluded = [
11
+ "queries",
12
+ "children",
13
+ "queryClient",
14
+ "skipSsrOnError",
15
+ "timeout"
16
+ ];
17
+ /**
18
+ * A server component that fetches multiple queries on the server and hydrates them to the client.
19
+ *
20
+ * @experimental This component is experimental and may be changed or removed in the future.
21
+ *
22
+ * @description
23
+ * QueriesHydration is designed for React Server Components (RSC).
24
+ * It pre-fetches multiple queries on the server side and automatically hydrates
25
+ * the data to the client, enabling seamless data synchronization between server and client.
26
+ *
27
+ * When errors occur during server-side fetching, the component gracefully falls back
28
+ * to client-side rendering, ensuring your application remains resilient.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * // app/page.tsx (Server Component)
33
+ * import { Suspense } from 'react'
34
+ * import { QueriesHydration } from '@suspensive/react-query'
35
+ * import { queryOptions } from '@tanstack/react-query'
36
+ *
37
+ * const userQueryOptions = (userId: string) => queryOptions({
38
+ * queryKey: ['user', userId],
39
+ * queryFn: () => fetchUser(userId)
40
+ * })
41
+ *
42
+ * const postsQueryOptions = () => queryOptions({
43
+ * queryKey: ['posts'],
44
+ * queryFn: () => fetchPosts()
45
+ * })
46
+ *
47
+ * export default function Page({ userId }: { userId: string }) {
48
+ * return (
49
+ * <>
50
+ * <Suspense fallback={<div>Loading user...</div>}>
51
+ * <QueriesHydration queries={[userQueryOptions(userId)]}>
52
+ * <UserProfile />
53
+ * </QueriesHydration>
54
+ * </Suspense>
55
+ *
56
+ * <Suspense fallback={<div>Loading posts...</div>}>
57
+ * <QueriesHydration queries={[postsQueryOptions()]}>
58
+ * <PostsList />
59
+ * </QueriesHydration>
60
+ * </Suspense>
61
+ * </>
62
+ * )
63
+ * }
64
+ * ```
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * // With custom error fallback
69
+ * <Suspense fallback={<div>Loading user...</div>}>
70
+ * <QueriesHydration
71
+ * queries={[userQueryOptions(userId)]}
72
+ * skipSsrOnError={{ fallback: <div>Fetching on client...</div> }}
73
+ * >
74
+ * <UserProfile />
75
+ * </QueriesHydration>
76
+ * </Suspense>
77
+ * ```
78
+ *
79
+ * @see {@link https://suspensive.org/docs/react-query/QueriesHydration Documentation}
80
+ */
81
+ function QueriesHydration(_x) {
82
+ return _QueriesHydration.apply(this, arguments);
83
+ }
84
+ function _QueriesHydration() {
85
+ _QueriesHydration = require_asyncToGenerator._asyncToGenerator(function* (_ref) {
86
+ let { queries, children, queryClient = new _tanstack_react_query.QueryClient(), skipSsrOnError = true, timeout } = _ref, props = require_objectWithoutProperties._objectWithoutProperties(_ref, _excluded);
87
+ const timeoutController = timeout != null && timeout >= 0 ? createTimeoutController(timeout, `QueriesHydration: timeout after ${timeout} ms)`) : void 0;
88
+ try {
89
+ const queriesPromise = Promise.all(queries.map((query) => "getNextPageParam" in query ? queryClient.fetchInfiniteQuery(query) : queryClient.fetchQuery(query)));
90
+ yield timeoutController != null ? Promise.race([queriesPromise, timeoutController.promise]) : queriesPromise;
91
+ timeoutController === null || timeoutController === void 0 || timeoutController.clear();
92
+ } catch (_unused) {
93
+ timeoutController === null || timeoutController === void 0 || timeoutController.clear();
94
+ if (skipSsrOnError) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ClientOnly.ClientOnly, {
95
+ fallback: skipSsrOnError === true ? void 0 : skipSsrOnError.fallback,
96
+ children
97
+ });
98
+ }
99
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tanstack_react_query.Hydrate, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, {
100
+ state: (0, _tanstack_react_query.dehydrate)(queryClient),
101
+ children
102
+ }));
103
+ });
104
+ return _QueriesHydration.apply(this, arguments);
105
+ }
106
+ const createTimeoutController = (ms, errorMessage) => {
107
+ let timerId;
108
+ return {
109
+ promise: new Promise((_, reject) => {
110
+ timerId = setTimeout(() => reject(new Error(errorMessage)), ms);
111
+ }),
112
+ clear: () => timerId != null && clearTimeout(timerId)
113
+ };
114
+ };
115
+
116
+ //#endregion
117
+ exports.QueriesHydration = QueriesHydration;
118
+ //# sourceMappingURL=QueriesHydration.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueriesHydration.cjs","names":["QueryClient","ClientOnly","Hydrate"],"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;;;;iFAqCD;MArCC,EACrC,SACA,UACA,cAAc,IAAIA,mCAAa,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,+BAAD;IAAY,UAAU,mBAAmB,OAAO,SAAY,eAAe;IAAW;IAAsB;;AAIlH,SACE,2CAACC,6GAAY;GAAO,4CAAiB,YAAY;GAC9C;IACO;;;;AAId,MAAM,2BAA2B,IAAY,iBAAyB;CACpE,IAAI;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"}
@@ -1,3 +1,117 @@
1
- import { t as QueriesHydration } from "./QueriesHydration-MZQ7Oj60.mjs";
1
+ import { _objectWithoutProperties } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.mjs";
2
+ import { ClientOnly } from "./components/ClientOnly.mjs";
3
+ import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.mjs";
4
+ import { _asyncToGenerator } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.mjs";
5
+ import { Hydrate, QueryClient, dehydrate } from "@tanstack/react-query";
6
+ import { jsx } from "react/jsx-runtime";
2
7
 
3
- export { QueriesHydration };
8
+ //#region src/QueriesHydration.tsx
9
+ const _excluded = [
10
+ "queries",
11
+ "children",
12
+ "queryClient",
13
+ "skipSsrOnError",
14
+ "timeout"
15
+ ];
16
+ /**
17
+ * A server component that fetches multiple queries on the server and hydrates them to the client.
18
+ *
19
+ * @experimental This component is experimental and may be changed or removed in the future.
20
+ *
21
+ * @description
22
+ * QueriesHydration is designed for React Server Components (RSC).
23
+ * It pre-fetches multiple queries on the server side and automatically hydrates
24
+ * the data to the client, enabling seamless data synchronization between server and client.
25
+ *
26
+ * When errors occur during server-side fetching, the component gracefully falls back
27
+ * to client-side rendering, ensuring your application remains resilient.
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * // app/page.tsx (Server Component)
32
+ * import { Suspense } from 'react'
33
+ * import { QueriesHydration } from '@suspensive/react-query'
34
+ * import { queryOptions } from '@tanstack/react-query'
35
+ *
36
+ * const userQueryOptions = (userId: string) => queryOptions({
37
+ * queryKey: ['user', userId],
38
+ * queryFn: () => fetchUser(userId)
39
+ * })
40
+ *
41
+ * const postsQueryOptions = () => queryOptions({
42
+ * queryKey: ['posts'],
43
+ * queryFn: () => fetchPosts()
44
+ * })
45
+ *
46
+ * export default function Page({ userId }: { userId: string }) {
47
+ * return (
48
+ * <>
49
+ * <Suspense fallback={<div>Loading user...</div>}>
50
+ * <QueriesHydration queries={[userQueryOptions(userId)]}>
51
+ * <UserProfile />
52
+ * </QueriesHydration>
53
+ * </Suspense>
54
+ *
55
+ * <Suspense fallback={<div>Loading posts...</div>}>
56
+ * <QueriesHydration queries={[postsQueryOptions()]}>
57
+ * <PostsList />
58
+ * </QueriesHydration>
59
+ * </Suspense>
60
+ * </>
61
+ * )
62
+ * }
63
+ * ```
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * // With custom error fallback
68
+ * <Suspense fallback={<div>Loading user...</div>}>
69
+ * <QueriesHydration
70
+ * queries={[userQueryOptions(userId)]}
71
+ * skipSsrOnError={{ fallback: <div>Fetching on client...</div> }}
72
+ * >
73
+ * <UserProfile />
74
+ * </QueriesHydration>
75
+ * </Suspense>
76
+ * ```
77
+ *
78
+ * @see {@link https://suspensive.org/docs/react-query/QueriesHydration Documentation}
79
+ */
80
+ function QueriesHydration(_x) {
81
+ return _QueriesHydration.apply(this, arguments);
82
+ }
83
+ function _QueriesHydration() {
84
+ _QueriesHydration = _asyncToGenerator(function* (_ref) {
85
+ let { queries, children, queryClient = new QueryClient(), skipSsrOnError = true, timeout } = _ref, props = _objectWithoutProperties(_ref, _excluded);
86
+ const timeoutController = timeout != null && timeout >= 0 ? createTimeoutController(timeout, `QueriesHydration: timeout after ${timeout} ms)`) : void 0;
87
+ try {
88
+ const queriesPromise = Promise.all(queries.map((query) => "getNextPageParam" in query ? queryClient.fetchInfiniteQuery(query) : queryClient.fetchQuery(query)));
89
+ yield timeoutController != null ? Promise.race([queriesPromise, timeoutController.promise]) : queriesPromise;
90
+ timeoutController === null || timeoutController === void 0 || timeoutController.clear();
91
+ } catch (_unused) {
92
+ timeoutController === null || timeoutController === void 0 || timeoutController.clear();
93
+ if (skipSsrOnError) return /* @__PURE__ */ jsx(ClientOnly, {
94
+ fallback: skipSsrOnError === true ? void 0 : skipSsrOnError.fallback,
95
+ children
96
+ });
97
+ }
98
+ return /* @__PURE__ */ jsx(Hydrate, _objectSpread2(_objectSpread2({}, props), {}, {
99
+ state: dehydrate(queryClient),
100
+ children
101
+ }));
102
+ });
103
+ return _QueriesHydration.apply(this, arguments);
104
+ }
105
+ const createTimeoutController = (ms, errorMessage) => {
106
+ let timerId;
107
+ return {
108
+ promise: new Promise((_, reject) => {
109
+ timerId = setTimeout(() => reject(new Error(errorMessage)), ms);
110
+ }),
111
+ clear: () => timerId != null && clearTimeout(timerId)
112
+ };
113
+ };
114
+
115
+ //#endregion
116
+ export { QueriesHydration };
117
+ //# sourceMappingURL=QueriesHydration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueriesHydration.mjs","names":[],"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,YAAD;IAAY,UAAU,mBAAmB,OAAO,SAAY,eAAe;IAAW;IAAsB;;AAIlH,SACE,oBAAC,2CAAY;GAAO,OAAO,UAAU,YAAY;GAC9C;IACO;;;;AAId,MAAM,2BAA2B,IAAY,iBAAyB;CACpE,IAAI;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"}
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_objectWithoutProperties = require('./objectWithoutProperties-CfjOeCpP.cjs');
4
+ const require_objectWithoutProperties = require('./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.cjs');
5
5
  let _tanstack_react_query = require("@tanstack/react-query");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
7
 
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { t as _objectWithoutProperties } from "./objectWithoutProperties-CZk5Qmfh.mjs";
3
+ import { _objectWithoutProperties } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.mjs";
4
4
  import { useSuspenseInfiniteQuery } from "@tanstack/react-query";
5
5
  import { Fragment, jsx } from "react/jsx-runtime";
6
6
 
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_objectWithoutProperties = require('./objectWithoutProperties-CfjOeCpP.cjs');
4
+ const require_objectWithoutProperties = require('./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.cjs');
5
5
  let _tanstack_react_query = require("@tanstack/react-query");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
7
 
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { t as _objectWithoutProperties } from "./objectWithoutProperties-CZk5Qmfh.mjs";
3
+ import { _objectWithoutProperties } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.mjs";
4
4
  import { useSuspenseQuery } from "@tanstack/react-query";
5
5
  import { Fragment, jsx } from "react/jsx-runtime";
6
6
 
@@ -0,0 +1,29 @@
1
+
2
+ //#region \0@oxc-project+runtime@0.115.0/helpers/asyncToGenerator.js
3
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
4
+ try {
5
+ var i = n[a](c), u = i.value;
6
+ } catch (n) {
7
+ e(n);
8
+ return;
9
+ }
10
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
11
+ }
12
+ function _asyncToGenerator(n) {
13
+ return function() {
14
+ var t = this, e = arguments;
15
+ return new Promise(function(r, o) {
16
+ var a = n.apply(t, e);
17
+ function _next(n) {
18
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
19
+ }
20
+ function _throw(n) {
21
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
22
+ }
23
+ _next(void 0);
24
+ });
25
+ };
26
+ }
27
+
28
+ //#endregion
29
+ exports._asyncToGenerator = _asyncToGenerator;
@@ -0,0 +1,28 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/asyncToGenerator.js
2
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
3
+ try {
4
+ var i = n[a](c), u = i.value;
5
+ } catch (n) {
6
+ e(n);
7
+ return;
8
+ }
9
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
10
+ }
11
+ function _asyncToGenerator(n) {
12
+ return function() {
13
+ var t = this, e = arguments;
14
+ return new Promise(function(r, o) {
15
+ var a = n.apply(t, e);
16
+ function _next(n) {
17
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
18
+ }
19
+ function _throw(n) {
20
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
21
+ }
22
+ _next(void 0);
23
+ });
24
+ };
25
+ }
26
+
27
+ //#endregion
28
+ export { _asyncToGenerator };
@@ -0,0 +1,14 @@
1
+ const require_toPropertyKey = require('./toPropertyKey.cjs');
2
+
3
+ //#region \0@oxc-project+runtime@0.115.0/helpers/defineProperty.js
4
+ function _defineProperty(e, r, t) {
5
+ return (r = require_toPropertyKey.toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
6
+ value: t,
7
+ enumerable: !0,
8
+ configurable: !0,
9
+ writable: !0
10
+ }) : e[r] = t, e;
11
+ }
12
+
13
+ //#endregion
14
+ exports._defineProperty = _defineProperty;
@@ -0,0 +1,14 @@
1
+ import { toPropertyKey } from "./toPropertyKey.mjs";
2
+
3
+ //#region \0@oxc-project+runtime@0.115.0/helpers/defineProperty.js
4
+ function _defineProperty(e, r, t) {
5
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
6
+ value: t,
7
+ enumerable: !0,
8
+ configurable: !0,
9
+ writable: !0
10
+ }) : e[r] = t, e;
11
+ }
12
+
13
+ //#endregion
14
+ export { _defineProperty };
@@ -0,0 +1,27 @@
1
+ const require_defineProperty = require('./defineProperty.cjs');
2
+
3
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectSpread2.js
4
+ function ownKeys(e, r) {
5
+ var t = Object.keys(e);
6
+ if (Object.getOwnPropertySymbols) {
7
+ var o = Object.getOwnPropertySymbols(e);
8
+ r && (o = o.filter(function(r) {
9
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
10
+ })), t.push.apply(t, o);
11
+ }
12
+ return t;
13
+ }
14
+ function _objectSpread2(e) {
15
+ for (var r = 1; r < arguments.length; r++) {
16
+ var t = null != arguments[r] ? arguments[r] : {};
17
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
18
+ require_defineProperty._defineProperty(e, r, t[r]);
19
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
20
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
21
+ });
22
+ }
23
+ return e;
24
+ }
25
+
26
+ //#endregion
27
+ exports._objectSpread2 = _objectSpread2;
@@ -0,0 +1,27 @@
1
+ import { _defineProperty } from "./defineProperty.mjs";
2
+
3
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectSpread2.js
4
+ function ownKeys(e, r) {
5
+ var t = Object.keys(e);
6
+ if (Object.getOwnPropertySymbols) {
7
+ var o = Object.getOwnPropertySymbols(e);
8
+ r && (o = o.filter(function(r) {
9
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
10
+ })), t.push.apply(t, o);
11
+ }
12
+ return t;
13
+ }
14
+ function _objectSpread2(e) {
15
+ for (var r = 1; r < arguments.length; r++) {
16
+ var t = null != arguments[r] ? arguments[r] : {};
17
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
18
+ _defineProperty(e, r, t[r]);
19
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
20
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
21
+ });
22
+ }
23
+ return e;
24
+ }
25
+
26
+ //#endregion
27
+ export { _objectSpread2 };
@@ -0,0 +1,15 @@
1
+ const require_objectWithoutPropertiesLoose = require('./objectWithoutPropertiesLoose.cjs');
2
+
3
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectWithoutProperties.js
4
+ function _objectWithoutProperties(e, t) {
5
+ if (null == e) return {};
6
+ var o, r, i = require_objectWithoutPropertiesLoose._objectWithoutPropertiesLoose(e, t);
7
+ if (Object.getOwnPropertySymbols) {
8
+ var s = Object.getOwnPropertySymbols(e);
9
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
10
+ }
11
+ return i;
12
+ }
13
+
14
+ //#endregion
15
+ exports._objectWithoutProperties = _objectWithoutProperties;
@@ -1,15 +1,5 @@
1
- //#region \0@oxc-project+runtime@0.115.0/helpers/objectWithoutPropertiesLoose.js
2
- function _objectWithoutPropertiesLoose(r, e) {
3
- if (null == r) return {};
4
- var t = {};
5
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
6
- if (e.includes(n)) continue;
7
- t[n] = r[n];
8
- }
9
- return t;
10
- }
1
+ import { _objectWithoutPropertiesLoose } from "./objectWithoutPropertiesLoose.mjs";
11
2
 
12
- //#endregion
13
3
  //#region \0@oxc-project+runtime@0.115.0/helpers/objectWithoutProperties.js
14
4
  function _objectWithoutProperties(e, t) {
15
5
  if (null == e) return {};
@@ -22,4 +12,4 @@ function _objectWithoutProperties(e, t) {
22
12
  }
23
13
 
24
14
  //#endregion
25
- export { _objectWithoutProperties as t };
15
+ export { _objectWithoutProperties };
@@ -0,0 +1,14 @@
1
+
2
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectWithoutPropertiesLoose.js
3
+ function _objectWithoutPropertiesLoose(r, e) {
4
+ if (null == r) return {};
5
+ var t = {};
6
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
7
+ if (e.includes(n)) continue;
8
+ t[n] = r[n];
9
+ }
10
+ return t;
11
+ }
12
+
13
+ //#endregion
14
+ exports._objectWithoutPropertiesLoose = _objectWithoutPropertiesLoose;
@@ -0,0 +1,13 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectWithoutPropertiesLoose.js
2
+ function _objectWithoutPropertiesLoose(r, e) {
3
+ if (null == r) return {};
4
+ var t = {};
5
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
6
+ if (e.includes(n)) continue;
7
+ t[n] = r[n];
8
+ }
9
+ return t;
10
+ }
11
+
12
+ //#endregion
13
+ export { _objectWithoutPropertiesLoose };
@@ -0,0 +1,16 @@
1
+ const require_typeof = require('./typeof.cjs');
2
+
3
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPrimitive.js
4
+ function toPrimitive(t, r) {
5
+ if ("object" != require_typeof._typeof(t) || !t) return t;
6
+ var e = t[Symbol.toPrimitive];
7
+ if (void 0 !== e) {
8
+ var i = e.call(t, r || "default");
9
+ if ("object" != require_typeof._typeof(i)) return i;
10
+ throw new TypeError("@@toPrimitive must return a primitive value.");
11
+ }
12
+ return ("string" === r ? String : Number)(t);
13
+ }
14
+
15
+ //#endregion
16
+ exports.toPrimitive = toPrimitive;
@@ -0,0 +1,16 @@
1
+ import { _typeof } from "./typeof.mjs";
2
+
3
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPrimitive.js
4
+ function toPrimitive(t, r) {
5
+ if ("object" != _typeof(t) || !t) return t;
6
+ var e = t[Symbol.toPrimitive];
7
+ if (void 0 !== e) {
8
+ var i = e.call(t, r || "default");
9
+ if ("object" != _typeof(i)) return i;
10
+ throw new TypeError("@@toPrimitive must return a primitive value.");
11
+ }
12
+ return ("string" === r ? String : Number)(t);
13
+ }
14
+
15
+ //#endregion
16
+ export { toPrimitive };
@@ -0,0 +1,11 @@
1
+ const require_typeof = require('./typeof.cjs');
2
+ const require_toPrimitive = require('./toPrimitive.cjs');
3
+
4
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPropertyKey.js
5
+ function toPropertyKey(t) {
6
+ var i = require_toPrimitive.toPrimitive(t, "string");
7
+ return "symbol" == require_typeof._typeof(i) ? i : i + "";
8
+ }
9
+
10
+ //#endregion
11
+ exports.toPropertyKey = toPropertyKey;
@@ -0,0 +1,11 @@
1
+ import { _typeof } from "./typeof.mjs";
2
+ import { toPrimitive } from "./toPrimitive.mjs";
3
+
4
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPropertyKey.js
5
+ function toPropertyKey(t) {
6
+ var i = toPrimitive(t, "string");
7
+ return "symbol" == _typeof(i) ? i : i + "";
8
+ }
9
+
10
+ //#endregion
11
+ export { toPropertyKey };
@@ -0,0 +1,18 @@
1
+
2
+ //#region \0@oxc-project+runtime@0.115.0/helpers/typeof.js
3
+ function _typeof(o) {
4
+ "@babel/helpers - typeof";
5
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
6
+ return typeof o;
7
+ } : function(o) {
8
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
9
+ }, _typeof(o);
10
+ }
11
+
12
+ //#endregion
13
+ Object.defineProperty(exports, '_typeof', {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _typeof;
17
+ }
18
+ });