Add AbortController cleanup to async frontend effects
This commit is contained in:
@@ -106,12 +106,14 @@ export function ActivateJailDialog({
|
||||
useEffect(() => {
|
||||
if (!open || !jail) return;
|
||||
|
||||
const controller = new AbortController();
|
||||
setValidating(true);
|
||||
setValidationIssues([]);
|
||||
setValidationWarnings([]);
|
||||
|
||||
onValidate()
|
||||
.then((result) => {
|
||||
if (controller.signal.aborted) return;
|
||||
setValidationIssues(result.issues);
|
||||
})
|
||||
.catch(() => {
|
||||
@@ -119,8 +121,13 @@ export function ActivateJailDialog({
|
||||
// attempt activation and let the server decide.
|
||||
})
|
||||
.finally(() => {
|
||||
if (controller.signal.aborted) return;
|
||||
setValidating(false);
|
||||
});
|
||||
|
||||
return (): void => {
|
||||
controller.abort();
|
||||
};
|
||||
}, [open, jail, onValidate]);
|
||||
|
||||
const handleClose = (): void => {
|
||||
|
||||
Reference in New Issue
Block a user