@tanstack/react-query 5.104.1 → 5.104.2

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 (347) hide show
  1. package/build/legacy/HydrationBoundary.cjs +2 -3
  2. package/build/legacy/HydrationBoundary.cjs.map +1 -1
  3. package/build/legacy/HydrationBoundary.d.cts +2 -3
  4. package/build/legacy/HydrationBoundary.d.cts.map +1 -1
  5. package/build/legacy/HydrationBoundary.d.ts +2 -3
  6. package/build/legacy/HydrationBoundary.d.ts.map +1 -1
  7. package/build/legacy/HydrationBoundary.js +2 -3
  8. package/build/legacy/HydrationBoundary.js.map +1 -1
  9. package/build/legacy/IsRestoringProvider.cjs +0 -1
  10. package/build/legacy/IsRestoringProvider.cjs.map +1 -1
  11. package/build/legacy/IsRestoringProvider.d.cts +0 -1
  12. package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
  13. package/build/legacy/IsRestoringProvider.d.ts +0 -1
  14. package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
  15. package/build/legacy/IsRestoringProvider.js +0 -1
  16. package/build/legacy/IsRestoringProvider.js.map +1 -1
  17. package/build/legacy/QueryClientProvider.cjs +3 -4
  18. package/build/legacy/QueryClientProvider.cjs.map +1 -1
  19. package/build/legacy/QueryClientProvider.d.cts +3 -4
  20. package/build/legacy/QueryClientProvider.d.cts.map +1 -1
  21. package/build/legacy/QueryClientProvider.d.ts +3 -4
  22. package/build/legacy/QueryClientProvider.d.ts.map +1 -1
  23. package/build/legacy/QueryClientProvider.js +3 -4
  24. package/build/legacy/QueryClientProvider.js.map +1 -1
  25. package/build/legacy/QueryErrorResetBoundary.cjs +5 -5
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +23 -5
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +23 -5
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +5 -5
  32. package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
  33. package/build/legacy/errorBoundaryUtils.cjs +21 -0
  34. package/build/legacy/errorBoundaryUtils.cjs.map +1 -1
  35. package/build/legacy/errorBoundaryUtils.d.cts +21 -0
  36. package/build/legacy/errorBoundaryUtils.d.cts.map +1 -1
  37. package/build/legacy/errorBoundaryUtils.d.ts +21 -0
  38. package/build/legacy/errorBoundaryUtils.d.ts.map +1 -1
  39. package/build/legacy/errorBoundaryUtils.js +21 -0
  40. package/build/legacy/errorBoundaryUtils.js.map +1 -1
  41. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  42. package/build/legacy/infiniteQueryOptions.d.cts +5 -16
  43. package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
  44. package/build/legacy/infiniteQueryOptions.d.ts +5 -16
  45. package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
  46. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  47. package/build/legacy/mutationOptions.cjs.map +1 -1
  48. package/build/legacy/mutationOptions.d.cts +2 -6
  49. package/build/legacy/mutationOptions.d.cts.map +1 -1
  50. package/build/legacy/mutationOptions.d.ts +2 -6
  51. package/build/legacy/mutationOptions.d.ts.map +1 -1
  52. package/build/legacy/mutationOptions.js.map +1 -1
  53. package/build/legacy/queryOptions.cjs.map +1 -1
  54. package/build/legacy/queryOptions.d.cts +6 -16
  55. package/build/legacy/queryOptions.d.cts.map +1 -1
  56. package/build/legacy/queryOptions.d.ts +6 -16
  57. package/build/legacy/queryOptions.d.ts.map +1 -1
  58. package/build/legacy/queryOptions.js.map +1 -1
  59. package/build/legacy/suspense.cjs +27 -0
  60. package/build/legacy/suspense.cjs.map +1 -1
  61. package/build/legacy/suspense.d.cts +27 -0
  62. package/build/legacy/suspense.d.cts.map +1 -1
  63. package/build/legacy/suspense.d.ts +27 -0
  64. package/build/legacy/suspense.d.ts.map +1 -1
  65. package/build/legacy/suspense.js +27 -0
  66. package/build/legacy/suspense.js.map +1 -1
  67. package/build/legacy/types.cjs.map +1 -1
  68. package/build/legacy/types.d.cts +2 -22
  69. package/build/legacy/types.d.cts.map +1 -1
  70. package/build/legacy/types.d.ts +2 -22
  71. package/build/legacy/types.d.ts.map +1 -1
  72. package/build/legacy/types.js.map +1 -1
  73. package/build/legacy/useBaseQuery.cjs +13 -0
  74. package/build/legacy/useBaseQuery.cjs.map +1 -1
  75. package/build/legacy/useBaseQuery.d.cts +13 -0
  76. package/build/legacy/useBaseQuery.d.cts.map +1 -1
  77. package/build/legacy/useBaseQuery.d.ts +13 -0
  78. package/build/legacy/useBaseQuery.d.ts.map +1 -1
  79. package/build/legacy/useBaseQuery.js +13 -0
  80. package/build/legacy/useBaseQuery.js.map +1 -1
  81. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  82. package/build/legacy/useInfiniteQuery.d.cts +12 -21
  83. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  84. package/build/legacy/useInfiniteQuery.d.ts +12 -21
  85. package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
  86. package/build/legacy/useInfiniteQuery.js.map +1 -1
  87. package/build/legacy/useIsFetching.cjs +0 -3
  88. package/build/legacy/useIsFetching.cjs.map +1 -1
  89. package/build/legacy/useIsFetching.d.cts +0 -3
  90. package/build/legacy/useIsFetching.d.cts.map +1 -1
  91. package/build/legacy/useIsFetching.d.ts +0 -3
  92. package/build/legacy/useIsFetching.d.ts.map +1 -1
  93. package/build/legacy/useIsFetching.js +0 -3
  94. package/build/legacy/useIsFetching.js.map +1 -1
  95. package/build/legacy/useMutation.cjs +4 -8
  96. package/build/legacy/useMutation.cjs.map +1 -1
  97. package/build/legacy/useMutation.d.cts +4 -8
  98. package/build/legacy/useMutation.d.cts.map +1 -1
  99. package/build/legacy/useMutation.d.ts +4 -8
  100. package/build/legacy/useMutation.d.ts.map +1 -1
  101. package/build/legacy/useMutation.js +4 -8
  102. package/build/legacy/useMutation.js.map +1 -1
  103. package/build/legacy/useMutationState.cjs +7 -6
  104. package/build/legacy/useMutationState.cjs.map +1 -1
  105. package/build/legacy/useMutationState.d.cts +0 -6
  106. package/build/legacy/useMutationState.d.cts.map +1 -1
  107. package/build/legacy/useMutationState.d.ts +0 -6
  108. package/build/legacy/useMutationState.d.ts.map +1 -1
  109. package/build/legacy/useMutationState.js +7 -6
  110. package/build/legacy/useMutationState.js.map +1 -1
  111. package/build/legacy/usePrefetchInfiniteQuery.cjs +0 -3
  112. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
  113. package/build/legacy/usePrefetchInfiniteQuery.d.cts +0 -3
  114. package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
  115. package/build/legacy/usePrefetchInfiniteQuery.d.ts +0 -3
  116. package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
  117. package/build/legacy/usePrefetchInfiniteQuery.js +0 -3
  118. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
  119. package/build/legacy/usePrefetchQuery.cjs +0 -3
  120. package/build/legacy/usePrefetchQuery.cjs.map +1 -1
  121. package/build/legacy/usePrefetchQuery.d.cts +0 -3
  122. package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
  123. package/build/legacy/usePrefetchQuery.d.ts +0 -3
  124. package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
  125. package/build/legacy/usePrefetchQuery.js +0 -3
  126. package/build/legacy/usePrefetchQuery.js.map +1 -1
  127. package/build/legacy/useQueries.cjs +7 -8
  128. package/build/legacy/useQueries.cjs.map +1 -1
  129. package/build/legacy/useQueries.d.cts +7 -11
  130. package/build/legacy/useQueries.d.cts.map +1 -1
  131. package/build/legacy/useQueries.d.ts +7 -11
  132. package/build/legacy/useQueries.d.ts.map +1 -1
  133. package/build/legacy/useQueries.js +7 -8
  134. package/build/legacy/useQueries.js.map +1 -1
  135. package/build/legacy/useQuery.cjs.map +1 -1
  136. package/build/legacy/useQuery.d.cts +8 -13
  137. package/build/legacy/useQuery.d.cts.map +1 -1
  138. package/build/legacy/useQuery.d.ts +8 -13
  139. package/build/legacy/useQuery.d.ts.map +1 -1
  140. package/build/legacy/useQuery.js.map +1 -1
  141. package/build/legacy/useSuspenseInfiniteQuery.cjs +6 -8
  142. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  143. package/build/legacy/useSuspenseInfiniteQuery.d.cts +6 -8
  144. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  145. package/build/legacy/useSuspenseInfiniteQuery.d.ts +6 -8
  146. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  147. package/build/legacy/useSuspenseInfiniteQuery.js +6 -8
  148. package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
  149. package/build/legacy/useSuspenseQueries.cjs.map +1 -1
  150. package/build/legacy/useSuspenseQueries.d.cts +0 -9
  151. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  152. package/build/legacy/useSuspenseQueries.d.ts +0 -9
  153. package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
  154. package/build/legacy/useSuspenseQueries.js.map +1 -1
  155. package/build/legacy/useSuspenseQuery.cjs +4 -6
  156. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  157. package/build/legacy/useSuspenseQuery.d.cts +4 -6
  158. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  159. package/build/legacy/useSuspenseQuery.d.ts +4 -6
  160. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  161. package/build/legacy/useSuspenseQuery.js +4 -6
  162. package/build/legacy/useSuspenseQuery.js.map +1 -1
  163. package/build/modern/HydrationBoundary.cjs +2 -3
  164. package/build/modern/HydrationBoundary.cjs.map +1 -1
  165. package/build/modern/HydrationBoundary.d.cts +2 -3
  166. package/build/modern/HydrationBoundary.d.cts.map +1 -1
  167. package/build/modern/HydrationBoundary.d.ts +2 -3
  168. package/build/modern/HydrationBoundary.d.ts.map +1 -1
  169. package/build/modern/HydrationBoundary.js +2 -3
  170. package/build/modern/HydrationBoundary.js.map +1 -1
  171. package/build/modern/IsRestoringProvider.cjs +0 -1
  172. package/build/modern/IsRestoringProvider.cjs.map +1 -1
  173. package/build/modern/IsRestoringProvider.d.cts +0 -1
  174. package/build/modern/IsRestoringProvider.d.cts.map +1 -1
  175. package/build/modern/IsRestoringProvider.d.ts +0 -1
  176. package/build/modern/IsRestoringProvider.d.ts.map +1 -1
  177. package/build/modern/IsRestoringProvider.js +0 -1
  178. package/build/modern/IsRestoringProvider.js.map +1 -1
  179. package/build/modern/QueryClientProvider.cjs +3 -4
  180. package/build/modern/QueryClientProvider.cjs.map +1 -1
  181. package/build/modern/QueryClientProvider.d.cts +3 -4
  182. package/build/modern/QueryClientProvider.d.cts.map +1 -1
  183. package/build/modern/QueryClientProvider.d.ts +3 -4
  184. package/build/modern/QueryClientProvider.d.ts.map +1 -1
  185. package/build/modern/QueryClientProvider.js +3 -4
  186. package/build/modern/QueryClientProvider.js.map +1 -1
  187. package/build/modern/QueryErrorResetBoundary.cjs +5 -5
  188. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  189. package/build/modern/QueryErrorResetBoundary.d.cts +23 -5
  190. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  191. package/build/modern/QueryErrorResetBoundary.d.ts +23 -5
  192. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  193. package/build/modern/QueryErrorResetBoundary.js +5 -5
  194. package/build/modern/QueryErrorResetBoundary.js.map +1 -1
  195. package/build/modern/errorBoundaryUtils.cjs +21 -0
  196. package/build/modern/errorBoundaryUtils.cjs.map +1 -1
  197. package/build/modern/errorBoundaryUtils.d.cts +21 -0
  198. package/build/modern/errorBoundaryUtils.d.cts.map +1 -1
  199. package/build/modern/errorBoundaryUtils.d.ts +21 -0
  200. package/build/modern/errorBoundaryUtils.d.ts.map +1 -1
  201. package/build/modern/errorBoundaryUtils.js +21 -0
  202. package/build/modern/errorBoundaryUtils.js.map +1 -1
  203. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  204. package/build/modern/infiniteQueryOptions.d.cts +5 -16
  205. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  206. package/build/modern/infiniteQueryOptions.d.ts +5 -16
  207. package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
  208. package/build/modern/infiniteQueryOptions.js.map +1 -1
  209. package/build/modern/mutationOptions.cjs.map +1 -1
  210. package/build/modern/mutationOptions.d.cts +2 -6
  211. package/build/modern/mutationOptions.d.cts.map +1 -1
  212. package/build/modern/mutationOptions.d.ts +2 -6
  213. package/build/modern/mutationOptions.d.ts.map +1 -1
  214. package/build/modern/mutationOptions.js.map +1 -1
  215. package/build/modern/queryOptions.cjs.map +1 -1
  216. package/build/modern/queryOptions.d.cts +6 -16
  217. package/build/modern/queryOptions.d.cts.map +1 -1
  218. package/build/modern/queryOptions.d.ts +6 -16
  219. package/build/modern/queryOptions.d.ts.map +1 -1
  220. package/build/modern/queryOptions.js.map +1 -1
  221. package/build/modern/suspense.cjs +27 -0
  222. package/build/modern/suspense.cjs.map +1 -1
  223. package/build/modern/suspense.d.cts +27 -0
  224. package/build/modern/suspense.d.cts.map +1 -1
  225. package/build/modern/suspense.d.ts +27 -0
  226. package/build/modern/suspense.d.ts.map +1 -1
  227. package/build/modern/suspense.js +27 -0
  228. package/build/modern/suspense.js.map +1 -1
  229. package/build/modern/types.cjs.map +1 -1
  230. package/build/modern/types.d.cts +2 -22
  231. package/build/modern/types.d.cts.map +1 -1
  232. package/build/modern/types.d.ts +2 -22
  233. package/build/modern/types.d.ts.map +1 -1
  234. package/build/modern/types.js.map +1 -1
  235. package/build/modern/useBaseQuery.cjs +13 -0
  236. package/build/modern/useBaseQuery.cjs.map +1 -1
  237. package/build/modern/useBaseQuery.d.cts +13 -0
  238. package/build/modern/useBaseQuery.d.cts.map +1 -1
  239. package/build/modern/useBaseQuery.d.ts +13 -0
  240. package/build/modern/useBaseQuery.d.ts.map +1 -1
  241. package/build/modern/useBaseQuery.js +13 -0
  242. package/build/modern/useBaseQuery.js.map +1 -1
  243. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  244. package/build/modern/useInfiniteQuery.d.cts +12 -21
  245. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  246. package/build/modern/useInfiniteQuery.d.ts +12 -21
  247. package/build/modern/useInfiniteQuery.d.ts.map +1 -1
  248. package/build/modern/useInfiniteQuery.js.map +1 -1
  249. package/build/modern/useIsFetching.cjs +0 -3
  250. package/build/modern/useIsFetching.cjs.map +1 -1
  251. package/build/modern/useIsFetching.d.cts +0 -3
  252. package/build/modern/useIsFetching.d.cts.map +1 -1
  253. package/build/modern/useIsFetching.d.ts +0 -3
  254. package/build/modern/useIsFetching.d.ts.map +1 -1
  255. package/build/modern/useIsFetching.js +0 -3
  256. package/build/modern/useIsFetching.js.map +1 -1
  257. package/build/modern/useMutation.cjs +4 -8
  258. package/build/modern/useMutation.cjs.map +1 -1
  259. package/build/modern/useMutation.d.cts +4 -8
  260. package/build/modern/useMutation.d.cts.map +1 -1
  261. package/build/modern/useMutation.d.ts +4 -8
  262. package/build/modern/useMutation.d.ts.map +1 -1
  263. package/build/modern/useMutation.js +4 -8
  264. package/build/modern/useMutation.js.map +1 -1
  265. package/build/modern/useMutationState.cjs +7 -6
  266. package/build/modern/useMutationState.cjs.map +1 -1
  267. package/build/modern/useMutationState.d.cts +0 -6
  268. package/build/modern/useMutationState.d.cts.map +1 -1
  269. package/build/modern/useMutationState.d.ts +0 -6
  270. package/build/modern/useMutationState.d.ts.map +1 -1
  271. package/build/modern/useMutationState.js +7 -6
  272. package/build/modern/useMutationState.js.map +1 -1
  273. package/build/modern/usePrefetchInfiniteQuery.cjs +0 -3
  274. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  275. package/build/modern/usePrefetchInfiniteQuery.d.cts +0 -3
  276. package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
  277. package/build/modern/usePrefetchInfiniteQuery.d.ts +0 -3
  278. package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
  279. package/build/modern/usePrefetchInfiniteQuery.js +0 -3
  280. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  281. package/build/modern/usePrefetchQuery.cjs +0 -3
  282. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  283. package/build/modern/usePrefetchQuery.d.cts +0 -3
  284. package/build/modern/usePrefetchQuery.d.cts.map +1 -1
  285. package/build/modern/usePrefetchQuery.d.ts +0 -3
  286. package/build/modern/usePrefetchQuery.d.ts.map +1 -1
  287. package/build/modern/usePrefetchQuery.js +0 -3
  288. package/build/modern/usePrefetchQuery.js.map +1 -1
  289. package/build/modern/useQueries.cjs +7 -8
  290. package/build/modern/useQueries.cjs.map +1 -1
  291. package/build/modern/useQueries.d.cts +7 -11
  292. package/build/modern/useQueries.d.cts.map +1 -1
  293. package/build/modern/useQueries.d.ts +7 -11
  294. package/build/modern/useQueries.d.ts.map +1 -1
  295. package/build/modern/useQueries.js +7 -8
  296. package/build/modern/useQueries.js.map +1 -1
  297. package/build/modern/useQuery.cjs.map +1 -1
  298. package/build/modern/useQuery.d.cts +8 -13
  299. package/build/modern/useQuery.d.cts.map +1 -1
  300. package/build/modern/useQuery.d.ts +8 -13
  301. package/build/modern/useQuery.d.ts.map +1 -1
  302. package/build/modern/useQuery.js.map +1 -1
  303. package/build/modern/useSuspenseInfiniteQuery.cjs +6 -8
  304. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  305. package/build/modern/useSuspenseInfiniteQuery.d.cts +6 -8
  306. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  307. package/build/modern/useSuspenseInfiniteQuery.d.ts +6 -8
  308. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  309. package/build/modern/useSuspenseInfiniteQuery.js +6 -8
  310. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
  311. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  312. package/build/modern/useSuspenseQueries.d.cts +0 -9
  313. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  314. package/build/modern/useSuspenseQueries.d.ts +0 -9
  315. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  316. package/build/modern/useSuspenseQueries.js.map +1 -1
  317. package/build/modern/useSuspenseQuery.cjs +4 -6
  318. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  319. package/build/modern/useSuspenseQuery.d.cts +4 -6
  320. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  321. package/build/modern/useSuspenseQuery.d.ts +4 -6
  322. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  323. package/build/modern/useSuspenseQuery.js +4 -6
  324. package/build/modern/useSuspenseQuery.js.map +1 -1
  325. package/package.json +6 -6
  326. package/src/HydrationBoundary.tsx +4 -5
  327. package/src/IsRestoringProvider.ts +0 -1
  328. package/src/QueryClientProvider.tsx +3 -4
  329. package/src/QueryErrorResetBoundary.tsx +30 -6
  330. package/src/errorBoundaryUtils.ts +21 -0
  331. package/src/infiniteQueryOptions.ts +5 -16
  332. package/src/mutationOptions.ts +2 -6
  333. package/src/queryOptions.ts +8 -17
  334. package/src/suspense.ts +29 -1
  335. package/src/types.ts +2 -22
  336. package/src/useBaseQuery.ts +13 -0
  337. package/src/useInfiniteQuery.ts +12 -21
  338. package/src/useIsFetching.ts +0 -3
  339. package/src/useMutation.ts +4 -8
  340. package/src/useMutationState.ts +7 -6
  341. package/src/usePrefetchInfiniteQuery.tsx +0 -3
  342. package/src/usePrefetchQuery.tsx +0 -3
  343. package/src/useQueries.ts +7 -11
  344. package/src/useQuery.ts +8 -13
  345. package/src/useSuspenseInfiniteQuery.ts +6 -8
  346. package/src/useSuspenseQueries.ts +0 -9
  347. package/src/useSuspenseQuery.ts +4 -6
