fix(messages): capture content in keydown, clear editor instantly, send async
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

Root cause: when typing fast + Enter, previous send hadn't finished
clearing the editor, so new text accumulated. Fix: keydown handler
captures content snapshot and clears Quill SYNCHRONOUSLY, then sends
via sendContent(). No setTimeout, no race condition.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-03-28 17:24:36 +01:00
parent bd591a2aed
commit 762bad0db1

View File

@ -1225,12 +1225,18 @@
},
});
// Enter = send (tiny delay lets Quill commit pending keystrokes)
// Enter = send: capture content immediately, clear editor, send async
state.quill.root.addEventListener('keydown', function (e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
e.stopImmediatePropagation();
setTimeout(function() { Composer.send(); }, 10);
// Snapshot content NOW before Quill processes further keystrokes
var html = state.quill.root.innerHTML;
var text = state.quill.getText().trim();
if (text) {
state.quill.setText(''); // Clear immediately
Composer.sendContent(html, text); // Send with captured content
}
}
}, true);
@ -1271,23 +1277,36 @@
}
},
send: async function () {
if (!state.currentConversationId || !state.quill) return;
if (state._isSending) return;
state._isSending = true;
var html = state.quill.root.innerHTML;
var text = state.quill.getText().trim();
if (!text && !state.attachedFiles.length) {
state._isSending = false;
return;
}
// sendContent: called with pre-captured content (from Enter keydown)
sendContent: async function (html, text) {
if (!state.currentConversationId) return;
var convId = state.currentConversationId;
var savedReplyTo = state.replyToMessage;
var savedFiles = state.attachedFiles.slice();
// Clear state (editor already cleared by keydown handler)
state.attachedFiles = [];
state.replyToMessage = null;
var replyPreview = document.getElementById('replyPreview');
if (replyPreview) replyPreview.style.display = 'none';
Composer.renderAttachments();
return Composer._doSend(convId, html, text, savedReplyTo, savedFiles);
},
// send: called from button click — reads from Quill
send: async function () {
if (!state.currentConversationId || !state.quill) return;
var html = state.quill.root.innerHTML;
var text = state.quill.getText().trim();
if (!text && !state.attachedFiles.length) return;
var convId = state.currentConversationId;
var savedReplyTo = state.replyToMessage;
var savedFiles = state.attachedFiles.slice();
// OPTIMISTIC UI: clear editor and show message IMMEDIATELY
state.quill.setText('');
state.attachedFiles = [];
state.replyToMessage = null;
@ -1295,6 +1314,11 @@
if (replyPreview) replyPreview.style.display = 'none';
Composer.renderAttachments();
return Composer._doSend(convId, html, text, savedReplyTo, savedFiles);
},
_doSend: async function (convId, html, text, savedReplyTo, savedFiles) {
// Show optimistic message in DOM instantly
var tempId = 'temp-' + Date.now();
var optimisticMsg = {