Skip to content

Commit 9883c41

Browse files
committed
fix: isFetched and isFetchedAfterMount should include failed fetches
1 parent 88d089c commit 9883c41

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/core/queryObserver.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class QueryObserver<
5151
private currentResultState?: QueryState<TQueryData, TError>
5252
private previousQueryResult?: QueryObserverResult<TData, TError>
5353
private initialDataUpdateCount: number
54+
private initialErrorUpdateCount: number
5455
private staleTimeoutId?: number
5556
private refetchIntervalId?: number
5657

@@ -63,6 +64,7 @@ export class QueryObserver<
6364
this.client = client
6465
this.options = options
6566
this.initialDataUpdateCount = 0
67+
this.initialErrorUpdateCount = 0
6668
this.bindMethods()
6769
this.setOptions(options)
6870
}
@@ -409,8 +411,10 @@ export class QueryObserver<
409411
error: state.error,
410412
errorUpdatedAt: state.errorUpdateCount,
411413
failureCount: state.fetchFailureCount,
412-
isFetched: state.dataUpdateCount > 0,
413-
isFetchedAfterMount: state.dataUpdateCount > this.initialDataUpdateCount,
414+
isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
415+
isFetchedAfterMount:
416+
state.dataUpdateCount > this.initialDataUpdateCount ||
417+
state.errorUpdateCount > this.initialErrorUpdateCount,
414418
isFetching,
415419
isLoadingError: status === 'error' && state.dataUpdatedAt === 0,
416420
isPlaceholderData,
@@ -489,6 +493,7 @@ export class QueryObserver<
489493
this.previousQueryResult = this.currentResult
490494
this.currentQuery = query
491495
this.initialDataUpdateCount = query.state.dataUpdateCount
496+
this.initialErrorUpdateCount = query.state.errorUpdateCount
492497

493498
const willFetch = prevQuery
494499
? this.willFetchOptionally()

src/react/tests/useQuery.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ describe('useQuery', () => {
250250
errorUpdatedAt: expect.any(Number),
251251
failureCount: 2,
252252
isError: true,
253-
isFetched: false,
254-
isFetchedAfterMount: false,
253+
isFetched: true,
254+
isFetchedAfterMount: true,
255255
isFetching: false,
256256
isIdle: false,
257257
isLoading: false,

0 commit comments

Comments
 (0)