From 2dc40bfc7c0e5a17355ed19b13253974f930f1fa Mon Sep 17 00:00:00 2001 From: OpenClaw Contributor Date: Mon, 16 Mar 2026 18:43:42 +0000 Subject: [PATCH] Address review: module-level limit, remove rAF to fix race - Move CHAT_HISTORY_REQUEST_LIMIT to module scope (align with views/chat.ts). - Apply chatMessages synchronously; drop requestAnimationFrame to avoid overwriting later mutations (e.g. user message or second load). Made-with: Cursor --- ui/src/ui/controllers/chat.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/ui/src/ui/controllers/chat.ts b/ui/src/ui/controllers/chat.ts index 1536a1114a0..138b83d3b81 100644 --- a/ui/src/ui/controllers/chat.ts +++ b/ui/src/ui/controllers/chat.ts @@ -7,6 +7,9 @@ import { generateUUID } from "../uuid.ts"; const SILENT_REPLY_PATTERN = /^\s*NO_REPLY\s*$/; +/** Limit chat.history request to avoid huge payloads and main-thread freeze (see CHAT_HISTORY_RENDER_LIMIT in views/chat.ts). */ +const CHAT_HISTORY_REQUEST_LIMIT = 25; + function isSilentReplyStream(text: string): boolean { return SILENT_REPLY_PATTERN.test(text); } @@ -71,9 +74,6 @@ export async function loadChatHistory(state: ChatState) { state.chatLoading = true; state.lastError = null; try { - // Request a small batch to avoid huge payloads and main-thread freeze when - // parsing JSON and rendering many markdown messages (browser "tab unresponsive"). - const CHAT_HISTORY_REQUEST_LIMIT = 25; const res = await state.client.request<{ messages?: Array; thinkingLevel?: string }>( "chat.history", { @@ -87,11 +87,7 @@ export async function loadChatHistory(state: ChatState) { maybeResetToolStream(state); state.chatStream = null; state.chatStreamStartedAt = null; - // Defer applying messages so the UI can paint "Loading chat..." before the heavy render. - state.chatLoading = false; - requestAnimationFrame(() => { - state.chatMessages = filtered; - }); + state.chatMessages = filtered; } catch (err) { state.lastError = String(err); } finally {