@tanstack/preact-query 5.103.1 → 5.103.3

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 (113) hide show
  1. package/README.md +2 -2
  2. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  3. package/build/legacy/infiniteQueryOptions.d.cts +1 -1
  4. package/build/legacy/infiniteQueryOptions.d.ts +1 -1
  5. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  6. package/build/legacy/queryOptions.cjs.map +1 -1
  7. package/build/legacy/queryOptions.d.cts +3 -2
  8. package/build/legacy/queryOptions.d.cts.map +1 -1
  9. package/build/legacy/queryOptions.d.ts +3 -2
  10. package/build/legacy/queryOptions.d.ts.map +1 -1
  11. package/build/legacy/queryOptions.js.map +1 -1
  12. package/build/legacy/suspense.cjs.map +1 -1
  13. package/build/legacy/suspense.d.cts.map +1 -1
  14. package/build/legacy/suspense.d.ts.map +1 -1
  15. package/build/legacy/suspense.js.map +1 -1
  16. package/build/legacy/types.cjs.map +1 -1
  17. package/build/legacy/types.d.cts +5 -4
  18. package/build/legacy/types.d.cts.map +1 -1
  19. package/build/legacy/types.d.ts +5 -4
  20. package/build/legacy/types.d.ts.map +1 -1
  21. package/build/legacy/types.js.map +1 -1
  22. package/build/legacy/useBaseQuery.cjs.map +1 -1
  23. package/build/legacy/useBaseQuery.js.map +1 -1
  24. package/build/legacy/useQueries.cjs.map +1 -1
  25. package/build/legacy/useQueries.d.cts +6 -2
  26. package/build/legacy/useQueries.d.cts.map +1 -1
  27. package/build/legacy/useQueries.d.ts +6 -2
  28. package/build/legacy/useQueries.d.ts.map +1 -1
  29. package/build/legacy/useQueries.js.map +1 -1
  30. package/build/legacy/useQuery.cjs.map +1 -1
  31. package/build/legacy/useQuery.d.cts +7 -2
  32. package/build/legacy/useQuery.d.cts.map +1 -1
  33. package/build/legacy/useQuery.d.ts +7 -2
  34. package/build/legacy/useQuery.d.ts.map +1 -1
  35. package/build/legacy/useQuery.js.map +1 -1
  36. package/build/legacy/useSuspenseQueries.cjs.map +1 -1
  37. package/build/legacy/useSuspenseQueries.d.cts +7 -3
  38. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  39. package/build/legacy/useSuspenseQueries.d.ts +7 -3
  40. package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
  41. package/build/legacy/useSuspenseQueries.js.map +1 -1
  42. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  43. package/build/modern/infiniteQueryOptions.d.cts +1 -1
  44. package/build/modern/infiniteQueryOptions.d.ts +1 -1
  45. package/build/modern/infiniteQueryOptions.js.map +1 -1
  46. package/build/modern/queryOptions.cjs.map +1 -1
  47. package/build/modern/queryOptions.d.cts +3 -2
  48. package/build/modern/queryOptions.d.cts.map +1 -1
  49. package/build/modern/queryOptions.d.ts +3 -2
  50. package/build/modern/queryOptions.d.ts.map +1 -1
  51. package/build/modern/queryOptions.js.map +1 -1
  52. package/build/modern/suspense.cjs.map +1 -1
  53. package/build/modern/suspense.d.cts.map +1 -1
  54. package/build/modern/suspense.d.ts.map +1 -1
  55. package/build/modern/suspense.js.map +1 -1
  56. package/build/modern/types.cjs.map +1 -1
  57. package/build/modern/types.d.cts +5 -4
  58. package/build/modern/types.d.cts.map +1 -1
  59. package/build/modern/types.d.ts +5 -4
  60. package/build/modern/types.d.ts.map +1 -1
  61. package/build/modern/types.js.map +1 -1
  62. package/build/modern/useBaseQuery.cjs.map +1 -1
  63. package/build/modern/useBaseQuery.js.map +1 -1
  64. package/build/modern/useQueries.cjs.map +1 -1
  65. package/build/modern/useQueries.d.cts +6 -2
  66. package/build/modern/useQueries.d.cts.map +1 -1
  67. package/build/modern/useQueries.d.ts +6 -2
  68. package/build/modern/useQueries.d.ts.map +1 -1
  69. package/build/modern/useQueries.js.map +1 -1
  70. package/build/modern/useQuery.cjs.map +1 -1
  71. package/build/modern/useQuery.d.cts +7 -2
  72. package/build/modern/useQuery.d.cts.map +1 -1
  73. package/build/modern/useQuery.d.ts +7 -2
  74. package/build/modern/useQuery.d.ts.map +1 -1
  75. package/build/modern/useQuery.js.map +1 -1
  76. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  77. package/build/modern/useSuspenseQueries.d.cts +7 -3
  78. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  79. package/build/modern/useSuspenseQueries.d.ts +7 -3
  80. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  81. package/build/modern/useSuspenseQueries.js.map +1 -1
  82. package/package.json +9 -10
  83. package/src/infiniteQueryOptions.ts +1 -1
  84. package/src/queryOptions.ts +4 -4
  85. package/src/suspense.ts +1 -2
  86. package/src/types.ts +5 -4
  87. package/src/useBaseQuery.ts +3 -6
  88. package/src/useQueries.ts +6 -2
  89. package/src/useQuery.ts +7 -2
  90. package/src/useSuspenseQueries.ts +7 -3
  91. package/build/query-codemods/eslint.config.js +0 -25
  92. package/build/query-codemods/package.json +0 -38
  93. package/build/query-codemods/root.eslint.config.js +0 -113
  94. package/build/query-codemods/tsconfig.json +0 -8
  95. package/build/query-codemods/vite.config.ts +0 -30
  96. /package/build/codemods/{src/utils → utils}/index.cjs +0 -0
  97. /package/build/codemods/{src/utils → utils}/transformers/query-cache-transformer.cjs +0 -0
  98. /package/build/codemods/{src/utils → utils}/transformers/query-client-transformer.cjs +0 -0
  99. /package/build/codemods/{src/utils → utils}/transformers/use-query-like-transformer.cjs +0 -0
  100. /package/build/codemods/{src/v4 → v4}/key-transformation.cjs +0 -0
  101. /package/build/codemods/{src/v4 → v4}/replace-import-specifier.cjs +0 -0
  102. /package/build/codemods/{src/v4 → v4}/utils/replacers/key-replacer.cjs +0 -0
  103. /package/build/codemods/{src/v5 → v5}/is-loading/is-loading.cjs +0 -0
  104. /package/build/codemods/{src/v5 → v5}/keep-previous-data/README.md +0 -0
  105. /package/build/codemods/{src/v5 → v5}/keep-previous-data/keep-previous-data.cjs +0 -0
  106. /package/build/codemods/{src/v5 → v5}/keep-previous-data/utils/already-has-placeholder-data-property.cjs +0 -0
  107. /package/build/codemods/{src/v5 → v5}/remove-overloads/remove-overloads.cjs +0 -0
  108. /package/build/codemods/{src/v5 → v5}/remove-overloads/transformers/filter-aware-usage-transformer.cjs +0 -0
  109. /package/build/codemods/{src/v5 → v5}/remove-overloads/transformers/query-fn-aware-usage-transformer.cjs +0 -0
  110. /package/build/codemods/{src/v5 → v5}/remove-overloads/utils/index.cjs +0 -0
  111. /package/build/codemods/{src/v5 → v5}/remove-overloads/utils/unknown-usage-error.cjs +0 -0
  112. /package/build/codemods/{src/v5 → v5}/rename-hydrate/rename-hydrate.cjs +0 -0
  113. /package/build/codemods/{src/v5 → v5}/rename-properties/rename-properties.cjs +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspenseQueries.js","names":[],"sources":["../../src/useSuspenseQueries.ts"],"sourcesContent":["import { skipToken } from '@tanstack/query-core'\nimport type {\n DefaultError,\n QueryClient,\n QueryFunction,\n ThrowOnError,\n} from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useQueries } from './useQueries'\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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":";;;;AA8lBA,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":["import { skipToken } from '@tanstack/query-core'\nimport type {\n DefaultError,\n QueryClient,\n QueryFunction,\n ThrowOnError,\n} from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useQueries } from './useQueries'\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 — past that, a tuple falls back to\n * a single homogeneous {@link UseSuspenseQueryOptions} type.\n *\n * An opaque array (e.g. `unknown[]`) is returned as-is; a non-tuple array whose element type structurally\n * matches a query options object is mapped per-element instead, still inferring each entry individually; any\n * other non-tuple array — one whose element type doesn't match the expected options shape — falls back to\n * that same homogeneous options type too.\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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 'preact/compat'\n * import { useErrorBoundary } from 'preact/hooks'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseQueries,\n * } from '@tanstack/preact-query'\n * import type { ComponentChildren } from 'preact'\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 * function ErrorBoundary({\n * children,\n * onReset,\n * fallbackRender,\n * }: {\n * children: ComponentChildren\n * onReset: () => void\n * fallbackRender: (props: {\n * error: Error\n * resetErrorBoundary: () => void\n * }) => ComponentChildren\n * }) {\n * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())\n *\n * if (error) return fallbackRender({ error, resetErrorBoundary })\n *\n * return children\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":";;;;AAkmBA,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/preact-query",
