@@ -15,13 +15,15 @@ export class QueryObserver<TResult, TError> {
1515 private currentResult ! : QueryResult < TResult , TError >
1616 private previousQueryResult ?: QueryResult < TResult , TError >
1717 private updateListener ?: UpdateListener < TResult , TError >
18+ private initialFetchedCount : number
1819 private staleTimeoutId ?: number
1920 private refetchIntervalId ?: number
2021 private started ?: boolean
2122
2223 constructor ( config : QueryObserverConfig < TResult , TError > ) {
2324 this . config = config
2425 this . queryCache = config . queryCache !
26+ this . initialFetchedCount = 0
2527
2628 // Bind exposed methods
2729 this . clear = this . clear . bind ( this )
@@ -100,6 +102,10 @@ export class QueryObserver<TResult, TError> {
100102 return this . currentResult . isStale
101103 }
102104
105+ getCurrentQuery ( ) : Query < TResult , TError > {
106+ return this . currentQuery
107+ }
108+
103109 getCurrentResult ( ) : QueryResult < TResult , TError > {
104110 return this . currentResult
105111 }
@@ -224,16 +230,18 @@ export class QueryObserver<TResult, TError> {
224230 const { currentQuery, currentResult, previousQueryResult, config } = this
225231 const { state } = currentQuery
226232 let { data, status, updatedAt } = state
233+ let isPreviousData = false
227234
228235 // Keep previous data if needed
229236 if (
230237 config . keepPreviousData &&
231- state . isLoading &&
238+ ( state . isIdle || state . isLoading ) &&
232239 previousQueryResult ?. isSuccess
233240 ) {
234241 data = previousQueryResult . data
235242 updatedAt = previousQueryResult . updatedAt
236243 status = previousQueryResult . status
244+ isPreviousData = true
237245 }
238246
239247 let isStale = false
@@ -261,10 +269,11 @@ export class QueryObserver<TResult, TError> {
261269 failureCount : state . failureCount ,
262270 fetchMore : this . fetchMore ,
263271 isFetched : state . isFetched ,
272+ isFetchedAfterMount : state . fetchedCount > this . initialFetchedCount ,
264273 isFetching : state . isFetching ,
265274 isFetchingMore : state . isFetchingMore ,
275+ isPreviousData,
266276 isStale,
267- query : currentQuery ,
268277 refetch : this . refetch ,
269278 updatedAt,
270279 }
@@ -288,6 +297,7 @@ export class QueryObserver<TResult, TError> {
288297
289298 this . previousQueryResult = this . currentResult
290299 this . currentQuery = newQuery
300+ this . initialFetchedCount = newQuery . state . fetchedCount
291301 this . updateResult ( )
292302
293303 if ( this . started ) {
0 commit comments