{"version":3,"file":"suspense.cjs","names":[],"sources":["../../src/suspense.ts"],"sourcesContent":["import type {\n  DefaultError,\n  DefaultedQueryObserverOptions,\n  Query,\n  QueryKey,\n  QueryObserver,\n  QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\n\nexport const defaultThrowOnError = <\n  TQueryFnData = unknown,\n  TError = DefaultError,\n  TData = TQueryFnData,\n  TQueryKey extends QueryKey = QueryKey,\n>(\n  _error: TError,\n  query: Query<TQueryFnData, TError, TData, TQueryKey>,\n) => query.state.data === undefined\n\nexport const ensureSuspenseTimers = (\n  defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>,\n) => {\n  if (defaultedOptions.suspense) {\n    // Handle staleTime to ensure minimum 1000ms in Suspense mode\n    // This prevents unnecessary refetching when components remount after suspending\n    const MIN_SUSPENSE_TIME_MS = 1000\n\n    const clamp = (value: number | 'static' | undefined) =>\n      value === 'static'\n        ? value\n        : Math.max(value ?? MIN_SUSPENSE_TIME_MS, MIN_SUSPENSE_TIME_MS)\n\n    const originalStaleTime = defaultedOptions.staleTime\n    defaultedOptions.staleTime =\n      typeof originalStaleTime === 'function'\n        ? (...args) => clamp(originalStaleTime(...args))\n        : clamp(originalStaleTime)\n\n    if (typeof defaultedOptions.gcTime === 'number') {\n      defaultedOptions.gcTime = Math.max(\n        defaultedOptions.gcTime,\n        MIN_SUSPENSE_TIME_MS,\n      )\n    }\n  }\n}\n\nexport const shouldSuspend = (\n  defaultedOptions:\n    | DefaultedQueryObserverOptions<any, any, any, any, any>\n    | undefined,\n  result: QueryObserverResult<any, any>,\n) => defaultedOptions?.suspense && result.isPending\n\nexport const fetchOptimistic = <\n  TQueryFnData,\n  TError,\n  TData,\n  TQueryData,\n  TQueryKey extends QueryKey,\n>(\n  defaultedOptions: DefaultedQueryObserverOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryData,\n    TQueryKey\n  >,\n  observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n  errorResetBoundary: QueryErrorResetBoundaryValue,\n) =>\n  observer.fetchOptimistic(defaultedOptions).catch(() => {\n    errorResetBoundary.clearReset()\n  })\n"],"mappings":";;AAUA,MAAa,uBAMX,QACA,UACG,MAAM,MAAM,SAAS,KAAA;AAE1B,MAAa,wBACX,qBACG;CACH,IAAI,iBAAiB,UAAU;EAG7B,MAAM,uBAAuB;EAE7B,MAAM,SAAS,UACb,UAAU,WACN,QACA,KAAK,IAAI,SAAS,sBAAsB,oBAAoB;EAElE,MAAM,oBAAoB,iBAAiB;EAC3C,iBAAiB,YACf,OAAO,sBAAsB,cACxB,GAAG,SAAS,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAC7C,MAAM,iBAAiB;EAE7B,IAAI,OAAO,iBAAiB,WAAW,UACrC,iBAAiB,SAAS,KAAK,IAC7B,iBAAiB,QACjB,oBACF;CAEJ;AACF;AAEA,MAAa,iBACX,kBAGA,WACG,kBAAkB,YAAY,OAAO;AAE1C,MAAa,mBAOX,kBAOA,UACA,uBAEA,SAAS,gBAAgB,gBAAgB,CAAC,CAAC,YAAY;CACrD,mBAAmB,WAAW;AAChC,CAAC"}