From a961fb8f75a460e1392f4646e379c1917cdf1357 Mon Sep 17 00:00:00 2001 From: Dipanshu Rawat Date: Fri, 20 Feb 2026 01:54:24 +0530 Subject: [PATCH] fix(frontend): fix event listener memory leak in useIsDisabled hook (#5027) fix: optimize event listener management in useIsDisabled hook --- .../ChatContainer/PromptInput/index.jsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx index 6c4998a5..ffa71f72 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx @@ -360,20 +360,15 @@ function useIsDisabled() { */ useEffect(() => { if (!window) return; - window.addEventListener(ATTACHMENTS_PROCESSING_EVENT, () => - setIsDisabled(true) - ); - window.addEventListener(ATTACHMENTS_PROCESSED_EVENT, () => - setIsDisabled(false) - ); + const onProcessing = () => setIsDisabled(true); + const onProcessed = () => setIsDisabled(false); + + window.addEventListener(ATTACHMENTS_PROCESSING_EVENT, onProcessing); + window.addEventListener(ATTACHMENTS_PROCESSED_EVENT, onProcessed); return () => { - window?.removeEventListener(ATTACHMENTS_PROCESSING_EVENT, () => - setIsDisabled(true) - ); - window?.removeEventListener(ATTACHMENTS_PROCESSED_EVENT, () => - setIsDisabled(false) - ); + window.removeEventListener(ATTACHMENTS_PROCESSING_EVENT, onProcessing); + window.removeEventListener(ATTACHMENTS_PROCESSED_EVENT, onProcessed); }; }, []);