From 5edb3fa241b981e6a9eeb7fe78cf738056adbf21 Mon Sep 17 00:00:00 2001 From: sravan Date: Wed, 24 Jun 2026 13:39:42 +0530 Subject: [PATCH] fix(chat): dedup sent message in sendMessage too (WS echo can beat the POST response) The server echoes the sender's own message over WS before returning the HTTP response, so onChatMessage could append it before sendMessage's await resolved, then sendMessage appended again -> double. Both append paths now dedup by id. Co-Authored-By: Claude Opus 4.8 --- server/public/home.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/public/home.html b/server/public/home.html index 89fcf71..f53bf29 100644 --- a/server/public/home.html +++ b/server/public/home.html @@ -589,7 +589,7 @@ - +
Loading…
@@ -1433,7 +1433,10 @@ async function sendMessage(){ try{ const m=await postJSON('/api/messages', payload); composeMentions=new Map(); - THREAD.push(m); appendBubble(m); clearReply(); pendingAttach=null; hideAttach(); + // Dedup by id: the server echoes our message over WS (to sync other tabs) and that echo + // can arrive BEFORE this POST resolves, so onChatMessage may have already appended it. + if(!THREAD.some(x=>x.id===m.id)){ THREAD.push(m); appendBubble(m); } + clearReply(); pendingAttach=null; hideAttach(); { const ck=selected.kind+':'+selected.id; if(THREAD_CACHE.has(ck)){ const a=THREAD_CACHE.get(ck); if(!a.some(x=>x.id===m.id)) a.push(m); } } const it=rowFor(selected.kind,selected.id); if(it){ it.last_body=m.body||(m.attachment?'📎 '+(m.attachment.name||'Attachment'):''); it.last_at=m.created_at; it.last_from_me=true; it.unread=0; }