@tanstack/react-query 5.0.0-alpha.12 → 5.0.0-alpha.19

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.
@@ -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));
@@ -1714,10 +1716,11 @@
1714
1716
  });
1715
1717
  }
1716
1718
  cancelQueries(filters = {}, cancelOptions = {}) {
1717
- if (typeof cancelOptions.revert === 'undefined') {
1718
- cancelOptions.revert = true;
1719
- }
1720
- 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)));
1721
1724
  return Promise.all(promises).then(noop$1).catch(noop$1);
1722
1725
  }
1723
1726
  invalidateQueries(filters = {}, options = {}) {
@@ -1866,10 +1869,12 @@
1866
1869
  #currentResult = undefined;
1867
1870
  #currentResultState;
1868
1871
  #currentResultOptions;
1869
- #previousQueryResult;
1870
1872
  #selectError;
1871
1873
  #selectFn;
1872
1874
  #selectResult;
1875
+ // This property keeps track of the last defined query data.
1876
+ // It will be used to pass the previous data to the placeholder function between renders.
1877
+ #lastDefinedQueryData;
1873
1878
  #staleTimeoutId;
1874
1879
  #refetchIntervalId;
1875
1880
  #currentRefetchInterval;
@@ -2064,7 +2069,6 @@
2064
2069
  const prevResultOptions = this.#currentResultOptions;
2065
2070
  const queryChange = query !== prevQuery;
2066
2071
  const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
2067
- const prevQueryResult = queryChange ? this.#currentResult : this.#previousQueryResult;
2068
2072
  const {
2069
2073
  state
2070
2074
  } = query;
@@ -2123,7 +2127,7 @@
2123
2127
  if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
2124
2128
  placeholderData = prevResult.data;
2125
2129
  } else {
2126
- placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(prevQueryResult?.data) : options.placeholderData;
2130
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastDefinedQueryData) : options.placeholderData;
2127
2131
  if (options.select && typeof placeholderData !== 'undefined') {
2128
2132
  try {
2129
2133
  placeholderData = options.select(placeholderData);
@@ -2187,6 +2191,9 @@
2187
2191
  if (shallowEqualObjects(nextResult, prevResult)) {
2188
2192
  return;
2189
2193
  }
2194
+ if (this.#currentResultState.data !== undefined) {
2195
+ this.#lastDefinedQueryData = this.#currentResultState.data;
2196
+ }
2190
2197
  this.#currentResult = nextResult;
2191
2198
 
2192
2199
  // Determine which callbacks to trigger
@@ -2227,7 +2234,6 @@
2227
2234
  const prevQuery = this.#currentQuery;
2228
2235
  this.#currentQuery = query;
2229
2236
  this.#currentQueryInitialState = query.state;
2230
- this.#previousQueryResult = this.#currentResult;
2231
2237
  if (this.hasListeners()) {
2232
2238
  prevQuery?.removeObserver(this);
2233
2239
  query.addObserver(this);