{"version":3,"file":"useSuspenseInfiniteQuery.cjs","names":["skipToken","useBaseQuery","defaultThrowOnError","InfiniteQueryObserver"],"sources":["../../src/useSuspenseInfiniteQuery.ts"],"sourcesContent":["'use client'\nimport { InfiniteQueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type {\n  DefaultError,\n  InfiniteData,\n  InfiniteQueryObserverSuccessResult,\n  QueryClient,\n  QueryKey,\n  QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n  UseSuspenseInfiniteQueryOptions,\n  UseSuspenseInfiniteQueryResult,\n} from './types'\n\n/**\n * The options for `useSuspenseInfiniteQuery` are the same as for `useInfiniteQuery`, except for `throwOnError`,\n * `enabled`, and `placeholderData`.\n *\n * Caveat: cancellation does not work.\n *\n * @remarks Multiple suspenseful query calls in the same component suspend serially, causing a request\n * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until\n * then. There's no way to parallelize multiple infinite queries under Suspense. Also keep in mind that\n * imperative fetch calls, such as `fetchNextPage`, may interfere with the default refetch behavior,\n * resulting in outdated data. Make sure to call these functions only in response to user actions, or add\n * conditions like `hasNextPage && !isFetching`.\n * @see {@link useInfiniteQuery} for the non-Suspense version of this hook.\n * @param options - The {@link UseSuspenseInfiniteQueryOptions} to use — the same options as `useInfiniteQuery`, minus the ones listed above.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same object as `useInfiniteQuery`, except that `data` is guaranteed to be defined,\n * `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived flags set\n * accordingly).\n *\n * @example\n * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is\n * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.\n * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import {\n *   QueryErrorResetBoundary,\n *   useSuspenseInfiniteQuery,\n * } from '@tanstack/react-query'\n *\n * function Projects() {\n *   // `data` is guaranteed to be defined here — no `isPending` check needed.\n *   const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n *     useSuspenseInfiniteQuery({\n *       queryKey: ['projects'],\n *       queryFn: ({ pageParam }) => fetchProjects(pageParam),\n *       initialPageParam: 0,\n *       getNextPageParam: (lastPage) => lastPage.nextId,\n *     })\n *\n *   return (\n *     <div>\n *       <ul>\n *         {data.pages.map((page) =>\n *           page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n *         )}\n *       </ul>\n *       <button\n *         onClick={() => fetchNextPage()}\n *         disabled={!hasNextPage || isFetching}\n *       >\n *         {isFetchingNextPage\n *           ? 'Loading more...'\n *           : hasNextPage\n *             ? 'Load More'\n *             : 'Nothing more to load'}\n *       </button>\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 projects...</h1>}>\n *             <Projects />\n *           </Suspense>\n *         </ErrorBoundary>\n *       )}\n *     </QueryErrorResetBoundary>\n *   )\n * }\n * ```\n */\nexport function useSuspenseInfiniteQuery<\n  TQueryFnData,\n  TError = DefaultError,\n  TData = InfiniteData<TQueryFnData>,\n  TQueryKey extends QueryKey = QueryKey,\n  TPageParam = unknown,\n>(\n  options: UseSuspenseInfiniteQueryOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryKey,\n    TPageParam\n  >,\n  queryClient?: QueryClient,\n): UseSuspenseInfiniteQueryResult<TData, TError> {\n  if (process.env.NODE_ENV !== 'production') {\n    if ((options.queryFn as any) === skipToken) {\n      console.error('skipToken is not allowed for useSuspenseInfiniteQuery')\n    }\n  }\n\n  return useBaseQuery(\n    {\n      ...options,\n      enabled: true,\n      suspense: true,\n      throwOnError: defaultThrowOnError,\n      placeholderData: undefined,\n    },\n    InfiniteQueryObserver as typeof QueryObserver,\n    queryClient,\n  ) as InfiniteQueryObserverSuccessResult<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,SAAgB,yBAOd,SAOA,aAC+C;CAC/C,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoBA,qBAAAA,WAC/B,QAAQ,MAAM,uDAAuD;CAAA;CAIzE,OAAOC,qBAAAA,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAcC,iBAAAA;EACd,iBAAiB,KAAA;CACnB,GACAC,qBAAAA,uBACA,WACF;AACF"}