3
- "version": "5.103.1",
3
+ "version": "5.103.3",
4
4
  "description": "Hooks for managing, caching and syncing asynchronous and remote data in preact",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -43,20 +43,19 @@
43
43
  "!build/codemods/**/__tests__"
44
44
  ],
45
45
  "dependencies": {
46
- "@tanstack/query-core": "5.103.1"
46
+ "@tanstack/query-core": "5.103.3"
47
47
  },
48
48
  "devDependencies": {
49
- "@preact/preset-vite": "^2.10.2",
49
+ "@preact/preset-vite": "^2.10.6",
50
+ "@tanstack/query-persist-client-core": "5.103.3",
51
+ "@tanstack/query-test-utils": "0.0.0",
50
52
  "@testing-library/preact": "^3.2.4",
51
- "cpy-cli": "^5.0.0",
52
53
  "eslint-config-preact": "^2.0.0",
53
- "npm-run-all2": "^5.0.0",
54
- "preact": "^10.28.0",
54
+ "npm-run-all2": "^9.0.3",
55
+ "preact": "^10.29.8",
55
56
  "preact-render-to-string": "^6.6.4",
56
57
  "typescript": "6.0.3",
57
- "typescript-eslint": "^8.54.0",
58
- "@tanstack/query-persist-client-core": "5.103.1",
59
- "@tanstack/query-test-utils": "0.0.0"
58
+ "typescript-eslint": "^8.54.0"
60
59
  },
