fix: error message persists after successful send + improve error colors
Browse filesBug: showError() appended the error element to #chat-messages with no
reference, so it was never removed. A successful subsequent send left
the old error visible at the top of the conversation.
Fix:
- Track the error element as this._errorEl in Chat
- Add clearError() to remove it; call it at the start of each new
send in app.js (right before the user bubble is rendered)
- Also clear _errorEl in clear() to avoid stale refs after /clean
Styling: the previous error used dark-mode-only Tailwind classes
(bg-red-950/40, text-red-400) which produced a muted brownish
background with near-invisible text in light mode. Replaced with
proper dark:-prefixed variants:
light: bg-red-50 / border-red-200 / text-red-700
dark: bg-red-950/40 / border-red-900/40 / text-red-400
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- src/components/app.js +1 -0
- src/components/chat.js +12 -2
|
@@ -258,6 +258,7 @@ export class App {
|
|
| 258 |
// Add to store & render — wrapped so any localStorage/DOM error is caught
|
| 259 |
let renderOk = false;
|
| 260 |
try {
|
|
|
|
| 261 |
store.addMessage(convId, userMessage);
|
| 262 |
this.chat.appendUserMessage(userMessage);
|
| 263 |
this._updateContextInfo();
|
|
|
|
| 258 |
// Add to store & render — wrapped so any localStorage/DOM error is caught
|
| 259 |
let renderOk = false;
|
| 260 |
try {
|
| 261 |
+
this.chat.clearError();
|
| 262 |
store.addMessage(convId, userMessage);
|
| 263 |
this.chat.appendUserMessage(userMessage);
|
| 264 |
this._updateContextInfo();
|
|
@@ -45,6 +45,7 @@ export class Chat {
|
|
| 45 |
this._offset = 0; // how many messages we've hidden
|
| 46 |
this._streamingEl = null;
|
| 47 |
this._typingEl = null;
|
|
|
|
| 48 |
}
|
| 49 |
|
| 50 |
render() {
|
|
@@ -282,7 +283,7 @@ export class Chat {
|
|
| 282 |
const container = this.el.querySelector('#chat-messages');
|
| 283 |
this.hideTypingIndicator();
|
| 284 |
if (this._streamingEl) {
|
| 285 |
-
this._streamingEl.innerHTML = `<span class="text-red-400">${escapeHtml(message)}</span>`;
|
| 286 |
this._streamingEl = null;
|
| 287 |
this._streamingText = '';
|
| 288 |
return;
|
|
@@ -290,14 +291,22 @@ export class Chat {
|
|
| 290 |
const errEl = document.createElement('div');
|
| 291 |
errEl.className = 'max-w-4xl mx-auto w-full px-6 mb-4 message-enter';
|
| 292 |
errEl.innerHTML = `
|
| 293 |
-
<div class="bg-red-950/40 border border-red-900/40 rounded-xl px-4 py-3 text-[13px] text-red-400 flex items-center gap-2">
|
| 294 |
${icon('x')} ${escapeHtml(message)}
|
| 295 |
</div>
|
| 296 |
`;
|
|
|
|
| 297 |
container.appendChild(errEl);
|
| 298 |
this._scrollToBottom();
|
| 299 |
}
|
| 300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
showSystemMessage(text) {
|
| 302 |
const container = this.el.querySelector('#chat-messages');
|
| 303 |
if (!container) return;
|
|
@@ -328,6 +337,7 @@ export class Chat {
|
|
| 328 |
this._streamingEl = null;
|
| 329 |
this._streamingText = '';
|
| 330 |
this._typingEl = null;
|
|
|
|
| 331 |
const container = this.el.querySelector('#chat-messages');
|
| 332 |
if (container) container.innerHTML = this._welcomeScreen();
|
| 333 |
}
|
|
|
|
| 45 |
this._offset = 0; // how many messages we've hidden
|
| 46 |
this._streamingEl = null;
|
| 47 |
this._typingEl = null;
|
| 48 |
+
this._errorEl = null;
|
| 49 |
}
|
| 50 |
|
| 51 |
render() {
|
|
|
|
| 283 |
const container = this.el.querySelector('#chat-messages');
|
| 284 |
this.hideTypingIndicator();
|
| 285 |
if (this._streamingEl) {
|
| 286 |
+
this._streamingEl.innerHTML = `<span class="text-red-600 dark:text-red-400">${escapeHtml(message)}</span>`;
|
| 287 |
this._streamingEl = null;
|
| 288 |
this._streamingText = '';
|
| 289 |
return;
|
|
|
|
| 291 |
const errEl = document.createElement('div');
|
| 292 |
errEl.className = 'max-w-4xl mx-auto w-full px-6 mb-4 message-enter';
|
| 293 |
errEl.innerHTML = `
|
| 294 |
+
<div class="bg-red-50 dark:bg-red-950/40 border border-red-200 dark:border-red-900/40 rounded-xl px-4 py-3 text-[13px] text-red-700 dark:text-red-400 flex items-center gap-2">
|
| 295 |
${icon('x')} ${escapeHtml(message)}
|
| 296 |
</div>
|
| 297 |
`;
|
| 298 |
+
this._errorEl = errEl;
|
| 299 |
container.appendChild(errEl);
|
| 300 |
this._scrollToBottom();
|
| 301 |
}
|
| 302 |
|
| 303 |
+
clearError() {
|
| 304 |
+
if (this._errorEl) {
|
| 305 |
+
this._errorEl.remove();
|
| 306 |
+
this._errorEl = null;
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
showSystemMessage(text) {
|
| 311 |
const container = this.el.querySelector('#chat-messages');
|
| 312 |
if (!container) return;
|
|
|
|
| 337 |
this._streamingEl = null;
|
| 338 |
this._streamingText = '';
|
| 339 |
this._typingEl = null;
|
| 340 |
+
this._errorEl = null;
|
| 341 |
const container = this.el.querySelector('#chat-messages');
|
| 342 |
if (container) container.innerHTML = this._welcomeScreen();
|
| 343 |
}
|