@tanstack/vue-query 5.0.0-alpha.18 → 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.
@@ -1850,10 +1850,12 @@
1850
1850
  #currentResult = undefined;
1851
1851
  #currentResultState;
1852
1852
  #currentResultOptions;
1853
- #previousQueryResult;
1854
1853
  #selectError;
1855
1854
  #selectFn;
1856
1855
  #selectResult;
1856
+ // This property keeps track of the last defined query data.
1857
+ // It will be used to pass the previous data to the placeholder function between renders.
1858
+ #lastDefinedQueryData;
1857
1859
  #staleTimeoutId;
1858
1860
  #refetchIntervalId;
1859
1861
  #currentRefetchInterval;
@@ -2048,7 +2050,6 @@
2048
2050
  const prevResultOptions = this.#currentResultOptions;
2049
2051
  const queryChange = query !== prevQuery;
2050
2052
  const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
2051
- const prevQueryResult = queryChange ? this.#currentResult : this.#previousQueryResult;
2052
2053
  const {
2053
2054
  state
2054
2055
  } = query;
@@ -2107,7 +2108,7 @@
2107
2108
  if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
2108
2109
  placeholderData = prevResult.data;
2109
2110
  } else {
2110
- placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(prevQueryResult?.data) : options.placeholderData;
2111
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastDefinedQueryData) : options.placeholderData;
2111
2112
  if (options.select && typeof placeholderData !== 'undefined') {
2112
2113
  try {
2113
2114
  placeholderData = options.select(placeholderData);
@@ -2171,6 +2172,9 @@
2171
2172
  if (shallowEqualObjects(nextResult, prevResult)) {
2172
2173
  return;
2173
2174
  }
2175
+ if (this.#currentResultState.data !== undefined) {
2176
+ this.#lastDefinedQueryData = this.#currentResultState.data;
2177
+ }
2174
2178
  this.#currentResult = nextResult;
2175
2179
 
2176
2180
  // Determine which callbacks to trigger
@@ -2211,7 +2215,6 @@
2211
2215
  const prevQuery = this.#currentQuery;
2212
2216
  this.#currentQuery = query;
2213
2217
  this.#currentQueryInitialState = query.state;
2214
- this.#previousQueryResult = this.#currentResult;
2215
2218
  if (this.hasListeners()) {
2216
2219
  prevQuery?.removeObserver(this);
2217
2220
  query.addObserver(this);