61
60
  "peerDependencies": {
62
61
  "preact": "^10.0.0"
@@ -77,6 +76,6 @@
77
76
  "test:build": "publint --strict && attw --pack",
78
77
  "build": "pnpm build:tsdown && pnpm build:codemods",
79
78
  "build:tsdown": "tsdown --tsconfig tsconfig.prod.json",
80
- "build:codemods": "cpy ../query-codemods/* ./build/codemods"
79
+ "build:codemods": "rm -rf ./build/codemods && mkdir ./build/codemods && cp -r ../query-codemods/src/* ./build/codemods"
81
80
  }
82
81
  }
@@ -92,7 +92,7 @@ export type UnusedSkipTokenInfiniteOptions<
92
92
 
93
93
  /**
94
94
  * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
95
- * never `undefined`.
95
+ * never `undefined` (unless a `select` changes `TData` to include `undefined`).
96
96
  *
97
97
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
98
98
  * @template TError - The type of errors your `queryFn` may throw.
@@ -71,7 +71,7 @@ export type UnusedSkipTokenOptions<
71
71
 
72
72
  /**
73
73
  * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
74
- * `undefined`.
74
+ * `undefined` (unless a `select` changes `TData` to include `undefined`).
75
75
  *
76
76
  * @template TQueryFnData - The type your `queryFn` resolves to.
77
77
  * @template TError - The type of errors your `queryFn` may throw.
@@ -92,8 +92,7 @@ export type DefinedInitialDataOptions<
92
92
  * cache.
93
93
  */
94
94
  initialData:
