From 25d27d88b8a183200932243cfd0ebf38c7cc0803 Mon Sep 17 00:00:00 2001 From: Aleksandr Semenov Date: Tue, 23 May 2023 22:16:31 +0400 Subject: [PATCH 1/2] fix(useIsMutating): fix vue warning onScopeDispose() is called when there is no active effect scope to be associated with --- packages/vue-query/src/useMutationState.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/vue-query/src/useMutationState.ts b/packages/vue-query/src/useMutationState.ts index 4a8c6f2ad5..e9ba1490cf 100644 --- a/packages/vue-query/src/useMutationState.ts +++ b/packages/vue-query/src/useMutationState.ts @@ -24,9 +24,8 @@ export function useIsMutating( status: 'pending' as const, })) - const length = computed( - () => useMutationState({ filters: unreffedFilters }, client).value.length, - ) + const mutationState = useMutationState({ filters: unreffedFilters }, client) + const length = computed(() => mutationState.value.length) return length } From 9ba307503ec6956627b63f86111bb1644ab2c9af Mon Sep 17 00:00:00 2001 From: Aleksandr Semenov Date: Tue, 23 May 2023 23:47:29 +0400 Subject: [PATCH 2/2] fix(useMutationState): fix test useMutationState should properly update filters --- packages/vue-query/src/useMutationState.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vue-query/src/useMutationState.ts b/packages/vue-query/src/useMutationState.ts index e9ba1490cf..addf34685d 100644 --- a/packages/vue-query/src/useMutationState.ts +++ b/packages/vue-query/src/useMutationState.ts @@ -1,4 +1,4 @@ -import { onScopeDispose, readonly, computed, ref } from 'vue-demi' +import { onScopeDispose, readonly, computed, ref, watch } from 'vue-demi' import type { Ref, DeepReadonly } from 'vue-demi' import type { MutationFilters as MF, @@ -57,6 +57,7 @@ export function useMutationState( options: MutationStateOptions = {}, queryClient?: QueryClient, ): DeepReadonly>> { + const filters = computed(() => cloneDeepUnref(options.filters)) const mutationCache = (queryClient || useQueryClient()).getMutationCache() const state = ref(getResult(mutationCache, options)) as Ref const unsubscribe = mutationCache.subscribe(() => { @@ -64,6 +65,14 @@ export function useMutationState( state.value = result }) + watch( + filters, + () => { + state.value = getResult(mutationCache, options) + }, + { deep: true }, + ) + onScopeDispose(() => { unsubscribe() })