Skip to content

Commit ebea61e

Browse files
author
Guillaume Chau
committed
fix: useXXXLoading() oldValue being undefined and triggering watcher
1 parent 3921587 commit ebea61e

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

packages/vue-apollo-composable/src/util/loadingTracking.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,35 @@ export function getCurrentTracking () {
6161
export function trackQuery (loading: Ref<boolean>) {
6262
const { appTracking, tracking } = getCurrentTracking()
6363

64-
watch(loading, value => {
65-
const mod = value ? 1 : -1
66-
tracking.queries.value += mod
67-
appTracking.queries.value += mod
64+
watch(loading, (value, oldValue) => {
65+
if (oldValue != null) {
66+
const mod = value ? 1 : -1
67+
tracking.queries.value += mod
68+
appTracking.queries.value += mod
69+
}
6870
})
6971
}
7072

7173
export function trackMutation (loading: Ref<boolean>) {
7274
const { appTracking, tracking } = getCurrentTracking()
7375

74-
watch(loading, value => {
75-
const mod = value ? 1 : -1
76-
tracking.mutations.value += mod
77-
appTracking.mutations.value += mod
76+
watch(loading, (value, oldValue) => {
77+
if (oldValue != null) {
78+
const mod = value ? 1 : -1
79+
tracking.mutations.value += mod
80+
appTracking.mutations.value += mod
81+
}
7882
})
7983
}
8084

8185
export function trackSubscription (loading: Ref<boolean>) {
8286
const { appTracking, tracking } = getCurrentTracking()
8387

84-
watch(loading, value => {
85-
const mod = value ? 1 : -1
86-
tracking.subscriptions.value += mod
87-
appTracking.subscriptions.value += mod
88+
watch(loading, (value, oldValue) => {
89+
if (oldValue != null) {
90+
const mod = value ? 1 : -1
91+
tracking.subscriptions.value += mod
92+
appTracking.subscriptions.value += mod
93+
}
8894
})
8995
}

0 commit comments

Comments
 (0)