commit 71c845ecd4913536086899e74dade91f559631f0
parent fb7bb7d7eef4986fca8c0a7d4cf106a82e075e2e
Author: Sebastian <sebasjm@taler-systems.com>
Date: Wed, 22 Jul 2026 16:38:59 -0300
prevent setResult when unmounted
Diffstat:
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git a/packages/taler-auditor-webui/src/hooks/backend.ts b/packages/taler-auditor-webui/src/hooks/backend.ts
@@ -34,6 +34,7 @@ import { useCallback, useEffect, useState } from "preact/hooks";
import { useSWRConfig } from "swr";
import { useBackendContext } from "../context/backend.js";
import { AuditorBackend } from "../declaration.js";
+import { useRef } from "preact/hooks";
export function useMatchMutate(): (
re?: RegExp,
@@ -81,6 +82,7 @@ export function useBackendConfig(): HttpResponse<
data: HttpResponse<Type, RequestError<AuditorBackend.ErrorDetail>>;
timer: number;
};
+ const unloaded = useRef(false);
const [result, setResult] = useState<State>({
data: { loading: true },
timer: 0,
@@ -94,12 +96,18 @@ export function useBackendConfig(): HttpResponse<
function tryConfig(): void {
request<Type>("config")
.then((data) => {
+ if (unloaded.current) {
+ return;
+ }
const timer: any = setTimeout(() => {
tryConfig();
}, CHECK_CONFIG_INTERVAL_OK);
setResult({ data, timer });
})
.catch((error) => {
+ if (unloaded.current) {
+ return;
+ }
const timer: any = setTimeout(() => {
tryConfig();
}, CHECK_CONFIG_INTERVAL_FAIL);
@@ -109,6 +117,10 @@ export function useBackendConfig(): HttpResponse<
}
tryConfig();
+ return () => {
+ unloaded.current = true;
+ clearTimeout(result.timer);
+ };
}, [request]);
return result.data;