From 82f24bf08f6e68c70b1701c69ee3f29ce0758bb6 Mon Sep 17 00:00:00 2001 From: Henry Park Date: Sun, 22 Feb 2026 00:19:18 -0800 Subject: [PATCH] fix: block send until thread is selected (#306) * fix: block send until thread is selected Prevents messages from ending up in orphan threads when user sends while currentThreadId is null during page load. Co-Authored-By: Claude Opus 4.6 (1M context) * fix: guard enableChatInput against null thread + add user feedback Prevents SSE events from re-enabling input before a thread is selected. Adds status message when user tries to send without a thread. Co-Authored-By: Claude Opus 4.6 (1M context) --------- Co-authored-by: Claude Opus 4.6 (1M context) --- src/channels/web/static/app.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/channels/web/static/app.js b/src/channels/web/static/app.js index fd5f9441..412808b4 100644 --- a/src/channels/web/static/app.js +++ b/src/channels/web/static/app.js @@ -241,6 +241,11 @@ function isCurrentThread(threadId) { function sendMessage() { const input = document.getElementById('chat-input'); const sendBtn = document.getElementById('send-btn'); + if (!currentThreadId) { + console.warn('sendMessage: no thread selected, ignoring'); + setStatus('Waiting for thread to load...'); + return; + } const content = input.value.trim(); if (!content) return; @@ -263,6 +268,8 @@ function sendMessage() { } function enableChatInput() { + // Don't re-enable until a thread is selected (prevents orphan messages) + if (!currentThreadId) return; const input = document.getElementById('chat-input'); const sendBtn = document.getElementById('send-btn'); sendBtn.disabled = false; @@ -740,6 +747,11 @@ function loadThreads() { if (!currentThreadId && assistantThreadId) { switchToAssistant(); } + + // Enable chat input once a thread is available + if (currentThreadId) { + enableChatInput(); + } }).catch(() => {}); } @@ -788,6 +800,10 @@ chatInput.addEventListener('keydown', (e) => { }); chatInput.addEventListener('input', () => autoResizeTextarea(chatInput)); +// Disable send until a thread is selected (loadThreads will enable it) +chatInput.disabled = true; +document.getElementById('send-btn').disabled = true; + // Infinite scroll: load older messages when scrolled near the top document.getElementById('chat-messages').addEventListener('scroll', function () { if (this.scrollTop < 100 && hasMore && !loadingOlder) {