@@ -5,12 +5,10 @@ import { DefaultError, WithRequired } from "@tanstack/query-core";
5
5
  * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
6
6
  * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
7
7
  * `useMutationState`.
8
- *
9
- * @see {@link useMutation} to run the mutation these options describe.
10
8
  * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
11
9
  * required `mutationKey`.
12
10
  * @returns The same options object, unchanged.
13
- *
11
+ * @see {@link useMutation} to run the mutation these options describe.
14
12
  * @example
15
13
  * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
16
14
  * ```tsx
@@ -36,13 +34,11 @@ export declare function mutationOptions<TData = unknown, TError = DefaultError,
36
34
  * `mutationKey` is required on this overload — use this when you don't need to target the mutation via a
37
35
  * `mutationKey` filter later (e.g. with `useMutationState`); it can still be observed through other filters,
38
36
  * such as `status`.
39
- *
40
- * @see {@link useMutation} to run the mutation these options describe.
41
37
  * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
42
38
  * `mutationKey`.
43
39
  * @returns The same options object, unchanged.
44
40
  * @remarks See the other overload's example for looking a mutation up via `useMutationState`.
45
- *
41
+ * @see {@link useMutation} to run the mutation these options describe.
46
42
  * @example
47
43
  * ```tsx
48
44
  * import { mutationOptions, useMutation } from '@tanstack/react-query'
