From 5975b78c811c1c61d3547c928a91bd862c4114fb Mon Sep 17 00:00:00 2001 From: Michael McQuade Date: Tue, 17 Nov 2026 09:04:50 -0600 Subject: [PATCH] perf(ui): a long transcript keeps only the turns near the view, so reading it back to its start no longer fills a phone's memory The message list drew a long conversation's end and the turns before it as the reader scrolled up, but never let go of a turn once drawn. Reading back to the first turn of a long agent session drew it whole, and a phone's browser closes the tab long before that. The list now keeps a window of whole turns around the view in both directions: - Within two screens of either edge it draws about 100 more parts there. - Turns more than four screens from the view are let go of, above and below, and what the reader is looking at stays where it is. - Once the end has been let go of, new turns, the reply being written and the queue wait below until the reader comes back; the jump control brings them back to the end and follows it. - A turn the reader is editing, selecting text in or reached with the keyboard is kept. - What the reader opened in a turn (a tool's output, a thought, a folded run, a long reply) is open again when the turn is drawn again. Expand-all and a new conversation start afresh. - Turns drawn again appear at once rather than entering as new ones. --- packages/ui/src/ai/components/ChatMessage.tsx | 7 +- .../ai/components/ChatMessageList.stories.tsx | 4 +- .../ui/src/ai/components/ChatMessageList.tsx | 446 ++++++++++++------ .../ChatMessageList.window.test.tsx | 224 ++++++++- .../agent/AgentMessageParts.test.tsx | 47 ++ .../ai/components/agent/AgentMessageParts.tsx | 31 +- packages/ui/src/ai/core/rowMemory.ts | 63 +++ 7 files changed, 638 insertions(+), 184 deletions(-) create mode 100644 packages/ui/src/ai/core/rowMemory.ts diff --git a/packages/ui/src/ai/components/ChatMessage.tsx b/packages/ui/src/ai/components/ChatMessage.tsx index c09b98fa..ac7e708b 100644 --- a/packages/ui/src/ai/components/ChatMessage.tsx +++ b/packages/ui/src/ai/components/ChatMessage.tsx @@ -13,6 +13,7 @@ import { formatDateTime, formatDuration, formatTimeLeft, toDateTime } from '../. import { EditIcon, RetryIcon } from '../../icons' import { useChatModelName } from '../core/ChatProvider' import { type ApprovalAnswerHandler, useChatConfig } from '../core/config' +import { useRemembered } from '../core/rowMemory' import { replyText } from '../core/useKeyboardShortcuts' import type { AttachmentRef, ChatUser, ChatMessage as Message } from '../types' import Markdown from '../ui/Markdown' @@ -167,9 +168,9 @@ function ChatMessage({ const textareaRef = useRef(null) const contentRef = useRef(null) const [collapsible, setCollapsible] = useState(false) - const [expanded, setExpanded] = useState(false) + const [expanded, setExpanded] = useRemembered(message.id, 'expanded', false) // Only without a host handler: a host that passes one shows reasoning itself. - const [reasoningOpen, setReasoningOpen] = useState(false) + const [reasoningOpen, setReasoningOpen] = useRemembered(message.id, 'reasoning', false) // Long finished assistant replies clamp with a fade; streaming replies never // clamp so the tail stays readable while it grows, and the latest reply never @@ -487,7 +488,7 @@ function ChatMessage({ {!isUser && collapsible && !isStreaming && !latest && (