95
- | NonUndefinedGuard<TQueryFnData>
96
- | (() => NonUndefinedGuard<TQueryFnData>)
95
+ NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)
97
96
  /**
98
97
  * Optional here, but omitting it is only safe when no fetch will be attempted — for example with
99
98
  * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
@@ -107,7 +106,8 @@ export type DefinedInitialDataOptions<
107
106
  * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
108
107
  * is the query key to generate options for.
109
108
  *
110
- * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
109
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
110
+ * a `select` changes `TData` to include `undefined`).
111
111
  *
112
112
  * @see {@link useQuery} to run a query with these options.
113
113
  * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
package/src/suspense.ts CHANGED
@@ -49,8 +49,7 @@ export const ensureSuspenseTimers = (
49
49
 
50
50
  export const shouldSuspend = (
51
51
  defaultedOptions:
52
- | DefaultedQueryObserverOptions<any, any, any, any, any>
53
- | undefined,
52
+ DefaultedQueryObserverOptions<any, any, any, any, any> | undefined,
54
53
  result: QueryObserverResult<any, any>,
55
54
  ) => defaultedOptions?.suspense && result.isPending
56
55
 
package/src/types.ts CHANGED
@@ -343,8 +343,8 @@ export type UseSuspenseQueryResult<
343
343
 
344
344
  /**
345
345
  * The result of `useQuery` when `initialData` is set, or of `useSuspenseQuery` before the `isPlaceholderData`
346
- * omission — `data` is never `undefined`. Re-exports {@link DefinedQueryObserverResult} from
347
- * `@tanstack/query-core`.
346
+ * omission — `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).
347
+ * Re-exports {@link DefinedQueryObserverResult} from `@tanstack/query-core`.
348
348
  *
349
349
  * @template TData - The type `data` ends up as after `select` runs.
350
350
  * @template TError - The type of errors your `queryFn` may throw.
@@ -367,8 +367,9 @@ export type UseInfiniteQueryResult<
367
367
  > = InfiniteQueryObserverResult<TData, TError>
368
368
 
369
369
  /**
370
- * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined`. Re-exports
371
- * {@link DefinedInfiniteQueryObserverResult} from `@tanstack/query-core`.
370
+ * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a
371
+ * `select` changes `TData` to include `undefined`). Re-exports {@link DefinedInfiniteQueryObserverResult}
372
+ * from `@tanstack/query-core`.
372
373
  *
373
374
  * @template TData - The type `data` ends up as after `select` runs.
374
375
  * @template TError - The type of errors your `queryFn` may throw.
@@ -55,12 +55,9 @@ export function useBaseQuery<
55
55
 
56
56
  const query = client
57
57
  .getQueryCache()
58
- .get<
59
- TQueryFnData,
60
- TError,
61
- TQueryData,
62
- TQueryKey
63
- >(defaultedOptions.queryHash)
58
+ .get<TQueryFnData, TError, TQueryData, TQueryKey>(
59
+ defaultedOptions.queryHash,
60
+ )
64
61
 
65
62
  if (process.env.NODE_ENV !== 'production') {
66
63
  if (!defaultedOptions.queryFn) {
package/src/useQueries.ts CHANGED
@@ -143,10 +143,14 @@ type GetUseQueryResult<T> =
143
143
 
144
144
  /**
145
145
  * The `queries` array accepted by `useQueries`. Recursively unwraps each tuple element so every entry's
146
- * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements. An opaque array (e.g.
147
- * `unknown[]`) is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls
146
+ * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements — past that, a tuple falls
148
147
  * back to a single homogeneous options type.
149
148
  *
149
+ * An opaque array (e.g. `unknown[]`) is returned as-is; a non-tuple array whose element type structurally
150
+ * matches a query options object is mapped per-element instead, still inferring each entry individually; any
151
+ * other non-tuple array — one whose element type doesn't match the expected options shape — falls back to
152
+ * that same homogeneous options type too.
153
+ *
150
154
  * @template T - The type of the `queries` array as written at the call site.
151
155
  * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
152
156
  * to be set explicitly.
package/src/useQuery.ts CHANGED
@@ -13,7 +13,8 @@ import type {
13
13
  import { useBaseQuery } from './useBaseQuery'
14
14
 
15
15
  /**
16
- * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
16
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
17
+ * a `select` changes `TData` to include `undefined`).
17
18
  *
18
19
  * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
19
20
  * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
@@ -223,7 +224,9 @@ export function useQuery<
223
224
  * ```
224
225
  *
225
226
  * @example
226
- * Seeding a detail query from an already-cached list, to skip the loading state:
227
+ * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries
228
+ * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was
229
+ * fetched rather than from now:
227
230
  * ```tsx
228
231
  * import { useQuery, useQueryClient } from '@tanstack/preact-query'
229
232
  *
@@ -237,6 +240,8 @@ export function useQuery<
237
240
  * queryClient
238
241
  * .getQueryData<Array<Post>>(['posts'])
239
242
  * ?.find((post) => post.id === postId),
243
+ * initialDataUpdatedAt: () =>
244
+ * queryClient.getQueryState(['posts'])?.dataUpdatedAt,
240
245
  * })
241
246
  *
242
247
  * if (isError) return <span>Error: {error.message}</span>
@@ -106,9 +106,13 @@ type GetUseSuspenseQueryResult<T> =
106
106
 
107
107
  /**
108
108
  * The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every
109
- * entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)
110
- * is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a
111
- * single homogeneous {@link UseSuspenseQueryOptions} type.
109
+ * entry's `queryFn`/`select` are inferred individually, up to 20 elements — past that, a tuple falls back to
110
+ * a single homogeneous {@link UseSuspenseQueryOptions} type.
111
+ *
112
+ * An opaque array (e.g. `unknown[]`) is returned as-is; a non-tuple array whose element type structurally
113
+ * matches a query options object is mapped per-element instead, still inferring each entry individually; any
114
+ * other non-tuple array — one whose element type doesn't match the expected options shape — falls back to
115
+ * that same homogeneous options type too.
112
116
  *
113
117
  * @template T - The type of the `queries` array as written at the call site.
114
118
  * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
@@ -1,25 +0,0 @@
1
- // @ts-check
2
-
3
- import rootConfig from './root.eslint.config.js'
4
-
5
- export default [
6
- ...rootConfig,
7
- {
8
- rules: {
9
- 'cspell/spellchecker': 'off',
10
- '@typescript-eslint/no-unnecessary-condition': 'off',
11
- 'import/no-duplicates': 'off',
12
- 'import/no-unresolved': 'off',
13
- 'import/order': 'off',
14
- 'no-shadow': 'off',
15
- 'sort-imports': 'off',
16
- },
17
- },
18
- {
19
- files: ['src/**/__testfixtures__/**'],
20
- rules: {
21
- // Codemod fixtures intentionally preserve historical QueryClient syntax.
22
- 'no-restricted-syntax': 'off',
23
- },
24
- },
25
- ]
@@ -1,38 +0,0 @@
1
- {
2
- "name": "@tanstack/query-codemods",
3
- "private": true,
4
- "description": "Collection of codemods to make the migration easier.",
5
- "author": "Balázs Máté Petró",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/TanStack/query.git",
10
- "directory": "packages/query-codemods"
11
- },
12
- "homepage": "https://tanstack.com/query",
13
- "funding": {
14
- "type": "github",
15
- "url": "https://github.com/sponsors/tannerlinsley"
16
- },
17
- "scripts": {
18
- "clean": "premove ./coverage ./dist-ts",
19
- "test:eslint": "eslint --concurrency=auto ./src",
20
- "test:lib": "vitest",
21
- "test:lib:dev": "pnpm run test:lib --watch"
22
- },
23
- "type": "module",
24
- "exports": {
25
- "./package.json": "./package.json"
26
- },
27
- "sideEffects": false,
28
- "files": [
29
- "src",
30
- "!src/jest.config.js",
31
- "!src/**/__testfixtures__",
32
- "!src/**/__tests__"
33
- ],
34
- "devDependencies": {
35
- "@types/jscodeshift": "17.3.0",
36
- "jscodeshift": "17.3.0"
37
- }
38
- }
@@ -1,113 +0,0 @@
1
- // @ts-check
2
-
3
- // @ts-ignore Needed due to moduleResolution Node vs Bundler
4
- import { tanstackConfig } from '@tanstack/eslint-config'
5
- import pluginCspell from '@cspell/eslint-plugin'
6
- import vitest from '@vitest/eslint-plugin'
7
-
8
- export default [
9
- ...tanstackConfig,
10
- {
11
- name: 'tanstack/temp',
12
- plugins: {
13
- cspell: pluginCspell,
14
- },
15
- rules: {
16
- 'cspell/spellchecker': [
17
- 'warn',
18
- {
19
- cspell: {
20
- words: [
21
- 'Promisable', // Our public interface
22
- 'TSES', // @typescript-eslint package's interface
23
- 'codemod', // We support our codemod
24
- 'combinate', // Library name
25
- 'datatag', // Query options tagging
26
- 'extralight', // Our public interface
27
- 'jscodeshift',
28
- 'refetches', // Query refetch operations
29
- 'retryer', // Our public interface
30
- 'solidjs', // Our target framework
31
- 'tabular-nums', // https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric
32
- 'tanstack', // Our package scope
33
- 'todos', // Too general word to be caught as error
34
- 'tsqd', // Our public interface (TanStack Query Devtools shorthand)
35
- 'tsdown', // We use tsdown as builder
36
- 'typecheck', // Field of vite.config.ts
37
- 'vue-demi', // dependency of @tanstack/vue-query
38
- 'ɵkind', // Angular specific
39
- 'ɵproviders', // Angular specific
40
- ],
41
- },
42
- },
43
- ],
44
- '@typescript-eslint/no-empty-function': 'off',
45
- '@typescript-eslint/no-unsafe-function-type': 'off',
46
- 'no-case-declarations': 'off',
47
- /**
48
- * Disallows direct calls to deprecated imperative query methods of `QueryClient`
49
- * for new tests and code
50
- *
51
- * Existing tests that directly test the methods from before the refactoring
52
- * will be grandfathered in and allowed to continue using the deprecated methods.
53
- * They should not be removed, but new tests should use the new methods instead.
54
- */
55
- 'no-restricted-syntax': [
56
- 'error',
57
- {
58
- selector:
59
- 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchQuery"], [callee.computed=true][callee.property.value="fetchQuery"])',
60
- message: 'Use queryClient.query(options) instead.',
61
- },
62
- {
63
- selector:
64
- 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchQuery"], [callee.computed=true][callee.property.value="prefetchQuery"])',
65
- message:
66
- 'Use queryClient.query(options).catch(noop) instead if errors should be swallowed.',
67
- },
68
- {
69
- selector:
70
- 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureQueryData"], [callee.computed=true][callee.property.value="ensureQueryData"])',
71
- message:
72
- "Use queryClient.query({ ...options, staleTime: 'static' }) instead.",
73
- },
74
- {
75
- selector:
76
- 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchInfiniteQuery"], [callee.computed=true][callee.property.value="fetchInfiniteQuery"])',
77
- message: 'Use queryClient.infiniteQuery(options) instead.',
78
- },
79
- {
80
- selector:
81
- 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchInfiniteQuery"], [callee.computed=true][callee.property.value="prefetchInfiniteQuery"])',
82
- message:
83
- 'Use queryClient.infiniteQuery(options).catch(noop) instead if errors should be swallowed.',
84
- },
85
- {
86
- selector:
87
- 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureInfiniteQueryData"], [callee.computed=true][callee.property.value="ensureInfiniteQueryData"])',
88
- message:
89
- "Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead.",
90
- },
91
- ],
92
- 'prefer-const': 'off',
93
- },
94
- },
95
- {
96
- files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
97
- plugins: { vitest },
98
- rules: {
99
- ...vitest.configs.recommended.rules,
100
- 'vitest/consistent-test-it': [
101
- 'error',
102
- { fn: 'it', withinDescribe: 'it' },
103
- ],
104
- 'vitest/no-standalone-expect': [
105
- 'error',
106
- {
107
- additionalTestBlockFunctions: ['itIf'],
108
- },
109
- ],
110
- },
111
- settings: { vitest: { typecheck: true } },
112
- },
113
- ]
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist-ts",
5
- "rootDir": "."
6
- },
7
- "include": ["src", "*.config.ts", "*.config.js", "package.json"]
8
- }
@@ -1,30 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- import packageJson from './package.json'
4
-
5
- export default defineConfig({
6
- // fix from https://github.com/vitest-dev/vitest/issues/6992#issuecomment-2509408660
7
- resolve: {
8
- conditions: ['@tanstack/custom-condition'],
9
- },
10
- environments: {
11
- ssr: {
12
- resolve: {
13
- conditions: ['@tanstack/custom-condition'],
14
- },
15
- },
16
- },
17
- test: {
18
- name: packageJson.name,
19
- dir: './src',
20
- watch: false,
21
- globals: true,
22
- coverage: {
23
- enabled: !!process.env.CI,
24
- provider: 'istanbul',
25
- include: ['src/**/*.{js,ts,cjs,mjs,jsx,tsx}'],
26
- },
27
- typecheck: { enabled: true },
28
- restoreMocks: true,
29
- },
30
- })
File without changes