Skip to content

Commit abe3c05

Browse files
authored
fix(sendbox): 发送消息时立即清空输入框避免竞态覆盖 (#1031)
SendBox 在 onSend() 的 .then() 回调中才执行 setInput(''), 由于 onSend 是异步操作,用户可能在等待期间已输入新内容, 异步回调会将新输入覆盖为空字符串。 将 setInput('') 和 clearDomSnippets() 移到 onSend() 调用之前 同步执行,与各后端 SendBox 的处理方式保持一致。 关联 #961 Co-authored-by: cdxiaodong <cdxiaodong@users.noreply.github.com>
1 parent 292d30b commit abe3c05

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/renderer/components/sendbox.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,12 @@ const SendBox: React.FC<{
242242
finalMessage = input + snippetsHtml;
243243
}
244244

245+
// 立即清空输入框,避免异步 onSend 完成后覆盖用户新输入
246+
// Clear input immediately to prevent async onSend completion from overwriting new user input
247+
setInput('');
248+
clearDomSnippets();
249+
245250
onSend(finalMessage)
246-
.then(() => {
247-
setInput('');
248-
clearDomSnippets(); // 发送后清除 DOM 片段 / Clear DOM snippets after sending
249-
})
250251
.catch(() => {})
251252
.finally(() => {
252253
setIsLoading(false);

0 commit comments

Comments
 (0)