fix: not updating queryFn on create query's old query and checking stale status after updating queryFn instead of storing the status before

This commit is contained in:
Kingkor Roy Tirtho
2023-02-16 12:48:19 +06:00
parent 091491966f
commit a85434a4db
2 changed files with 6 additions and 1 deletions
@@ -35,6 +35,7 @@ class QueryClient {
),
)
.cast<DataType, ErrorType, KeyType>();
query.updateQueryFn(queryFn);
cache.addQuery(query);
return query;
}
+5 -1
View File
@@ -153,8 +153,12 @@ class Query<DataType, ErrorType, KeyType>
}
void updateQueryFn(QueryFn<DataType> queryFn) {
if (state.queryFn == queryFn) return;
// updatedAt is updated with copyWith so storing it
// here to check if the query is stale later
final stale = state.isStale;
state = state.copyWith(queryFn: queryFn);
if (state.isStale || refreshConfig.refreshOnQueryFnChange) {
if (stale || refreshConfig.refreshOnQueryFnChange) {
refresh();
}
}