mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-26 21:39:43 +02:00
fix(chat): capture mention chips at submit so they aren't dropped
The composer cleared the live mention atom synchronously on send (via the editor reset), which raced the async onNew handler that read it — dropping every @-mention (docs, folders, connectors, and the new chat references) from the request. handleSubmit now snapshots the chips before clearing, and onNew consumes that snapshot (falling back to the live atom for the send-button path), derives the payload via deriveMentionedPayload, and sends mentioned_thread_ids.
This commit is contained in:
parent
1d5c364e1d
commit
2d1ccb468a
2 changed files with 67 additions and 29 deletions
|
|
@ -38,6 +38,7 @@ import { currentThreadAtom } from "@/atoms/chat/current-thread.atom";
|
|||
import {
|
||||
type MentionedDocumentInfo,
|
||||
mentionedDocumentsAtom,
|
||||
submittedMentionsAtom,
|
||||
} from "@/atoms/chat/mentioned-documents.atom";
|
||||
import { pendingUserImageDataUrlsAtom } from "@/atoms/chat/pending-user-images.atom";
|
||||
import {
|
||||
|
|
@ -446,6 +447,7 @@ const ClipboardChip: FC<{ text: string; onDismiss: () => void }> = ({ text, onDi
|
|||
|
||||
const Composer: FC = () => {
|
||||
const [mentionedDocuments, setMentionedDocuments] = useAtom(mentionedDocumentsAtom);
|
||||
const setSubmittedMentions = useSetAtom(submittedMentionsAtom);
|
||||
const [showDocumentPopover, setShowDocumentPopover] = useState(false);
|
||||
const [showPromptPicker, setShowPromptPicker] = useState(false);
|
||||
const [mentionQuery, setMentionQuery] = useState("");
|
||||
|
|
@ -575,6 +577,13 @@ const Composer: FC = () => {
|
|||
kind: "folder",
|
||||
};
|
||||
}
|
||||
if (d.kind === "thread") {
|
||||
return {
|
||||
id: d.id,
|
||||
title: d.title,
|
||||
kind: "thread",
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: d.id,
|
||||
title: d.title,
|
||||
|
|
@ -770,6 +779,10 @@ const Composer: FC = () => {
|
|||
setClipboardInitialText(undefined);
|
||||
}
|
||||
|
||||
// Capture chips before the reset below clears the live atom, so
|
||||
// the async ``onNew`` still sees them.
|
||||
setSubmittedMentions(mentionedDocuments);
|
||||
|
||||
aui.composer().send();
|
||||
editorRef.current?.clear();
|
||||
setIsComposerInputEmpty(true);
|
||||
|
|
@ -781,6 +794,8 @@ const Composer: FC = () => {
|
|||
isBlockedByOtherUser,
|
||||
clipboardInitialText,
|
||||
aui,
|
||||
mentionedDocuments,
|
||||
setSubmittedMentions,
|
||||
setMentionedDocuments,
|
||||
]);
|
||||
|
||||
|
|
@ -788,7 +803,7 @@ const Composer: FC = () => {
|
|||
(
|
||||
docId: number,
|
||||
docType?: string,
|
||||
kind?: "doc" | "folder" | "connector",
|
||||
kind?: "doc" | "folder" | "connector" | "thread",
|
||||
connectorType?: string
|
||||
) => {
|
||||
setMentionedDocuments((prev) => {
|
||||
|
|
@ -876,6 +891,8 @@ const Composer: FC = () => {
|
|||
<DocumentMentionPicker
|
||||
ref={documentPickerRef}
|
||||
searchSpaceId={Number(search_space_id)}
|
||||
enableChatMentions
|
||||
currentChatId={threadId}
|
||||
onSelectionChange={handleDocumentsMention}
|
||||
onDone={() => {
|
||||
setShowDocumentPopover(false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue