Skip to content

Commit 1bd1ba4

Browse files
committed
fix: use-request polling error
1 parent 6fb4b90 commit 1bd1ba4

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

packages/hooks/src/useRequest/plugins/usePollingPlugin.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { unref, ref, watchEffect } from "vue";
2-
import type { UseRequestPlugin, Interval } from "../types";
2+
import type { UseRequestPlugin, Timeout } from "../types";
33
import isDocumentVisible from "../utils/isDocumentVisible";
44
import subscribeReVisible from "../utils/subscribeReVisible";
55

66
const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
77
fetchInstance,
88
{ pollingInterval, pollingWhenHidden = true, pollingErrorRetryCount = -1 }
99
) => {
10-
const timerRef = ref<Interval>();
10+
let timeouter:Timeout
1111
const unsubscribeRef = ref<() => void>();
1212
const countRef = ref<number>(0);
1313

1414

1515

1616
const stopPolling = () => {
17-
if (timerRef.value) {
18-
clearInterval(timerRef.value);
17+
if (timeouter) {
18+
clearTimeout(timeouter);
1919
}
2020
unsubscribeRef.value?.();
2121
};
@@ -47,7 +47,7 @@ const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
4747
// When an error occurs, the request is not repeated after pollingErrorRetryCount retries
4848
(pollingErrorRetryCount !== -1 && countRef.value <= pollingErrorRetryCount)
4949
) {
50-
timerRef.value = setTimeout(() => {
50+
timeouter = setTimeout(() => {
5151
// if pollingWhenHidden = false && document is hidden, then stop polling and subscribe revisible
5252
if (!pollingWhenHidden && !isDocumentVisible()) {
5353
unsubscribeRef.value = subscribeReVisible(() => {
@@ -60,15 +60,6 @@ const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
6060
} else {
6161
countRef.value = 0;
6262
}
63-
// if (!pollingWhenHidden && !isDocumentVisible()) {
64-
// unsubscribeRef.value = subscribeReVisible(() => {
65-
// fetchInstance.refresh();
66-
// });
67-
// return;
68-
// }
69-
// timerRef.value = setInterval(() => {
70-
// fetchInstance.refresh();
71-
// },unref(pollingInterval));
7263
},
7364
onCancel: () => {
7465
stopPolling();

0 commit comments

Comments
 (0)