@tanstack/react-query 5.0.0-alpha.3 → 5.0.0-alpha.31

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 (204) hide show
  1. package/build/codemods/utils/index.js +205 -0
  2. package/build/codemods/utils/transformers/query-cache-transformer.js +116 -0
  3. package/build/codemods/utils/transformers/query-client-transformer.js +48 -0
  4. package/build/codemods/utils/transformers/use-query-like-transformer.js +32 -0
  5. package/build/codemods/v4/__testfixtures__/default-import.input.tsx +94 -0
  6. package/build/codemods/v4/__testfixtures__/default-import.output.tsx +96 -0
  7. package/build/codemods/v4/__testfixtures__/named-import.input.tsx +96 -0
  8. package/build/codemods/v4/__testfixtures__/named-import.output.tsx +98 -0
  9. package/build/codemods/v4/__testfixtures__/namespaced-import.input.tsx +86 -0
  10. package/build/codemods/v4/__testfixtures__/namespaced-import.output.tsx +88 -0
  11. package/build/codemods/v4/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
  12. package/build/codemods/v4/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
  13. package/build/codemods/v4/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
  14. package/build/codemods/v4/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
  15. package/build/codemods/v4/__testfixtures__/replace-import-specifier.input.tsx +10 -0
  16. package/build/codemods/v4/__testfixtures__/replace-import-specifier.output.tsx +10 -0
  17. package/build/codemods/v4/__testfixtures__/type-arguments.input.tsx +25 -0
  18. package/build/codemods/v4/__testfixtures__/type-arguments.output.tsx +31 -0
  19. package/build/codemods/v4/__tests__/key-transformation.test.js +32 -0
  20. package/build/codemods/v4/__tests__/replace-import-specifier.test.js +12 -0
  21. package/build/codemods/v4/key-transformation.js +138 -0
  22. package/build/codemods/v4/replace-import-specifier.js +25 -0
  23. package/build/codemods/v4/utils/replacers/key-replacer.js +164 -0
  24. package/build/codemods/v5/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
  25. package/build/codemods/v5/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
  26. package/build/codemods/v5/remove-overloads/__tests__/remove-overloads.test.js +6 -0
  27. package/build/codemods/v5/remove-overloads/remove-overloads.js +59 -0
  28. package/build/codemods/v5/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
  29. package/build/codemods/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
  30. package/build/codemods/v5/remove-overloads/utils/index.js +124 -0
  31. package/build/codemods/v5/remove-overloads/utils/unknown-usage-error.js +26 -0
  32. package/build/lib/HydrationBoundary.d.ts +1 -0
  33. package/build/lib/HydrationBoundary.d.ts.map +1 -0
  34. package/build/lib/HydrationBoundary.esm.js +1 -0
  35. package/build/lib/HydrationBoundary.esm.js.map +1 -1
  36. package/build/lib/HydrationBoundary.js +1 -0
  37. package/build/lib/HydrationBoundary.js.map +1 -1
  38. package/build/lib/HydrationBoundary.mjs +1 -0
  39. package/build/lib/HydrationBoundary.mjs.map +1 -1
  40. package/build/lib/QueryClientProvider.d.ts +1 -0
  41. package/build/lib/QueryClientProvider.d.ts.map +1 -0
  42. package/build/lib/QueryClientProvider.esm.js +1 -0
  43. package/build/lib/QueryClientProvider.esm.js.map +1 -1
  44. package/build/lib/QueryClientProvider.js +1 -0
  45. package/build/lib/QueryClientProvider.js.map +1 -1
  46. package/build/lib/QueryClientProvider.mjs +1 -0
  47. package/build/lib/QueryClientProvider.mjs.map +1 -1
  48. package/build/lib/QueryErrorResetBoundary.d.ts +1 -0
  49. package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
  50. package/build/lib/QueryErrorResetBoundary.esm.js +1 -0
  51. package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -1
  52. package/build/lib/QueryErrorResetBoundary.js +1 -0
  53. package/build/lib/QueryErrorResetBoundary.js.map +1 -1
  54. package/build/lib/QueryErrorResetBoundary.mjs +1 -0
  55. package/build/lib/QueryErrorResetBoundary.mjs.map +1 -1
  56. package/build/lib/__tests__/HydrationBoundary.test.d.ts +1 -0
  57. package/build/lib/__tests__/HydrationBoundary.test.d.ts.map +1 -0
  58. package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
  59. package/build/lib/__tests__/QueryClientProvider.test.d.ts.map +1 -0
  60. package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +1 -0
  61. package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts.map +1 -0
  62. package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
  63. package/build/lib/__tests__/ssr-hydration.test.d.ts.map +1 -0
  64. package/build/lib/__tests__/ssr.test.d.ts +1 -3
  65. package/build/lib/__tests__/ssr.test.d.ts.map +1 -0
  66. package/build/lib/__tests__/suspense.test.d.ts +1 -0
  67. package/build/lib/__tests__/suspense.test.d.ts.map +1 -0
  68. package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
  69. package/build/lib/__tests__/useInfiniteQuery.test.d.ts.map +1 -0
  70. package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +1 -0
  71. package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts.map +1 -0
  72. package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
  73. package/build/lib/__tests__/useIsFetching.test.d.ts.map +1 -0
  74. package/build/lib/__tests__/useMutation.test.d.ts +1 -0
  75. package/build/lib/__tests__/useMutation.test.d.ts.map +1 -0
  76. package/build/lib/__tests__/useMutationState.test.d.ts +1 -0
  77. package/build/lib/__tests__/useMutationState.test.d.ts.map +1 -0
  78. package/build/lib/__tests__/useQueries.test.d.ts +1 -0
  79. package/build/lib/__tests__/useQueries.test.d.ts.map +1 -0
  80. package/build/lib/__tests__/useQuery.test.d.ts +1 -0
  81. package/build/lib/__tests__/useQuery.test.d.ts.map +1 -0
  82. package/build/lib/__tests__/useQuery.types.test.d.ts +1 -0
  83. package/build/lib/__tests__/useQuery.types.test.d.ts.map +1 -0
  84. package/build/lib/__tests__/utils.d.ts +3 -3
  85. package/build/lib/__tests__/utils.d.ts.map +1 -0
  86. package/build/lib/errorBoundaryUtils.d.ts +4 -3
  87. package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
  88. package/build/lib/errorBoundaryUtils.esm.js +4 -3
  89. package/build/lib/errorBoundaryUtils.esm.js.map +1 -1
  90. package/build/lib/errorBoundaryUtils.js +4 -3
  91. package/build/lib/errorBoundaryUtils.js.map +1 -1
  92. package/build/lib/errorBoundaryUtils.mjs +4 -3
  93. package/build/lib/errorBoundaryUtils.mjs.map +1 -1
  94. package/build/lib/index.d.ts +2 -1
  95. package/build/lib/index.d.ts.map +1 -0
  96. package/build/lib/index.esm.js +1 -1
  97. package/build/lib/index.js +1 -0
  98. package/build/lib/index.js.map +1 -1
  99. package/build/lib/index.mjs +1 -1
  100. package/build/lib/isRestoring.d.ts +1 -0
  101. package/build/lib/isRestoring.d.ts.map +1 -0
  102. package/build/lib/isRestoring.esm.js +1 -0
  103. package/build/lib/isRestoring.esm.js.map +1 -1
  104. package/build/lib/isRestoring.js +1 -0
  105. package/build/lib/isRestoring.js.map +1 -1
  106. package/build/lib/isRestoring.mjs +1 -0
  107. package/build/lib/isRestoring.mjs.map +1 -1
  108. package/build/lib/suspense.d.ts +2 -1
  109. package/build/lib/suspense.d.ts.map +1 -0
  110. package/build/lib/suspense.esm.js +2 -9
  111. package/build/lib/suspense.esm.js.map +1 -1
  112. package/build/lib/suspense.js +2 -9
  113. package/build/lib/suspense.js.map +1 -1
  114. package/build/lib/suspense.mjs +1 -8
  115. package/build/lib/suspense.mjs.map +1 -1
  116. package/build/lib/types.d.ts +1 -0
  117. package/build/lib/types.d.ts.map +1 -0
  118. package/build/lib/useBaseQuery.d.ts +1 -0
  119. package/build/lib/useBaseQuery.d.ts.map +1 -0
  120. package/build/lib/useBaseQuery.esm.js +2 -12
  121. package/build/lib/useBaseQuery.esm.js.map +1 -1
  122. package/build/lib/useBaseQuery.js +2 -12
  123. package/build/lib/useBaseQuery.js.map +1 -1
  124. package/build/lib/useBaseQuery.mjs +2 -12
  125. package/build/lib/useBaseQuery.mjs.map +1 -1
  126. package/build/lib/useInfiniteQuery.d.ts +1 -0
  127. package/build/lib/useInfiniteQuery.d.ts.map +1 -0
  128. package/build/lib/useInfiniteQuery.esm.js +1 -0
  129. package/build/lib/useInfiniteQuery.esm.js.map +1 -1
  130. package/build/lib/useInfiniteQuery.js +1 -0
  131. package/build/lib/useInfiniteQuery.js.map +1 -1
  132. package/build/lib/useInfiniteQuery.mjs +1 -0
  133. package/build/lib/useInfiniteQuery.mjs.map +1 -1
  134. package/build/lib/useIsFetching.d.ts +1 -0
  135. package/build/lib/useIsFetching.d.ts.map +1 -0
  136. package/build/lib/useIsFetching.esm.js +1 -0
  137. package/build/lib/useIsFetching.esm.js.map +1 -1
  138. package/build/lib/useIsFetching.js +1 -0
  139. package/build/lib/useIsFetching.js.map +1 -1
  140. package/build/lib/useIsFetching.mjs +1 -0
  141. package/build/lib/useIsFetching.mjs.map +1 -1
  142. package/build/lib/useMutation.d.ts +1 -0
  143. package/build/lib/useMutation.d.ts.map +1 -0
  144. package/build/lib/useMutation.esm.js +2 -1
  145. package/build/lib/useMutation.esm.js.map +1 -1
  146. package/build/lib/useMutation.js +2 -1
  147. package/build/lib/useMutation.js.map +1 -1
  148. package/build/lib/useMutation.mjs +2 -1
  149. package/build/lib/useMutation.mjs.map +1 -1
  150. package/build/lib/useMutationState.d.ts +4 -3
  151. package/build/lib/useMutationState.d.ts.map +1 -0
  152. package/build/lib/useMutationState.esm.js +1 -0
  153. package/build/lib/useMutationState.esm.js.map +1 -1
  154. package/build/lib/useMutationState.js +1 -0
  155. package/build/lib/useMutationState.js.map +1 -1
  156. package/build/lib/useMutationState.mjs +1 -0
  157. package/build/lib/useMutationState.mjs.map +1 -1
  158. package/build/lib/useQueries.d.ts +3 -3
  159. package/build/lib/useQueries.d.ts.map +1 -0
  160. package/build/lib/useQueries.esm.js +20 -16
  161. package/build/lib/useQueries.esm.js.map +1 -1
  162. package/build/lib/useQueries.js +20 -16
  163. package/build/lib/useQueries.js.map +1 -1
  164. package/build/lib/useQueries.mjs +12 -11
  165. package/build/lib/useQueries.mjs.map +1 -1
  166. package/build/lib/useQuery.d.ts +3 -0
  167. package/build/lib/useQuery.d.ts.map +1 -0
  168. package/build/lib/useQuery.esm.js +6 -1
  169. package/build/lib/useQuery.esm.js.map +1 -1
  170. package/build/lib/useQuery.js +6 -0
  171. package/build/lib/useQuery.js.map +1 -1
  172. package/build/lib/useQuery.mjs +6 -1
  173. package/build/lib/useQuery.mjs.map +1 -1
  174. package/build/lib/utils.d.ts +1 -0
  175. package/build/lib/utils.d.ts.map +1 -0
  176. package/build/umd/index.development.js +124 -155
  177. package/build/umd/index.development.js.map +1 -1
  178. package/build/umd/index.production.js +1 -1
  179. package/build/umd/index.production.js.map +1 -1
  180. package/package.json +9 -4
  181. package/src/__tests__/HydrationBoundary.test.tsx +4 -3
  182. package/src/__tests__/QueryClientProvider.test.tsx +2 -1
  183. package/src/__tests__/QueryResetErrorBoundary.test.tsx +753 -620
  184. package/src/__tests__/ssr-hydration.test.tsx +11 -10
  185. package/src/__tests__/ssr.test.tsx +4 -7
  186. package/src/__tests__/suspense.test.tsx +17 -98
  187. package/src/__tests__/useInfiniteQuery.test.tsx +18 -16
  188. package/src/__tests__/useInfiniteQuery.type.test.tsx +94 -13
  189. package/src/__tests__/useMutation.test.tsx +25 -24
  190. package/src/__tests__/useMutationState.test.tsx +24 -58
  191. package/src/__tests__/useQueries.test.tsx +34 -163
  192. package/src/__tests__/useQuery.test.tsx +234 -365
  193. package/src/__tests__/useQuery.types.test.tsx +21 -1
  194. package/src/__tests__/utils.tsx +3 -2
  195. package/src/errorBoundaryUtils.ts +6 -5
  196. package/src/index.ts +1 -1
  197. package/src/suspense.ts +3 -11
  198. package/src/useBaseQuery.ts +2 -20
  199. package/src/useInfiniteQuery.ts +1 -0
  200. package/src/useIsFetching.ts +1 -0
  201. package/src/useMutation.ts +2 -1
  202. package/src/useMutationState.ts +4 -3
  203. package/src/useQueries.ts +20 -19
  204. package/src/useQuery.ts +23 -0
