Просмотр исходного кода

Add cleanup effect to clear timer reference in useEditorAssistant

Shun Miyazawa 10 месяцев назад
Родитель
Сommit
d55a671d8e
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      apps/app/src/features/openai/client/services/editor-assistant.tsx

+ 11 - 0
apps/app/src/features/openai/client/services/editor-assistant.tsx

@@ -252,6 +252,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
     lineRef.current = selectedTextFirstLineNumber;
   }, []);
 
+
   // Effects
   useTextSelectionEffect(codeMirrorEditor, selectTextHandler);
 
@@ -302,6 +303,16 @@ export const useEditorAssistant: UseEditorAssistant = () => {
     }
   }, [detectedDiff]);
 
+  useEffect(() => {
+    return () => {
+      if (timerRef.current != null) {
+        clearTimeout(timerRef.current);
+        timerRef.current = null;
+      }
+    };
+  }, []);
+
+
   // Views
   const headerIcon = useMemo(() => {
     return <span className="material-symbols-outlined growi-ai-chat-icon me-3 fs-4">support_agent</span>;