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 => {
|
||||
|
||||
@@ -75,25 +75,33 @@ export function ConfFilesTab({
|
||||
const [newContent, setNewContent] = useState("");
|
||||
const [creating, setCreating] = useState(false);
|
||||
|
||||
const loadFiles = useCallback(async () => {
|
||||
const loadFiles = useCallback(async (signal?: AbortSignal) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const resp = await fetchList();
|
||||
if (signal?.aborted) return;
|
||||
setFiles(resp.files);
|
||||
} catch (err: unknown) {
|
||||
if (signal?.aborted) return;
|
||||
setError(
|
||||
err instanceof ApiError
|
||||
? err.message
|
||||
: `Failed to load ${label.toLowerCase()} files.`,
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
if (!signal?.aborted) {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
}, [fetchList, label]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadFiles();
|
||||
const controller = new AbortController();
|
||||
void loadFiles(controller.signal);
|
||||
return (): void => {
|
||||
controller.abort();
|
||||
};
|
||||
}, [loadFiles]);
|
||||
|
||||
const handleAccordionToggle = useCallback(
|
||||
|
||||
Reference in New Issue
Block a user