Skip to content

Commit 280301f

Browse files
author
Guillaume Chau
committed
fix(useQuery): throttle & debounce not being applied initially
1 parent 947ceb1 commit 280301f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/vue-apollo-composable/src/useQuery.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,26 @@ export function useQuery<
236236
}
237237

238238
let debouncedRestart: Function
239+
let isRestartDebounceSetup = false
239240
function updateRestartFn () {
241+
// On server, will be called before currentOptions is initialized
242+
// @TODO investigate
240243
if (!currentOptions) {
241244
debouncedRestart = baseRestart
242-
} else if (currentOptions.value.throttle) {
243-
debouncedRestart = throttle(currentOptions.value.throttle, baseRestart)
244-
} else if (currentOptions.value.debounce) {
245-
debouncedRestart = debounce(currentOptions.value.debounce, baseRestart)
246245
} else {
247-
debouncedRestart = baseRestart
246+
if (currentOptions.value.throttle) {
247+
debouncedRestart = throttle(currentOptions.value.throttle, baseRestart)
248+
} else if (currentOptions.value.debounce) {
249+
debouncedRestart = debounce(currentOptions.value.debounce, baseRestart)
250+
} else {
251+
debouncedRestart = baseRestart
252+
}
253+
isRestartDebounceSetup = true
248254
}
249255
}
250256

251257
function restart () {
252-
if (!debouncedRestart) updateRestartFn()
258+
if (!isRestartDebounceSetup) updateRestartFn()
253259
debouncedRestart()
254260
}
255261

0 commit comments

Comments
 (0)