diff --git a/surfsense_web/components/assistant-ui/thread.tsx b/surfsense_web/components/assistant-ui/thread.tsx index c8f00d02e..047ac25d8 100644 --- a/surfsense_web/components/assistant-ui/thread.tsx +++ b/surfsense_web/components/assistant-ui/thread.tsx @@ -253,6 +253,7 @@ const Composer: FC = () => { const editorRef = useRef(null); const editorContainerRef = useRef(null); const uploadInputRef = useRef(null); + const isFileDialogOpenRef = useRef(false); const documentPickerRef = useRef(null); const { search_space_id, chat_id } = useParams(); const setMentionedDocumentIds = useSetAtom(mentionedDocumentIdsAtom); @@ -516,11 +517,18 @@ const Composer: FC = () => { ); const handleUploadClick = useCallback(() => { + if (isFileDialogOpenRef.current) return; + isFileDialogOpenRef.current = true; uploadInputRef.current?.click(); + // Reset after a delay to handle cancellation (which doesn't fire the change event). + setTimeout(() => { + isFileDialogOpenRef.current = false; + }, 1000); }, []); const handleUploadInputChange = useCallback( async (event: React.ChangeEvent) => { + isFileDialogOpenRef.current = false; const files = Array.from(event.target.files ?? []); event.target.value = ""; if (files.length === 0 || !search_space_id) return;