diff --git a/apps/comments-ui/src/components/Form.js b/apps/comments-ui/src/components/Form.js index e3be3fb46d..c7ea4716b4 100644 --- a/apps/comments-ui/src/components/Form.js +++ b/apps/comments-ui/src/components/Form.js @@ -88,9 +88,11 @@ const Form = (props) => { return; } + let timer; + // Scroll to view if it's a reply if (props.isReply) { - setTimeout(() => { + timer = setTimeout(() => { if (!formEl.current) { // Unmounted return; @@ -119,6 +121,12 @@ const Form = (props) => { }); }) .run(); + + return () => { + if (timer) { + clearTimeout(timer); + } + }; }, [editor, props]); useEffect(() => { @@ -126,10 +134,6 @@ const Form = (props) => { return; } - // Remove previous events - editor.off('focus'); - editor.off('blur'); - editor.on('focus', () => { onFormFocus(); }); @@ -143,7 +147,13 @@ const Form = (props) => { //props.toggle(); } } - }); + }); + + return () => { + // Remove previous events + editor?.off('focus'); + editor?.off('blur'); + }; }, [editor, props, onFormFocus]); const submitForm = async (event) => {