@@ -926,7 +926,7 @@
926
926
  {
927
927
  console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`);
928
928
  }
929
- onError(new Error('undefined'));
929
+ onError(new Error(`${this.queryHash} data is undefined`));
930
930
  return;
931
931
  }
932
932
  this.setData(data);
@@ -1043,7 +1043,7 @@
1043
1043
  this.state = reducer(this.state);
1044
1044
  notifyManager.batch(() => {
1045
1045
  this.#observers.forEach(observer => {
1046
- observer.onQueryUpdate(action);
1046
+ observer.onQueryUpdate();
1047
1047
  });
1048
1048
  this.#cache.notify({
1049
1049
  query: this,
@@ -1080,7 +1080,7 @@
1080
1080
  constructor(config = {}) {
1081
1081
  super();
1082
1082
  this.config = config;
1083
- this.#queries = config.createStore?.() ?? new Map();
1083
+ this.#queries = new Map();
1084
1084
  }
1085
1085
  build(client, options, state) {
1086
1086
  const queryKey = options.queryKey;
@@ -1135,10 +1135,11 @@
1135
1135
  return [...this.#queries.values()];
1136
1136
  }
1137
1137
  find(filters) {
1138
- if (typeof filters.exact === 'undefined') {
1139
- filters.exact = true;
1140
- }
1141
- return this.getAll().find(query => matchQuery(filters, query));
1138
+ const defaultedFilters = {
1139
+ exact: true,
1140
+ ...filters
1141
+ };
1142
+ return this.getAll().find(query => matchQuery(defaultedFilters, query));
1142
1143
  }
1143
1144
  findAll(filters = {}) {
1144
1145
  const queries = this.getAll();
@@ -1444,10 +1445,11 @@
1444
1445
  return this.#mutations;
1445
1446
  }
1446
1447
  find(filters) {
1447
- if (typeof filters.exact === 'undefined') {
1448
- filters.exact = true;
1449
- }
1450
- return this.#mutations.find(mutation => matchMutation(filters, mutation));
1448
+ const defaultedFilters = {
1449
+ exact: true,
1450
+ ...filters
1451
+ };
1452
+ return this.#mutations.find(mutation => matchMutation(defaultedFilters, mutation));
1451
1453
  }
1452
1454
  findAll(filters = {}) {
1453
1455
  return this.#mutations.filter(mutation => matchMutation(filters, mutation));
@@ -1473,12 +1475,15 @@
1473
1475
  function infiniteQueryBehavior() {
1474
1476
  return {
1475
1477
  onFetch: context => {
1476
- context.fetchFn = () => {
1478
+ context.fetchFn = async () => {
1477
1479
  const options = context.options;
1478
1480
  const direction = context.fetchOptions?.meta?.fetchMore?.direction;
1479
1481
  const oldPages = context.state.data?.pages || [];
1480
1482
  const oldPageParams = context.state.data?.pageParams || [];
1481
- let newPageParams = oldPageParams;
1483
+ const empty = {
1484
+ pages: [],
1485
+ pageParams: []
1486
+ };
1482
1487
  let cancelled = false;
1483
1488
  const addSignalProperty = object => {
1484
1489
  Object.defineProperty(object, 'signal', {
@@ -1498,95 +1503,95 @@
1498
1503
 
1499
1504
  // Get query function
1500
1505
  const queryFn = context.options.queryFn || (() => Promise.reject(new Error('Missing queryFn')));
1501
- const buildNewPages = (pages, param, page, previous) => {
1502
- const {
1503
- maxPages
1504
- } = context.options;
1505
- if (previous) {
1506
- newPageParams = addToStart(newPageParams, param, maxPages);
1507
- return addToStart(pages, page, maxPages);
1508
- }
1509
- newPageParams = addToEnd(newPageParams, param, maxPages);
1510
- return addToEnd(pages, page, maxPages);
1511
- };
1512
1506
 
1513
1507
  // Create function to fetch a page
1514
- const fetchPage = (pages, param, previous) => {
1508
+ const fetchPage = async (data, param, previous) => {
1515
1509
  if (cancelled) {
1516
1510
  return Promise.reject();
1517
1511
  }
1518
- if (typeof param === 'undefined' && pages.length) {
1519
- return Promise.resolve(pages);
1512
+ if (typeof param === 'undefined' && data.pages.length) {
1513
+ return Promise.resolve(data);
1520
1514
  }
1521
1515
  const queryFnContext = {
1522
1516
  queryKey: context.queryKey,
1523
1517
  pageParam: param,
1518
+ direction: previous ? 'backward' : 'forward',
1524
1519
  meta: context.options.meta
1525
1520
  };
1526
1521
  addSignalProperty(queryFnContext);
1527
- const queryFnResult = queryFn(queryFnContext);
1528
- const promise = Promise.resolve(queryFnResult).then(page => buildNewPages(pages, param, page, previous));
1529
- return promise;
1522
+ const page = await queryFn(queryFnContext);
1523
+ const {
1524
+ maxPages
1525
+ } = context.options;
1526
+ const addTo = previous ? addToStart : addToEnd;
1527
+ return {
1528
+ pages: addTo(data.pages, page, maxPages),
1529
+ pageParams: addTo(data.pageParams, param, maxPages)
1530
+ };
1530
1531
  };
1531
- let promise;
1532
+ let result;
1532
1533
 
1533
1534
  // Fetch first page?
1534
1535
  if (!oldPages.length) {
1535
- promise = fetchPage([], options.defaultPageParam);
1536
+ result = await fetchPage(empty, options.defaultPageParam);
1536
1537
  }
1537
1538
 
1538
1539
  // fetch next / previous page?
1539
1540
  else if (direction) {
1540
1541
  const previous = direction === 'backward';
1541
- const param = previous ? getPreviousPageParam(options, oldPages) : getNextPageParam(options, oldPages);
1542
- promise = fetchPage(oldPages, param, previous);
1542
+ const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
1543
+ const oldData = {
1544
+ pages: oldPages,
1545
+ pageParams: oldPageParams
1546
+ };
1547
+ const param = pageParamFn(options, oldData);
1548
+ result = await fetchPage(oldData, param, previous);
1543
1549
  }
1544
1550
 
1545
1551
  // Refetch pages
1546
1552
  else {
1547
- newPageParams = [];
1548
-
1549
1553
  // Fetch first page
1550
- promise = fetchPage([], oldPageParams[0]);
1554
+ result = await fetchPage(empty, oldPageParams[0]);
1551
1555
 
1552
1556
  // Fetch remaining pages
1553
1557
  for (let i = 1; i < oldPages.length; i++) {
1554
- promise = promise.then(pages => {
1555
- const param = getNextPageParam(options, pages);
1556
- return fetchPage(pages, param);
1557
- });
1558
+ const param = getNextPageParam(options, result);
1559
+ result = await fetchPage(result, param);
1558
1560
  }
1559
1561
  }
1560
- const finalPromise = promise.then(pages => ({
1561
- pages,
1562
- pageParams: newPageParams
1563
- }));
1564
- return finalPromise;
1562
+ return result;
1565
1563
  };
1566
1564
  }
1567
1565
  };
1568
1566
  }
1569
- function getNextPageParam(options, pages) {
1570
- return options.getNextPageParam(pages[pages.length - 1], pages);
1567
+ function getNextPageParam(options, {
1568
+ pages,
1569
+ pageParams
1570
+ }) {
1571
+ const lastIndex = pages.length - 1;
1572
+ return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams);
1571
1573
  }
1572
- function getPreviousPageParam(options, pages) {
1573
- return options.getPreviousPageParam?.(pages[0], pages);
1574
+ function getPreviousPageParam(options, {
1575
+ pages,
1576
+ pageParams
1577
+ }) {
1578
+ return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams);
1574
1579
  }
1575
1580
 
1576
1581
  /**
1577
1582
  * Checks if there is a next page.
1578
1583
  */
1579
- function hasNextPage(options, pages) {
1580
- if (!pages) return false;
1581
- return typeof getNextPageParam(options, pages) !== 'undefined';
1584
+ function hasNextPage(options, data) {
1585
+ if (!data) return false;
1586
+ return typeof getNextPageParam(options, data) !== 'undefined';
1582
1587
  }
1583
1588
 
1584
1589
  /**
1585
1590
  * Checks if there is a previous page.
1586
1591
  */
1587
- function hasPreviousPage(options, pages) {
1588
- if (!pages || !options.getPreviousPageParam) return false;
1589
- return typeof getPreviousPageParam(options, pages) !== 'undefined';
1592
+ function hasPreviousPage(options, data) {
1593
+ if (!data || !options.getPreviousPageParam) return false;
1594
+ return typeof getPreviousPageParam(options, data) !== 'undefined';
1590
1595
  }
1591
1596
 
1592
1597
  // CLASS
@@ -1711,10 +1716,11 @@
1711
1716
  });
1712
1717
  }
1713
1718
  cancelQueries(filters = {}, cancelOptions = {}) {
1714
- if (typeof cancelOptions.revert === 'undefined') {
1715
- cancelOptions.revert = true;
1716
- }
1717
- const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(cancelOptions)));
1719
+ const defaultedCancelOptions = {
1720
+ revert: true,
1721
+ ...cancelOptions
1722
+ };
1723
+ const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(defaultedCancelOptions)));
1718
1724
  return Promise.all(promises).then(noop$1).catch(noop$1);
1719
1725
  }
1720
1726
  invalidateQueries(filters = {}, options = {}) {
@@ -1733,15 +1739,18 @@
1733
1739
  });
1734
1740
  }
1735
1741
  refetchQueries(filters = {}, options) {
1736
- const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => query.fetch(undefined, {
1742
+ const fetchOptions = {
1737
1743
  ...options,
1738
1744
  cancelRefetch: options?.cancelRefetch ?? true
1739
- })));
1740
- let promise = Promise.all(promises).then(noop$1);
1741
- if (!options?.throwOnError) {
1742
- promise = promise.catch(noop$1);
1743
- }
1744
- return promise;
1745
+ };
1746
+ const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => {
1747
+ let promise = query.fetch(undefined, fetchOptions);
1748
+ if (!fetchOptions.throwOnError) {
1749
+ promise = promise.catch(noop$1);
1750
+ }
1751
+ return query.state.fetchStatus === 'paused' ? Promise.resolve() : promise;
1752
+ }));
1753
+ return Promise.all(promises).then(noop$1);
1745
1754
  }
1746
1755
  fetchQuery(options) {
1747
1756
  const defaultedOptions = this.defaultQueryOptions(options);
@@ -1834,8 +1843,8 @@
1834
1843
  if (typeof defaultedOptions.refetchOnReconnect === 'undefined') {
1835
1844
  defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== 'always';
1836
1845
  }
1837
- if (typeof defaultedOptions.throwErrors === 'undefined') {
1838
- defaultedOptions.throwErrors = !!defaultedOptions.suspense;
1846
+ if (typeof defaultedOptions.throwOnError === 'undefined') {
1847
+ defaultedOptions.throwOnError = !!defaultedOptions.suspense;
1839
1848
  }
1840
1849
  return defaultedOptions;
1841
1850
  }
@@ -1863,10 +1872,12 @@
1863
1872
  #currentResult = undefined;
1864
1873
  #currentResultState;
1865
1874
  #currentResultOptions;
1866
- #previousQueryResult;
1867
1875
  #selectError;
1868
1876
  #selectFn;
1869
1877
  #selectResult;
1878
+ // This property keeps track of the last query with defined data.
1879
+ // It will be used to pass the previous data and query to the placeholder function between renders.
1880
+ #lastQueryWithDefinedData;
1870
1881
  #staleTimeoutId;
1871
1882
  #refetchIntervalId;
1872
1883
  #currentRefetchInterval;
@@ -2023,7 +2034,7 @@
2023
2034
  }, timeout);
2024
2035
  }
2025
2036
  #computeRefetchInterval() {
2026
- return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.#currentResult.data, this.#currentQuery) : this.options.refetchInterval ?? false;
2037
+ return (typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.#currentResult.data, this.#currentQuery) : this.options.refetchInterval) ?? false;
2027
2038
  }
2028
2039
  #updateRefetchInterval(nextInterval) {
2029
2040
  this.#clearRefetchInterval();
@@ -2061,7 +2072,6 @@
2061
2072
  const prevResultOptions = this.#currentResultOptions;
2062
2073
  const queryChange = query !== prevQuery;
2063
2074
  const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
2064
- const prevQueryResult = queryChange ? this.#currentResult : this.#previousQueryResult;
2065
2075
  const {
2066
2076
  state
2067
2077
  } = query;
@@ -2120,7 +2130,7 @@
2120
2130
  if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
2121
2131
  placeholderData = prevResult.data;
2122
2132
  } else {
2123
- placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(prevQueryResult?.data) : options.placeholderData;
2133
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
2124
2134
  if (options.select && typeof placeholderData !== 'undefined') {
2125
2135
  try {
2126
2136
  placeholderData = options.select(placeholderData);
@@ -2184,6 +2194,9 @@
2184
2194
  if (shallowEqualObjects(nextResult, prevResult)) {
2185
2195
  return;
2186
2196
  }
2197
+ if (this.#currentResultState.data !== undefined) {
2198
+ this.#lastQueryWithDefinedData = this.#currentQuery;
2199
+ }
2187
2200
  this.#currentResult = nextResult;
2188
2201
 
2189
2202
  // Determine which callbacks to trigger
@@ -2199,7 +2212,7 @@
2199
2212
  return true;
2200
2213
  }
2201
2214
  const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps);
2202
- if (this.options.throwErrors) {
2215
+ if (this.options.throwOnError) {
2203
2216
  includedProps.add('error');
2204
2217
  }
2205
2218
  return Object.keys(this.#currentResult).some(key => {
@@ -2224,36 +2237,20 @@
2224
2237
  const prevQuery = this.#currentQuery;
2225
2238
  this.#currentQuery = query;
2226
2239
  this.#currentQueryInitialState = query.state;
2227
- this.#previousQueryResult = this.#currentResult;
2228
2240
  if (this.hasListeners()) {
2229
2241
  prevQuery?.removeObserver(this);
2230
2242
  query.addObserver(this);
2231
2243
  }
2232
2244
  }
2233
- onQueryUpdate(action) {
2234
- const notifyOptions = {};
2235
- if (action.type === 'success') {
2236
- notifyOptions.onSuccess = !action.manual;
2237
- } else if (action.type === 'error' && !isCancelledError(action.error)) {
2238
- notifyOptions.onError = true;
2239
- }
2240
- this.#updateResult(notifyOptions);
2245
+ onQueryUpdate() {
2246
+ this.#updateResult();
2241
2247
  if (this.hasListeners()) {
2242
2248
  this.#updateTimers();
2243
2249
  }
2244
2250
  }
2245
2251
  #notify(notifyOptions) {
2246
2252
  notifyManager.batch(() => {
2247
- // First trigger the configuration callbacks
2248
- if (notifyOptions.onSuccess) {
2249
- this.options.onSuccess?.(this.#currentResult.data);
2250
- this.options.onSettled?.(this.#currentResult.data, null);
2251
- } else if (notifyOptions.onError) {
2252
- this.options.onError?.(this.#currentResult.error);
2253
- this.options.onSettled?.(undefined, this.#currentResult.error);
2254
- }
2255
-
2256
- // Then trigger the listeners
2253
+ // First, trigger the listeners
2257
2254
  if (notifyOptions.listeners) {
2258
2255
  this.listeners.forEach(listener => {
2259
2256
  listener(this.#currentResult);
@@ -2375,9 +2372,10 @@
2375
2372
  }
2376
2373
  #findMatchingObservers(queries) {
2377
2374
  const prevObservers = this.#observers;
2375
+ const prevObserversMap = new Map(prevObservers.map(observer => [observer.options.queryHash, observer]));
2378
2376
  const defaultedQueryOptions = queries.map(options => this.#client.defaultQueryOptions(options));
2379
2377
  const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
2380
- const match = prevObservers.find(observer => observer.options.queryHash === defaultedOptions.queryHash);
2378
+ const match = prevObserversMap.get(defaultedOptions.queryHash);
2381
2379
  if (match != null) {
2382
2380
  return [{
2383
2381
  defaultedQueryOptions: defaultedOptions,
@@ -2386,8 +2384,8 @@
2386
2384
  }
2387
2385
  return [];
2388
2386
  });
2389
- const matchedQueryHashes = matchingObservers.map(match => match.defaultedQueryOptions.queryHash);
2390
- const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.includes(defaultedOptions.queryHash));
2387
+ const matchedQueryHashes = new Set(matchingObservers.map(match => match.defaultedQueryOptions.queryHash));
2388
+ const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.has(defaultedOptions.queryHash));
2391
2389
  const getObserver = options => {
2392
2390
  const defaultedOptions = this.#client.defaultQueryOptions(options);
2393
2391
  const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
@@ -2444,7 +2442,7 @@
2444
2442
  options.behavior = infiniteQueryBehavior();
2445
2443
  return super.getOptimisticResult(options);
2446
2444
  }
2447
- fetchNextPage(options = {}) {
2445
+ fetchNextPage(options) {
2448
2446
  return this.fetch({
2449
2447
  ...options,
2450
2448
  meta: {
@@ -2454,9 +2452,7 @@
2454
2452
  }
2455
2453
  });
2456
2454
  }
2457
- fetchPreviousPage({
2458
- ...options
2459
- } = {}) {
2455
+ fetchPreviousPage(options) {
2460
2456
  return this.fetch({
2461
2457
  ...options,
2462
2458
  meta: {
@@ -2481,8 +2477,8 @@
2481
2477
  ...result,
2482
2478
  fetchNextPage: this.fetchNextPage,
2483
2479
  fetchPreviousPage: this.fetchPreviousPage,
2484
- hasNextPage: hasNextPage(options, state.data?.pages),
2485
- hasPreviousPage: hasPreviousPage(options, state.data?.pages),
2480
+ hasNextPage: hasNextPage(options, state.data),
2481
+ hasPreviousPage: hasPreviousPage(options, state.data),
2486
2482
  isFetchingNextPage,
2487
2483
  isFetchingPreviousPage,
2488
2484
  isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
@@ -2608,24 +2604,10 @@
2608
2604
  return query.state.status === 'success';
2609
2605
  }
2610
2606
  function dehydrate(client, options = {}) {
2611
- const mutations = [];
2612
- const queries = [];
2613
- if (options.dehydrateMutations !== false) {
2614
- const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
2615
- client.getMutationCache().getAll().forEach(mutation => {
2616
- if (shouldDehydrateMutation(mutation)) {
2617
- mutations.push(dehydrateMutation(mutation));
2618
- }
2619
- });
2620
- }
2621
- if (options.dehydrateQueries !== false) {
2622
- const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
2623
- client.getQueryCache().getAll().forEach(query => {
2624
- if (shouldDehydrateQuery(query)) {
2625
- queries.push(dehydrateQuery(query));
2626
- }
2627
- });
2628
- }
2607
+ const filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
2608
+ const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);
2609
+ const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
2610
+ const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);
2629
2611
  return {
2630
2612
  mutations,
2631
2613
  queries
@@ -2747,7 +2729,7 @@
2747
2729
  }
2748
2730
 
2749
2731
  const ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
2750
- if (options.suspense || options.throwErrors) {
2732
+ if (options.suspense || options.throwOnError) {
2751
2733
  // Prevent retrying failed query if the error boundary has not been reset yet
2752
2734
  if (!errorResetBoundary.isReset()) {
2753
2735
  options.retryOnMount = false;
@@ -2762,10 +2744,10 @@
2762
2744
  const getHasError = ({
2763
2745
  result,
2764
2746
  errorResetBoundary,
2765
- throwErrors,
2747
+ throwOnError,
2766
2748
  query
2767
2749
  }) => {
2768
- return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(throwErrors, [result.error, query]);
2750
+ return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(throwOnError, [result.error, query]);
2769
2751
  };
2770
2752
 
2771
2753
  const ensureStaleTime = defaultedOptions => {
@@ -2779,26 +2761,19 @@
2779
2761
  };
2780
2762
  const willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring;
2781
2763
  const shouldSuspend = (defaultedOptions, result, isRestoring) => defaultedOptions?.suspense && willFetch(result, isRestoring);
2782
- const fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).then(({
2783
- data
2784
- }) => {
2785
- defaultedOptions.onSuccess?.(data);
2786
- defaultedOptions.onSettled?.(data, null);
2787
- }).catch(error => {
2764
+ const fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
2788
2765
  errorResetBoundary.clearReset();
2789
- defaultedOptions.onError?.(error);
2790
- defaultedOptions.onSettled?.(undefined, error);
2791
2766
  });
2792
2767
 
2793
2768
  // This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
2794
2769
  // `placeholderData` function does not have a parameter
2795
2770
 
2796
2771
  function useQueries({
2797
- queries,
2798
- queryClient
2799
- }) {
2772
+ queries
2773
+ }, queryClient) {
2800
2774
  const client = useQueryClient(queryClient);
2801
2775
  const isRestoring = useIsRestoring();
2776
+ const errorResetBoundary = useQueryErrorResetBoundary();
2802
2777
  const defaultedQueries = React__namespace.useMemo(() => queries.map(options => {
2803
2778
  const defaultedOptions = client.defaultQueryOptions(options);
2804
2779
 
@@ -2806,6 +2781,11 @@
2806
2781
  defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
2807
2782
  return defaultedOptions;
2808
2783
  }), [queries, client, isRestoring]);
2784
+ defaultedQueries.forEach(query => {
2785
+ ensureStaleTime(query);
2786
+ ensurePreventErrorBoundaryRetry(query, errorResetBoundary);
2787
+ });
2788
+ useClearResetErrorBoundary(errorResetBoundary);
2809
2789
  const [observer] = React__namespace.useState(() => new QueriesObserver(client, defaultedQueries));
2810
2790
  const optimisticResult = observer.getOptimisticResult(defaultedQueries);
2811
2791
  React__namespace.useSyncExternalStore(React__namespace.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
@@ -2816,12 +2796,6 @@
2816
2796
  listeners: false
2817
2797
  });
2818
2798
  }, [defaultedQueries, observer]);
2819
- const errorResetBoundary = useQueryErrorResetBoundary();
2820
- defaultedQueries.forEach(query => {
2821
- ensurePreventErrorBoundaryRetry(query, errorResetBoundary);
2822
- ensureStaleTime(query);
2823
- });
2824
- useClearResetErrorBoundary(errorResetBoundary);
2825
2799
  const shouldAtLeastOneSuspend = optimisticResult.some((result, index) => shouldSuspend(defaultedQueries[index], result, isRestoring));
2826
2800
  const suspensePromises = shouldAtLeastOneSuspend ? optimisticResult.flatMap((result, index) => {
2827
2801
  const options = defaultedQueries[index];
@@ -2838,11 +2812,12 @@
2838
2812
  if (suspensePromises.length > 0) {
2839
2813
  throw Promise.all(suspensePromises);
2840
2814
  }
2815
+ const observerQueries = observer.getQueries();
2841
2816
  const firstSingleResultWhichShouldThrow = optimisticResult.find((result, index) => getHasError({
2842
2817
  result,
2843
2818
  errorResetBoundary,
2844
- throwErrors: defaultedQueries[index]?.throwErrors ?? false,
2845
- query: observer.getQueries()[index]
2819
+ throwOnError: defaultedQueries[index]?.throwOnError ?? false,
2820
+ query: observerQueries[index]
2846
2821
  }));
2847
2822
  if (firstSingleResultWhichShouldThrow?.error) {
2848
2823
  throw firstSingleResultWhichShouldThrow.error;
@@ -2858,17 +2833,6 @@
2858
2833
 
2859
2834
  // Make sure results are optimistically set in fetching state before subscribing or updating options
2860
2835
  defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
2861
-
2862
- // Include callbacks in batch renders
2863
- if (defaultedOptions.onError) {
2864
- defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
2865
- }
2866
- if (defaultedOptions.onSuccess) {
2867
- defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
2868
- }
2869
- if (defaultedOptions.onSettled) {
2870
- defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
2871
- }
2872
2836
  ensureStaleTime(defaultedOptions);
2873
2837
  ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
2874
2838
  useClearResetErrorBoundary(errorResetBoundary);
@@ -2892,7 +2856,7 @@
2892
2856
  if (getHasError({
2893
2857
  result,
2894
2858
  errorResetBoundary,
2895
- throwErrors: defaultedOptions.throwErrors,
2859
+ throwOnError: defaultedOptions.throwOnError,
2896
2860
  query: observer.getCurrentQuery()
2897
2861
  })) {
2898
2862
  throw result.error;
@@ -2902,6 +2866,10 @@
2902
2866
  return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
2903
2867
  }
2904
2868
 
2869
+ function queryOptions(options) {
2870
+ return options;
2871
+ }
2872
+
2905
2873
  // HOOK
2906
2874
 
2907
2875
  function useQuery(options, queryClient) {
@@ -2979,7 +2947,7 @@
2979
2947
  const mutate = React__namespace.useCallback((variables, mutateOptions) => {
2980
2948
  observer.mutate(variables, mutateOptions).catch(noop);
2981
2949
  }, [observer]);
2982
- if (result.error && shouldThrowError(observer.options.throwErrors, [result.error])) {
2950
+ if (result.error && shouldThrowError(observer.options.throwOnError, [result.error])) {
2983
2951
  throw result.error;
2984
2952
  }
2985
2953
  return {
@@ -3024,6 +2992,7 @@
3024
2992
  exports.matchQuery = matchQuery;
3025
2993
  exports.notifyManager = notifyManager;
3026
2994
  exports.onlineManager = onlineManager;
2995
+ exports.queryOptions = queryOptions;
3027
2996
  exports.replaceEqualDeep = replaceEqualDeep;
3028
2997
  exports.useInfiniteQuery = useInfiniteQuery;
3029
2998
  exports.useIsFetching = useIsFetching;