Relates to: PR #441 ("add error tracking and retry methods to query collection utils")
Scope: DX / reliability / precision
Breaking changes: None proposed
Summary#
QueryCollection.utils.refetch() currently uses only queryKey without exact: true, which can cause unintended cascade refetches of queries with shared key prefixes. This issue proposes making refetch target only the intended query.
Current Behavior#
const refetch: RefetchFn = (opts) => {
return queryClient.refetchQueries(
{
queryKey: queryKey,
},
{
throwOnError: opts?.throwOnError,
}
)
}
Problem: Calling refetch() on a collection with key ['todos', 1] also refetches ['todos'] and ['todos', 2].
Proposed Solution#
const refetch: RefetchFn = (opts) => {
return queryClient.refetchQueries(
{
queryKey,
exact: true,
type: 'active',
},
{
throwOnError: opts?.throwOnError,
}
)
}
Acceptance Criteria#
Open Question#
Should type: 'active' be the default, or should we allow cold refetch by default and document it?