@@ -1 +1 @@
1
- {"version":3,"file":"mutationOptions.d.ts","names":[],"sources":["../../src/mutationOptions.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgCgB,gBACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,aACP,mBAAmB,OAAO,QAAQ,YAAY,mCAG/C,aACD,mBAAmB,OAAO,QAAQ,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA6BhC,gBACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,KACP,mBAAmB,OAAO,QAAQ,YAAY,mCAG/C,KACD,mBAAmB,OAAO,QAAQ,YAAY"}
1
+ {"version":3,"file":"mutationOptions.d.ts","names":[],"sources":["../../src/mutationOptions.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8BgB,gBACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,aACP,mBAAmB,OAAO,QAAQ,YAAY,mCAG/C,aACD,mBAAmB,OAAO,QAAQ,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;wBA2BhC,gBACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,KACP,mBAAmB,OAAO,QAAQ,YAAY,mCAG/C,KACD,mBAAmB,OAAO,QAAQ,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"mutationOptions.js","names":[],"sources":["../../src/mutationOptions.ts"],"sourcesContent":["import type { DefaultError, WithRequired } from '@tanstack/query-core'\nimport type { UseMutationOptions } from './types'\n\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A\n * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with\n * `useMutationState`.\n *\n * @see {@link useMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a\n * required `mutationKey`.\n * @returns The same options object, unchanged.\n *\n * @example\n * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global \"saving…\" indicator:\n * ```tsx\n * import { mutationOptions, useMutationState } from '@tanstack/react-query'\n *\n * const createPostOptions = mutationOptions({\n * mutationKey: ['posts', 'create'],\n * mutationFn: createPost,\n * })\n *\n * function SavingIndicator() {\n * const isCreatingPost = useMutationState({\n * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },\n * }).length > 0\n *\n * return isCreatingPost ? <span>Saving…</span> : null\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: WithRequired<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): WithRequired<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. No\n * `mutationKey` is required on this overload — use this when you don't need to target the mutation via a\n * `mutationKey` filter later (e.g. with `useMutationState`); it can still be observed through other filters,\n * such as `status`.\n *\n * @see {@link useMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a\n * `mutationKey`.\n * @returns The same options object, unchanged.\n * @remarks See the other overload's example for looking a mutation up via `useMutationState`.\n *\n * @example\n * ```tsx\n * import { mutationOptions, useMutation } from '@tanstack/react-query'\n *\n * export const createPostOptions = mutationOptions({\n * mutationFn: createPost,\n * })\n *\n * function CreatePost() {\n * const mutation = useMutation(createPostOptions)\n * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: Omit<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): Omit<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n): UseMutationOptions<TData, TError, TVariables, TOnMutateResult> {\n return options\n}\n"],"mappings":";AAsFA,SAAgB,gBAMd,SACgE;CAChE,OAAO;AACT"}
1
+ {"version":3,"file":"mutationOptions.js","names":[],"sources":["../../src/mutationOptions.ts"],"sourcesContent":["import type { DefaultError, WithRequired } from '@tanstack/query-core'\nimport type { UseMutationOptions } from './types'\n\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A\n * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with\n * `useMutationState`.\n * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a\n * required `mutationKey`.\n * @returns The same options object, unchanged.\n * @see {@link useMutation} to run the mutation these options describe.\n * @example\n * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global \"saving…\" indicator:\n * ```tsx\n * import { mutationOptions, useMutationState } from '@tanstack/react-query'\n *\n * const createPostOptions = mutationOptions({\n * mutationKey: ['posts', 'create'],\n * mutationFn: createPost,\n * })\n *\n * function SavingIndicator() {\n * const isCreatingPost = useMutationState({\n * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },\n * }).length > 0\n *\n * return isCreatingPost ? <span>Saving…</span> : null\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: WithRequired<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): WithRequired<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. No\n * `mutationKey` is required on this overload — use this when you don't need to target the mutation via a\n * `mutationKey` filter later (e.g. with `useMutationState`); it can still be observed through other filters,\n * such as `status`.\n * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a\n * `mutationKey`.\n * @returns The same options object, unchanged.\n * @remarks See the other overload's example for looking a mutation up via `useMutationState`.\n * @see {@link useMutation} to run the mutation these options describe.\n * @example\n * ```tsx\n * import { mutationOptions, useMutation } from '@tanstack/react-query'\n *\n * export const createPostOptions = mutationOptions({\n * mutationFn: createPost,\n * })\n *\n * function CreatePost() {\n * const mutation = useMutation(createPostOptions)\n * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: Omit<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): Omit<\n UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n): UseMutationOptions<TData, TError, TVariables, TOnMutateResult> {\n return options\n}\n"],"mappings":";AAkFA,SAAgB,gBAMd,SACgE;CAChE,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"queryOptions.cjs","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { UseQueryOptions } from './types'\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is\n * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)\n /**\n * Optional here, but omitting it is only safe when no fetch will be attempted — for example with\n * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no\n * `queryFn` still tries to fetch and fails with a \"Missing queryFn\" error; `initialData` does not prevent this.\n */\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * function Posts() {\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery(postsOptions)\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data, isPending, isError, error } = useQuery(postOptions(id))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data.title}</h1>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data, isPending, isError, error } = useQuery(postOptions(id))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data.title}</h1>\n * }\n * ```\n *\n * @example\n * A factory that disables the query, type safe, until `postId` is set:\n * ```tsx\n * import { queryOptions, skipToken, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (postId: number | undefined) =>\n * queryOptions({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery(postOptions(postId))\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";;AAgQA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
1
+ {"version":3,"file":"queryOptions.cjs","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { UseQueryOptions } from './types'\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is\n * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n /**\n * Optional here, but omitting it is only safe when no fetch will be attempted — for example with\n * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no\n * `queryFn` still tries to fetch and fails with a \"Missing queryFn\" error; `initialData` does not prevent this.\n */\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @example\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * function Posts() {\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery(postsOptions)\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data, isPending, isError, error } = useQuery(postOptions(id))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data.title}</h1>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data, isPending, isError, error } = useQuery(postOptions(id))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data.title}</h1>\n * }\n * ```\n * @example\n * A factory that disables the query, type safe, until `postId` is set:\n * ```tsx\n * import { queryOptions, skipToken, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (postId: number | undefined) =>\n * queryOptions({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery(postOptions(postId))\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";;AAuPA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
@@ -4,7 +4,6 @@ import { DefaultError, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryF
4
4
  /**
5
5
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
6
6
  * `undefined` while the query is `pending`.
7
- *
8
7
  * @template TQueryFnData - The type your `queryFn` resolves to.
9
8
  * @template TError - The type of errors your `queryFn` may throw.
10
9
  * @template TData - The type `data` ends up as after `select` runs.
@@ -23,7 +22,6 @@ export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = Default
23
22
  /**
24
23
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
25
24
  * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
26
- *
27
25
  * @template TQueryFnData - The type your `queryFn` resolves to.
28
26
  * @template TError - The type of errors your `queryFn` may throw.
29
27
  * @template TData - The type `data` ends up as after `select` runs.
@@ -41,7 +39,6 @@ export type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError
41
39
  /**
42
40
  * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
43
41
  * `undefined` (unless a `select` changes `TData` to include `undefined`).
44
- *
45
42
  * @template TQueryFnData - The type your `queryFn` resolves to.
46
43
  * @template TError - The type of errors your `queryFn` may throw.
47
44
  * @template TData - The type `data` ends up as after `select` runs.
@@ -70,12 +67,10 @@ export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultEr
70
67
  *
71
68
  * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
72
69
  * a `select` changes `TData` to include `undefined`).
73
- *
74
- * @see {@link useQuery} to run a query with these options.
75
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
76
70
  * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
77
71
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
78
- *
72
+ * @see {@link useQuery} to run a query with these options.
73
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
79
74
  * @example
80
75
  * ```tsx
81
76
  * import { queryOptions, useQuery } from '@tanstack/react-query'
@@ -107,12 +102,10 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
107
102
  * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
108
103
  * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
109
104
  * is the query key to generate options for.
110
- *
111
- * @see {@link useQuery} to run a query with these options.
112
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
113
105
  * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
114
106
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
115
- *
107
+ * @see {@link useQuery} to run a query with these options.
108
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
116
109
  * @example
117
110
  * A parameterized factory, so the same options object can be reused per `id`:
118
111
  * ```tsx
@@ -139,13 +132,11 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
139
132
  * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
140
133
  * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
141
134
  * is the query key to generate options for.
142
- *
143
- * @see {@link useQuery} to run a query with these options.
144
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
145
135
  * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
146
136
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
147
137
  * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.
148
- *
138
+ * @see {@link useQuery} to run a query with these options.
139
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
149
140
  * @example
150
141
  * A parameterized factory, so the same options object can be reused per `id`:
151
142
  * ```tsx
@@ -166,7 +157,6 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
166
157
  * return <h1>{data.title}</h1>
167
158
  * }
168
159
  * ```
169
- *
170
160
  * @example
171
161
  * A factory that disables the query, type safe, until `postId` is set:
172
162
  * ```tsx
@@ -1 +1 @@
1
- {"version":3,"file":"queryOptions.d.cts","names":[],"sources":["../../src/queryOptions.ts"],"mappings":";;;;;;;;;;;;YAqBY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQ/C,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;;;;;;;;;;YAYZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;EAS7C,UAAU,QACR,gBAAgB,cAAc,QAAQ,OAAO,uBAC7C;;;;;;;;;;;YAaQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KAAK,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQpD,aACE,kBAAkB,uBAAuB,kBAAkB;;;;;;EAM7D,UAAU,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0CxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiC/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwD/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
1
+ {"version":3,"file":"queryOptions.d.cts","names":[],"sources":["../../src/queryOptions.ts"],"mappings":";;;;;;;;;;;YAoBY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQ/C,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;;;;;;;;;YAWZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;EAS7C,UAAU,QACR,gBAAgB,cAAc,QAAQ,OAAO,uBAC7C;;;;;;;;;;YAYQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KAAK,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQpD,aACI,kBAAkB,uBACX,kBAAkB;;;;;;EAM7B,UAAU,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+B/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqD/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
@@ -4,7 +4,6 @@ import { DefaultError, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryF
4
4
  /**
5
5
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
6
6
  * `undefined` while the query is `pending`.
7
- *
8
7
  * @template TQueryFnData - The type your `queryFn` resolves to.
9
8
  * @template TError - The type of errors your `queryFn` may throw.
10
9
  * @template TData - The type `data` ends up as after `select` runs.
@@ -23,7 +22,6 @@ export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = Default
23
22
  /**
24
23
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
25
24
  * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
26
- *
27
25
  * @template TQueryFnData - The type your `queryFn` resolves to.
28
26
  * @template TError - The type of errors your `queryFn` may throw.
29
27
  * @template TData - The type `data` ends up as after `select` runs.
@@ -41,7 +39,6 @@ export type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError
41
39
  /**
42
40
  * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
43
41
  * `undefined` (unless a `select` changes `TData` to include `undefined`).
44
- *
45
42
  * @template TQueryFnData - The type your `queryFn` resolves to.
46
43
  * @template TError - The type of errors your `queryFn` may throw.
47
44
  * @template TData - The type `data` ends up as after `select` runs.
@@ -70,12 +67,10 @@ export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultEr
70
67
  *
71
68
  * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
72
69
  * a `select` changes `TData` to include `undefined`).
73
- *
74
- * @see {@link useQuery} to run a query with these options.
75
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
76
70
  * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
77
71
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
78
- *
72
+ * @see {@link useQuery} to run a query with these options.
73
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
79
74
  * @example
80
75
  * ```tsx
81
76
  * import { queryOptions, useQuery } from '@tanstack/react-query'
@@ -107,12 +102,10 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
107
102
  * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
108
103
  * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
109
104
  * is the query key to generate options for.
110
- *
111
- * @see {@link useQuery} to run a query with these options.
112
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
113
105
  * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
114
106
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
115
- *
107
+ * @see {@link useQuery} to run a query with these options.
108
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
116
109
  * @example
117
110
  * A parameterized factory, so the same options object can be reused per `id`:
118
111
  * ```tsx
@@ -139,13 +132,11 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
139
132
  * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
140
133
  * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
141
134
  * is the query key to generate options for.
142
- *
143
- * @see {@link useQuery} to run a query with these options.
144
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
145
135
  * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
146
136
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
147
137
  * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.
148
- *
138
+ * @see {@link useQuery} to run a query with these options.
139
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
149
140
  * @example
150
141
  * A parameterized factory, so the same options object can be reused per `id`:
151
142
  * ```tsx
@@ -166,7 +157,6 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
166
157
  * return <h1>{data.title}</h1>
167
158
  * }
168
159
  * ```
169
- *
170
160
  * @example
171
161
  * A factory that disables the query, type safe, until `postId` is set:
172
162
  * ```tsx
@@ -1 +1 @@
1
- {"version":3,"file":"queryOptions.d.ts","names":[],"sources":["../../src/queryOptions.ts"],"mappings":";;;;;;;;;;;;YAqBY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQ/C,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;;;;;;;;;;YAYZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;EAS7C,UAAU,QACR,gBAAgB,cAAc,QAAQ,OAAO,uBAC7C;;;;;;;;;;;YAaQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KAAK,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQpD,aACE,kBAAkB,uBAAuB,kBAAkB;;;;;;EAM7D,UAAU,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0CxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiC/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwD/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
1
+ {"version":3,"file":"queryOptions.d.ts","names":[],"sources":["../../src/queryOptions.ts"],"mappings":";;;;;;;;;;;YAoBY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQ/C,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;;;;;;;;;YAWZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;EAS7C,UAAU,QACR,gBAAgB,cAAc,QAAQ,OAAO,uBAC7C;;;;;;;;;;YAYQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KAAK,gBAAgB,cAAc,QAAQ,OAAO;;;;;;;;EAQpD,aACI,kBAAkB,uBACX,kBAAkB;;;;;;EAM7B,UAAU,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+B/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqD/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"queryOptions.js","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { UseQueryOptions } from './types'\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is\n * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)\n /**\n * Optional here, but omitting it is only safe when no fetch will be attempted — for example with\n * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no\n * `queryFn` still tries to fetch and fails with a \"Missing queryFn\" error; `initialData` does not prevent this.\n */\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * function Posts() {\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery(postsOptions)\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data, isPending, isError, error } = useQuery(postOptions(id))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data.title}</h1>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data, isPending, isError, error } = useQuery(postOptions(id))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data.title}</h1>\n * }\n * ```\n *\n * @example\n * A factory that disables the query, type safe, until `postId` is set:\n * ```tsx\n * import { queryOptions, skipToken, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (postId: number | undefined) =>\n * queryOptions({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery(postOptions(postId))\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AAgQA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
1
+ {"version":3,"file":"queryOptions.js","names":[],"sources":["../../src/queryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { UseQueryOptions } from './types'\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is\n * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n /**\n * Optional here, but omitting it is only safe when no fetch will be attempted — for example with\n * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no\n * `queryFn` still tries to fetch and fails with a \"Missing queryFn\" error; `initialData` does not prevent this.\n */\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @example\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * function Posts() {\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery(postsOptions)\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data, isPending, isError, error } = useQuery(postOptions(id))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data.title}</h1>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can\n * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and\n * is the query key to generate options for.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.\n * @see {@link useQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```tsx\n * import { queryOptions, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * function Post({ id }: { id: string }) {\n * const { data, isPending, isError, error } = useQuery(postOptions(id))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data.title}</h1>\n * }\n * ```\n * @example\n * A factory that disables the query, type safe, until `postId` is set:\n * ```tsx\n * import { queryOptions, skipToken, useQuery } from '@tanstack/react-query'\n *\n * export const postOptions = (postId: number | undefined) =>\n * queryOptions({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery(postOptions(postId))\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AAuPA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
@@ -1,6 +1,19 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/suspense.ts
3
+ /**
4
+ * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
5
+ * only if the query has no data to show.
6
+ * @param _error - The error of the query. Unused.
7
+ * @param query - The query that errored.
8
+ * @returns `true` if the query has no data.
9
+ */
3
10
  const defaultThrowOnError = (_error, query) => query.state.data === void 0;
11
+ /**
12
+ * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
13
+ * component that remounts after suspending doesn't refetch right away or find the query garbage
14
+ * collected. A `'static'` `staleTime` is kept as is. Mutates the options.
15
+ * @param defaultedOptions - The defaulted query options to adjust.
16
+ */
4
17
  const ensureSuspenseTimers = (defaultedOptions) => {
5
18
  if (defaultedOptions.suspense) {
6
19
  const MIN_SUSPENSE_TIME_MS = 1e3;
@@ -10,7 +23,21 @@ const ensureSuspenseTimers = (defaultedOptions) => {
10
23
  if (typeof defaultedOptions.gcTime === "number") defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, MIN_SUSPENSE_TIME_MS);
11
24
  }
12
25
  };
26
+ /**
27
+ * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
28
+ * @param defaultedOptions - The defaulted query options, if any.
29
+ * @param result - The current result of the observer.
30
+ * @returns `true` if the component should suspend.
31
+ */
13
32
  const shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
33
+ /**
34
+ * Fetches the query for a suspending component, without affecting the observer's own result. If
35
+ * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
36
+ * @param defaultedOptions - The defaulted query options to fetch with.
37
+ * @param observer - The observer of the query.
38
+ * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
39
+ * @returns A promise that resolves once the fetch settles. It never rejects.
40
+ */
14
41
  const fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
15
42
  errorResetBoundary.clearReset();
16
43
  });
@@ -1 +1 @@
1
- {"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> | 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,kBAEA,WACG,kBAAkB,YAAY,OAAO;AAE1C,MAAa,mBAOX,kBAOA,UACA,uBAEA,SAAS,gBAAgB,gBAAgB,CAAC,CAAC,YAAY;CACrD,mBAAmB,WAAW;AAChC,CAAC"}
1
+ {"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\n/**\n * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary\n * only if the query has no data to show.\n * @param _error - The error of the query. Unused.\n * @param query - The query that errored.\n * @returns `true` if the query has no data.\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\n/**\n * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a\n * component that remounts after suspending doesn't refetch right away or find the query garbage\n * collected. A `'static'` `staleTime` is kept as is. Mutates the options.\n * @param defaultedOptions - The defaulted query options to adjust.\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\n/**\n * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.\n * @param defaultedOptions - The defaulted query options, if any.\n * @param result - The current result of the observer.\n * @returns `true` if the component should suspend.\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\n/**\n * Fetches the query for a suspending component, without affecting the observer's own result. If\n * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.\n * @param defaultedOptions - The defaulted query options to fetch with.\n * @param observer - The observer of the query.\n * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.\n * @returns A promise that resolves once the fetch settles. It never rejects.\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":";;;;;;;;;AAiBA,MAAa,uBAMX,QACA,UACG,MAAM,MAAM,SAAS,KAAA;;;;;;;AAQ1B,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;;;;;;;AAQA,MAAa,iBACX,kBAGA,WACG,kBAAkB,YAAY,OAAO;;;;;;;;;AAU1C,MAAa,mBAOX,kBAOA,UACA,uBAEA,SAAS,gBAAgB,gBAAgB,CAAC,CAAC,YAAY;CACrD,mBAAmB,WAAW;AAChC,CAAC"}
@@ -1,9 +1,36 @@
1
1
  import { QueryErrorResetBoundaryValue } from "./QueryErrorResetBoundary.cjs";
2
2
  import { DefaultError, DefaultedQueryObserverOptions, Query, QueryKey, QueryObserver, QueryObserverResult } from "@tanstack/query-core";
3
3
  //#region src/suspense.d.ts
4
+ /**
5
+ * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
6
+ * only if the query has no data to show.
7
+ * @param _error - The error of the query. Unused.
8
+ * @param query - The query that errored.
9
+ * @returns `true` if the query has no data.
10
+ */
4
11
  export declare const defaultThrowOnError: <TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(_error: TError, query: Query<TQueryFnData, TError, TData, TQueryKey>) => boolean;
12
+ /**
13
+ * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
14
+ * component that remounts after suspending doesn't refetch right away or find the query garbage
15
+ * collected. A `'static'` `staleTime` is kept as is. Mutates the options.
16
+ * @param defaultedOptions - The defaulted query options to adjust.
17
+ */
5
18
  export declare const ensureSuspenseTimers: (defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>) => void;
19
+ /**
20
+ * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
21
+ * @param defaultedOptions - The defaulted query options, if any.
22
+ * @param result - The current result of the observer.
23
+ * @returns `true` if the component should suspend.
24
+ */
6
25
  export declare const shouldSuspend: (defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any> | undefined, result: QueryObserverResult<any, any>) => boolean | undefined;
26
+ /**
27
+ * Fetches the query for a suspending component, without affecting the observer's own result. If
28
+ * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
29
+ * @param defaultedOptions - The defaulted query options to fetch with.
30
+ * @param observer - The observer of the query.
31
+ * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
32
+ * @returns A promise that resolves once the fetch settles. It never rejects.
33
+ */
7
34
  export declare const fetchOptimistic: <TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(defaultedOptions: DefaultedQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>, errorResetBoundary: QueryErrorResetBoundaryValue) => Promise<void | QueryObserverResult<TData, TError>>;
8
35
  //#endregion
9
36
  //# sourceMappingURL=suspense.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"suspense.d.cts","names":[],"sources":["../../src/suspense.ts"],"mappings":";;;qBAUa,sBACX,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,QAAQ,QACR,OAAO,MAAM,cAAc,QAAQ,OAAO;qBAG/B,uBACX,kBAAkB;qBA2BP,gBACX,kBACE,oEACF,QAAQ;qBAGG,kBACX,cACA,QACA,OACA,YACA,kBAAkB,UAElB,kBAAkB,8BAChB,cACA,QACA,OACA,YACA,YAEF,UAAU,cAAc,cAAc,QAAQ,OAAO,YAAY,YACjE,oBAAoB,iCAA4B,eAAA,oBAAA,OAAA"}
1
+ {"version":3,"file":"suspense.d.cts","names":[],"sources":["../../src/suspense.ts"],"mappings":";;;;;;;;;;qBAiBa,sBACX,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,QAAQ,QACR,OAAO,MAAM,cAAc,QAAQ,OAAO;;;;;;;qBAS/B,uBACX,kBAAkB;;;;;;;qBAiCP,gBACX,kBACI,oEAEJ,QAAQ;;;;;;;;;qBAWG,kBACX,cACA,QACA,OACA,YACA,kBAAkB,UAElB,kBAAkB,8BAChB,cACA,QACA,OACA,YACA,YAEF,UAAU,cAAc,cAAc,QAAQ,OAAO,YAAY,YACjE,oBAAoB,iCAA4B,eAAA,oBAAA,OAAA"}
@@ -1,9 +1,36 @@
1
1
  import { QueryErrorResetBoundaryValue } from "./QueryErrorResetBoundary.js";
2
2
  import { DefaultError, DefaultedQueryObserverOptions, Query, QueryKey, QueryObserver, QueryObserverResult } from "@tanstack/query-core";
3
3
  //#region src/suspense.d.ts
4
+ /**
5
+ * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
6
+ * only if the query has no data to show.
7
+ * @param _error - The error of the query. Unused.
8
+ * @param query - The query that errored.
9
+ * @returns `true` if the query has no data.
10
+ */
4
11
  export declare const defaultThrowOnError: <TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(_error: TError, query: Query<TQueryFnData, TError, TData, TQueryKey>) => boolean;
12
+ /**
13
+ * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
14
+ * component that remounts after suspending doesn't refetch right away or find the query garbage
15
+ * collected. A `'static'` `staleTime` is kept as is. Mutates the options.
16
+ * @param defaultedOptions - The defaulted query options to adjust.
17
+ */
5
18
  export declare const ensureSuspenseTimers: (defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>) => void;
19
+ /**
20
+ * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
21
+ * @param defaultedOptions - The defaulted query options, if any.
22
+ * @param result - The current result of the observer.
23
+ * @returns `true` if the component should suspend.
24
+ */
6
25
  export declare const shouldSuspend: (defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any> | undefined, result: QueryObserverResult<any, any>) => boolean | undefined;
26
+ /**
27
+ * Fetches the query for a suspending component, without affecting the observer's own result. If
28
+ * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
29
+ * @param defaultedOptions - The defaulted query options to fetch with.
30
+ * @param observer - The observer of the query.
31
+ * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
32
+ * @returns A promise that resolves once the fetch settles. It never rejects.
33
+ */
7
34
  export declare const fetchOptimistic: <TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(defaultedOptions: DefaultedQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>, errorResetBoundary: QueryErrorResetBoundaryValue) => Promise<void | QueryObserverResult<TData, TError>>;
8
35
  //#endregion
9
36
  //# sourceMappingURL=suspense.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"suspense.d.ts","names":[],"sources":["../../src/suspense.ts"],"mappings":";;;qBAUa,sBACX,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,QAAQ,QACR,OAAO,MAAM,cAAc,QAAQ,OAAO;qBAG/B,uBACX,kBAAkB;qBA2BP,gBACX,kBACE,oEACF,QAAQ;qBAGG,kBACX,cACA,QACA,OACA,YACA,kBAAkB,UAElB,kBAAkB,8BAChB,cACA,QACA,OACA,YACA,YAEF,UAAU,cAAc,cAAc,QAAQ,OAAO,YAAY,YACjE,oBAAoB,iCAA4B,eAAA,oBAAA,OAAA"}
1
+ {"version":3,"file":"suspense.d.ts","names":[],"sources":["../../src/suspense.ts"],"mappings":";;;;;;;;;;qBAiBa,sBACX,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,QAAQ,QACR,OAAO,MAAM,cAAc,QAAQ,OAAO;;;;;;;qBAS/B,uBACX,kBAAkB;;;;;;;qBAiCP,gBACX,kBACI,oEAEJ,QAAQ;;;;;;;;;qBAWG,kBACX,cACA,QACA,OACA,YACA,kBAAkB,UAElB,kBAAkB,8BAChB,cACA,QACA,OACA,YACA,YAEF,UAAU,cAAc,cAAc,QAAQ,OAAO,YAAY,YACjE,oBAAoB,iCAA4B,eAAA,oBAAA,OAAA"}
@@ -1,5 +1,18 @@
1
1
  //#region src/suspense.ts
2
+ /**
3
+ * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
4
+ * only if the query has no data to show.
5
+ * @param _error - The error of the query. Unused.
6
+ * @param query - The query that errored.
7
+ * @returns `true` if the query has no data.
8
+ */
2
9
  const defaultThrowOnError = (_error, query) => query.state.data === void 0;
10
+ /**
11
+ * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
12
+ * component that remounts after suspending doesn't refetch right away or find the query garbage
13
+ * collected. A `'static'` `staleTime` is kept as is. Mutates the options.
14
+ * @param defaultedOptions - The defaulted query options to adjust.
15
+ */
3
16
  const ensureSuspenseTimers = (defaultedOptions) => {
4
17
  if (defaultedOptions.suspense) {
5
18
  const MIN_SUSPENSE_TIME_MS = 1e3;
@@ -9,7 +22,21 @@ const ensureSuspenseTimers = (defaultedOptions) => {
9
22
  if (typeof defaultedOptions.gcTime === "number") defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, MIN_SUSPENSE_TIME_MS);
10
23
  }
11
24
  };
25
+ /**
26
+ * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
27
+ * @param defaultedOptions - The defaulted query options, if any.
28
+ * @param result - The current result of the observer.
29
+ * @returns `true` if the component should suspend.
30
+ */
12
31
  const shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
32
+ /**
33
+ * Fetches the query for a suspending component, without affecting the observer's own result. If
34
+ * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
35
+ * @param defaultedOptions - The defaulted query options to fetch with.
36
+ * @param observer - The observer of the query.
37
+ * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
38
+ * @returns A promise that resolves once the fetch settles. It never rejects.
39
+ */
13
40
  const fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
14
41
  errorResetBoundary.clearReset();
15
42
  });
@@ -1 +1 @@
1
- {"version":3,"file":"suspense.js","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> | 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,kBAEA,WACG,kBAAkB,YAAY,OAAO;AAE1C,MAAa,mBAOX,kBAOA,UACA,uBAEA,SAAS,gBAAgB,gBAAgB,CAAC,CAAC,YAAY;CACrD,mBAAmB,WAAW;AAChC,CAAC"}
1
+ {"version":3,"file":"suspense.js","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\n/**\n * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary\n * only if the query has no data to show.\n * @param _error - The error of the query. Unused.\n * @param query - The query that errored.\n * @returns `true` if the query has no data.\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\n/**\n * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a\n * component that remounts after suspending doesn't refetch right away or find the query garbage\n * collected. A `'static'` `staleTime` is kept as is. Mutates the options.\n * @param defaultedOptions - The defaulted query options to adjust.\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\n/**\n * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.\n * @param defaultedOptions - The defaulted query options, if any.\n * @param result - The current result of the observer.\n * @returns `true` if the component should suspend.\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\n/**\n * Fetches the query for a suspending component, without affecting the observer's own result. If\n * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.\n * @param defaultedOptions - The defaulted query options to fetch with.\n * @param observer - The observer of the query.\n * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.\n * @returns A promise that resolves once the fetch settles. It never rejects.\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":";;;;;;;;AAiBA,MAAa,uBAMX,QACA,UACG,MAAM,MAAM,SAAS,KAAA;;;;;;;AAQ1B,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;;;;;;;AAQA,MAAa,iBACX,kBAGA,WACG,kBAAkB,YAAY,OAAO;;;;;;;;;AAU1C,MAAa,mBAOX,kBAOA,UACA,uBAEA,SAAS,gBAAgB,gBAAgB,CAAC,CAAC,YAAY;CACrD,mBAAmB,WAAW;AAChC,CAAC"}