From fce9942ae0e6fdc9326e285b987723a480a6e52e Mon Sep 17 00:00:00 2001 From: pewdiepie-archdaemon Date: Thu, 11 Jun 2026 22:00:22 +0900 Subject: [PATCH] =?UTF-8?q?Chat:=20fix=20mode-tag=20breakage=20=E2=80=94?= =?UTF-8?q?=20toggleState=20wasn't=20in=20scope=20at=20those=20sites?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous commit read toggleState.mode before it was declared (send-time site near line 632) and outside its closure (assistant finalize site near line 3426). Both threw ReferenceError / TDZ on first send, which crashed the chat send + render pipeline. Read fresh via Storage.loadToggleState() at each site, defaulting to 'chat' on any error. Mode-tag rendering otherwise unchanged. --- static/js/chat.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/static/js/chat.js b/static/js/chat.js index 12df53973..802fedca5 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -630,7 +630,12 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer let _userMsgEl = null; // Capture which mode the user picked at send time so the message // header can show "Chat" or "Agent" next to the timestamp. - const _sendMode = (toggleState.mode || 'chat') === 'agent' ? 'agent' : 'chat'; + // toggleState is declared later in this function — load fresh here. + let _sendMode = 'chat'; + try { + const _ts = Storage.loadToggleState(); + if ((_ts.mode || 'chat') === 'agent') _sendMode = 'agent'; + } catch (_) {} if (!skipBubble) { const _userMeta = { mode: _sendMode }; if (_pendingAttachInfo) _userMeta.attachments = _pendingAttachInfo; @@ -3429,8 +3434,12 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer const model = meta && meta.model; const meta_ = metricsData ? Object.assign({ model }, metricsData) : { model }; // Carry the send-time mode through so the assistant header gets - // the same Chat/Agent tag next to its timestamp. - meta_.mode = (toggleState.mode || 'chat') === 'agent' ? 'agent' : 'chat'; + // the same Chat/Agent tag next to its timestamp. toggleState + // isn't in scope here — read fresh. + try { + const _ts = Storage.loadToggleState(); + meta_.mode = ((_ts.mode || 'chat') === 'agent') ? 'agent' : 'chat'; + } catch (_) {} chatRenderer.addMessage('assistant', roundText, model, meta_); uiModule.scrollHistory(); return true;