fix: clean up setTimeout schedules in contact effects

Two useEffect hooks scheduled `setTimeout` callbacks without returning
a cleanup. If the effect re-ran (or the component unmounted) before the
timeout fired, the callback would still execute against stale state /
unmounted refs. Capture the timeout id and return `() => clearTimeout(id)`.

Flagged by react-doctor as react-doctor/effect-needs-cleanup
(State & Effects, error).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matti Nannt
2026-05-23 14:41:43 +02:00
parent be5beaeed7
commit 6955d7c99f
2 changed files with 4 additions and 2 deletions
@@ -133,7 +133,7 @@ export const EditContactAttributesModal = ({
const errorFieldId = `attribute-key-${firstErrorIndex}`;
const errorElement = document.getElementById(errorFieldId);
if (errorElement) {
setTimeout(() => {
const timeoutId = setTimeout(() => {
errorElement.scrollIntoView({ behavior: "smooth", block: "center" });
// Try to focus the input inside the combobox if it exists
const inputElement = errorElement.querySelector("input") as HTMLInputElement;
@@ -143,6 +143,7 @@ export const EditContactAttributesModal = ({
errorElement.focus();
}
}, 100);
return () => clearTimeout(timeoutId);
}
}
}
@@ -337,9 +337,10 @@ export const UploadContactsCSVButton = ({
useEffect(() => {
if (error && errorContainerRef.current) {
// Small delay to ensure DOM has updated and the alert is visible
setTimeout(() => {
const timeoutId = setTimeout(() => {
errorContainerRef.current?.scrollIntoView({ behavior: "smooth", block: "center" });
}, 100);
return () => clearTimeout(timeoutId);
}
}, [error]);