From 785eeb7fbc8940754e2076408896e979a15067ec Mon Sep 17 00:00:00 2001 From: sravan Date: Fri, 14 Aug 2026 11:50:20 +0530 Subject: [PATCH] #14 draft ROOT CAUSE: openConvo's cancelEdit() wiped the just-opened chat's draft MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reproduced with a real headless browser driving the live app: typing saved the draft and it survived switching chats, but RETURNING to the chat deleted it. Stack trace pinned it exactly: setDraft(REMOVE) <- _restoreDraftAfterEdit <- cancelEdit <- openConvo:3484 <- selectChat openConvo ran `clearReply(); cancelEdit(); hideAttach();` on every open. cancelEdit -> _restoreDraftAfterEdit -> setDraft(selected,'') — and since `selected` is already the chat being opened, it wiped THAT chat's draft (and blanked the composer) BEFORE the draft-restore a few lines later could read it. So the draft never survived reopening — this predated the recent rounds; my _restoreDraftAfterEdit change just made the wipe explicit. Fix: drop cancelEdit() from openConvo (edit state is already reset at the top via editTarget=null/_editSavedDraft='', and the shell was just rebuilt fresh). The edit-cancel button + saveEdit still call cancelEdit normally. Verified with puppeteer: type in chat A -> open B -> back to A -> "hello draft" restored (PASS), no setDraft REMOVE on return. Co-Authored-By: Claude Opus 4.8 --- server/public/home.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/public/home.html b/server/public/home.html index 81e42c7..86e206a 100644 --- a/server/public/home.html +++ b/server/public/home.html @@ -3481,7 +3481,11 @@ async function openConvo(kind,id){ el.ondrop=(e)=>{ const f=e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files[0]; if(f){ e.preventDefault(); el.classList.remove('drag-over'); uploadFile(f); } }; const back=document.getElementById('convoBack'); if(back) back.onclick=showWelcome; const form=document.getElementById('composer'); if(form) form.addEventListener('submit',(e)=>{ e.preventDefault(); sendMessage(); }); - clearReply(); cancelEdit(); hideAttach(); + // #14 ROOT CAUSE: do NOT call cancelEdit() here. It runs _restoreDraftAfterEdit → setDraft(selected,'') which + // WIPED the just-opened chat's draft (and blanked the composer) BEFORE the restore below could read it — the + // draft never survived reopening a chat. Edit state is already reset at the top (editTarget=null, + // _editSavedDraft=''), and the composer/edit bar are fresh from the shell rebuild, so nothing else is needed. + clearReply(); hideAttach(); const ab2=document.getElementById('attachBtn'); const apop=document.getElementById('attachPop'); if(ab2&&apop) ab2.onclick=(e)=>{ e.stopPropagation(); apop.style.display = apop.style.display==='none' ? 'flex' : 'none'; }; // show a composer-anchored menu instead of firing the generic mid-screen OS chooser straight away if(apop) apop.querySelectorAll('.attach-opt').forEach(b=>b.onclick=(e)=>{ e.stopPropagation(); apop.style.display='none'; const src=b.dataset.src; const inp = src==='photo'?document.getElementById('fileInputImg') : src==='camera'?document.getElementById('fileInputCam') : document.getElementById('fileInput'); if(inp) inp.click(); }); // Photos → gallery, Camera → capture, Document → any file