From b3042a02be0c3b3aade4e9d5f3cb5c937ebb3f3e Mon Sep 17 00:00:00 2001 From: mainnebula <51970406+mainnebula@users.noreply.github.com> Date: Mon, 16 Feb 2026 18:12:10 -0500 Subject: [PATCH] fix: prevent file attachment dialog from opening twice Add a ref-based guard to handleUploadClick that prevents the native file picker from being triggered a second time when the browser re-dispatches a click event after the dialog closes. This matches the existing pattern used in document-upload-popup.tsx for the Upload Documents dialog. --- surfsense_web/components/assistant-ui/thread.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) 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;