@@ -15,13 +15,15 @@ export class QueryObserver<TResult, TError> {
15
15
private currentResult ! : QueryResult < TResult , TError >
16
16
private previousQueryResult ?: QueryResult < TResult , TError >
17
17
private updateListener ?: UpdateListener < TResult , TError >
18
+ private initialFetchedCount : number
18
19
private staleTimeoutId ?: number
19
20
private refetchIntervalId ?: number
20
21
private started ?: boolean
21
22
22
23
constructor ( config : QueryObserverConfig < TResult , TError > ) {
23
24
this . config = config
24
25
this . queryCache = config . queryCache !
26
+ this . initialFetchedCount = 0
25
27
26
28
// Bind exposed methods
27
29
this . clear = this . clear . bind ( this )
@@ -100,6 +102,10 @@ export class QueryObserver<TResult, TError> {
100
102
return this . currentResult . isStale
101
103
}
102
104
105
+ getCurrentQuery ( ) : Query < TResult , TError > {
106
+ return this . currentQuery
107
+ }
108
+
103
109
getCurrentResult ( ) : QueryResult < TResult , TError > {
104
110
return this . currentResult
105
111
}
@@ -224,16 +230,18 @@ export class QueryObserver<TResult, TError> {
224
230
const { currentQuery, currentResult, previousQueryResult, config } = this
225
231
const { state } = currentQuery
226
232
let { data, status, updatedAt } = state
233
+ let isPreviousData = false
227
234
228
235
// Keep previous data if needed
229
236
if (
230
237
config . keepPreviousData &&
231
- state . isLoading &&
238
+ ( state . isIdle || state . isLoading ) &&
232
239
previousQueryResult ?. isSuccess
233
240
) {
234
241
data = previousQueryResult . data
235
242
updatedAt = previousQueryResult . updatedAt
236
243
status = previousQueryResult . status
244
+ isPreviousData = true
237
245
}
238
246
239
247
let isStale = false
@@ -261,10 +269,11 @@ export class QueryObserver<TResult, TError> {
261
269
failureCount : state . failureCount ,
262
270
fetchMore : this . fetchMore ,
263
271
isFetched : state . isFetched ,
272
+ isFetchedAfterMount : state . fetchedCount > this . initialFetchedCount ,
264
273
isFetching : state . isFetching ,
265
274
isFetchingMore : state . isFetchingMore ,
275
+ isPreviousData,
266
276
isStale,
267
- query : currentQuery ,
268
277
refetch : this . refetch ,
269
278
updatedAt,
270
279
}
@@ -288,6 +297,7 @@ export class QueryObserver<TResult, TError> {
288
297
289
298
this . previousQueryResult = this . currentResult
290
299
this . currentQuery = newQuery
300
+ this . initialFetchedCount = newQuery . state . fetchedCount
291
301
this . updateResult ( )
292
302
293
303
if ( this . started ) {
0 commit comments