mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-23 19:49:08 -05:00
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:
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user