From ee0fa336d826fc1bc2d82719bbef76b13aefba53 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 05:17:33 -0700 Subject: [PATCH] fix: guard sidebar drop state (#3661) --- .../sidebar/useSidebarProjectDrop.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/components/sidebar/useSidebarProjectDrop.ts b/src/renderer/src/components/sidebar/useSidebarProjectDrop.ts index 73c97f59ebb..0d0b01ca7a9 100644 --- a/src/renderer/src/components/sidebar/useSidebarProjectDrop.ts +++ b/src/renderer/src/components/sidebar/useSidebarProjectDrop.ts @@ -4,6 +4,7 @@ import { NATIVE_FILE_DROP_TARGET, hasNativeFileDragTypes } from '../../../../shared/native-file-drop' +import { useMountedRef } from '@/hooks/useMountedRef' import { useAppStore } from '@/store' import { getSidebarProjectDropAffordance, @@ -28,6 +29,7 @@ export function useSidebarProjectDrop(): { const [isHandlingDrop, setIsHandlingDrop] = useState(false) const dragDepthRef = useRef(0) const remoteRuntimeActive = isRemoteRuntimeActive(settings) + const mountedRef = useMountedRef() const clearDragState = useCallback(() => { dragDepthRef.current = 0 @@ -64,20 +66,27 @@ export function useSidebarProjectDrop(): { try { await window.api.fs.authorizeExternalPath({ targetPath: pathResolution.path }) const stat = await window.api.fs.stat({ filePath: pathResolution.path }) + if (!mountedRef.current) { + return + } if (!stat.isDirectory) { toast.error('Drop a folder to add it as a project.') return } openModal('add-repo', { droppedLocalPath: pathResolution.path }) } catch (error) { - toast.error('Could not add dropped folder.', { - description: error instanceof Error ? error.message : String(error) - }) + if (mountedRef.current) { + toast.error('Could not add dropped folder.', { + description: error instanceof Error ? error.message : String(error) + }) + } } finally { - setIsHandlingDrop(false) + if (mountedRef.current) { + setIsHandlingDrop(false) + } } }, - [openModal, remoteRuntimeActive] + [mountedRef, openModal, remoteRuntimeActive] ) useEffect(() => {