fix: prevent duplicate messages from SSE/poll race condition
Some checks failed
NordaBiz Tests / Unit & Integration Tests (push) Has been cancelled
NordaBiz Tests / E2E Tests (Playwright) (push) Has been cancelled
NordaBiz Tests / Smoke Tests (Production) (push) Has been cancelled
NordaBiz Tests / Send Failure Notification (push) Has been cancelled
Some checks failed
NordaBiz Tests / Unit & Integration Tests (push) Has been cancelled
NordaBiz Tests / E2E Tests (Playwright) (push) Has been cancelled
NordaBiz Tests / Smoke Tests (Production) (push) Has been cancelled
NordaBiz Tests / Send Failure Notification (push) Has been cancelled
Deduplicate by sender+content match regardless of _optimistic flag, preventing double display when SSE event arrives before POST response. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
441fb524d1
commit
f4af7709b0
@ -775,17 +775,19 @@
|
||||
var convId = msg.conversation_id;
|
||||
if (!state.messages[convId]) state.messages[convId] = [];
|
||||
|
||||
// Dedup: skip if message with this ID already exists
|
||||
// Dedup: by real ID or by matching optimistic message (same sender + content)
|
||||
// Dedup: skip if message already exists by ID, content match, or time proximity
|
||||
var dominated = state.messages[convId].some(function(m) {
|
||||
if (m.id === msg.id) return true;
|
||||
// Match optimistic msg: same sender, same stripped content
|
||||
if (m._optimistic && msg.sender_id && m.sender_id === msg.sender_id) {
|
||||
// Match by same sender + same stripped content (optimistic or SSE/poll race)
|
||||
if (msg.sender_id && m.sender_id === msg.sender_id) {
|
||||
var mc = (m.content || '').replace(/<[^>]*>/g, '').trim();
|
||||
var nc = (msg.content || '').replace(/<[^>]*>/g, '').trim();
|
||||
if (mc && nc && mc === nc) {
|
||||
m.id = msg.id; // Update to real ID
|
||||
// Update to real ID if this was optimistic
|
||||
if (m._optimistic) {
|
||||
m.id = msg.id;
|
||||
m._optimistic = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user