From 7149925539c5bd46c0e15a9b2859f09e9796eb4e Mon Sep 17 00:00:00 2001 From: James Murdza Date: Sun, 1 Sep 2024 21:53:59 -0700 Subject: [PATCH] fix: remove useCallback, fixing null socket issue when reading files --- frontend/components/editor/index.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index 4f6405e..b8d829e 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -491,14 +491,13 @@ export default function CodeEditor({ const fileCache = useRef(new Map()); // Debounced function to get file content - const debouncedGetFile = useCallback( - debounce((tabId, callback) => { - socket?.emit('getFile', tabId, callback); - }, 300), // 300ms debounce delay, adjust as needed - [] - ); + const debouncedGetFile = + (tabId: any, callback: any) => { + socket?.emit('getFile', tabId, callback); + } // 300ms debounce delay, adjust as needed + + const selectFile = (tab: TTab) => { - const selectFile = useCallback((tab: TTab) => { if (tab.id === activeFileId) return; setGenerate((prev) => ({ ...prev, show: false })); @@ -523,7 +522,7 @@ export default function CodeEditor({ setEditorLanguage(processFileType(tab.name)); setActiveFileId(tab.id); - }, [activeFileId, tabs, debouncedGetFile]); + }; // Close tab and remove from tabs const closeTab = (id: string) => {