Skip to content

Commit

Permalink
fix(vue-query): ensure that invalidateQueries trigger queryFn wit…
Browse files Browse the repository at this point in the history
…h updated ref values
  • Loading branch information
DamianOsipiuk committed Dec 19, 2023
1 parent 7a61733 commit 57412d0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/vue-query/src/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,14 @@ export class QueryClient extends QC {
filters: MaybeRefDeep<InvalidateQueryFilters> = {},
options: MaybeRefDeep<InvalidateOptions> = {},
): Promise<void> {
return super.invalidateQueries(
cloneDeepUnref(filters),
cloneDeepUnref(options),
)
// (dosipiuk): We need to delay `invalidate` execution to next macro task for all reactive values to be updated
// This ensures that `context` in `queryFn` while invalidating after mutation has correct value.
return new Promise((resolve) => {
setTimeout(async () => {
await super.invalidateQueries(cloneDeepUnref(filters), cloneDeepUnref(options))
resolve()
}, 0)
})
}

refetchQueries(
Expand Down

0 comments on commit 57412d0

Please sign in to comment.