Skip to content

Commit 15005d8

Browse files
fix(auth): implement proper debounce ref for forgot password requests (calcom#28490)
* fix(auth): implement proper debounce ref for forgot password requests * Add cleanup for debounced submit function Cancel debounced function on component unmount. --------- Co-authored-by: javidan <javababayev@gmail.com> Co-authored-by: Sahitya Chandra <sahityajb@gmail.com>
1 parent 87fb2ab commit 15005d8

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

apps/web/modules/auth/forgot-password/forgot-password-view.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@ export default function ForgotPassword(props: PageProps) {
5454
}
5555
};
5656

57-
const debouncedHandleSubmitPasswordRequest = debounce(submitForgotPasswordRequest, 250);
57+
const submitRef = React.useRef(submitForgotPasswordRequest);
58+
submitRef.current = submitForgotPasswordRequest;
5859

59-
const handleSubmit = async (e: SyntheticEvent) => {
60+
const debouncedHandleSubmitPasswordRequest = React.useRef(
61+
debounce((args: { email: string }) => submitRef.current(args), 250)
62+
).current;
63+
64+
React.useEffect(() => {
65+
return () => debouncedHandleSubmitPasswordRequest.cancel();
66+
}, []);
67+
68+
const handleSubmit = (e: SyntheticEvent) => {
6069
e.preventDefault();
6170

6271
if (!email) {
@@ -71,7 +80,7 @@ export default function ForgotPassword(props: PageProps) {
7180
setError(null);
7281
setSuccess(false);
7382

74-
await debouncedHandleSubmitPasswordRequest({ email });
83+
debouncedHandleSubmitPasswordRequest({ email });
7584
};
7685

7786
const Success = () => {

0 commit comments

Comments
 (0)