fix(web): stop chat composer lag on long chats#196
Open
alex-fedotyev wants to merge 1 commit into
Open
Conversation
Typing in the composer stalled on long chats: dozens of keystrokes would surface seconds later. Two things compounded: - Every keystroke wrote the draft into the global store (setDraft), and ChatPage subscribes to the whole store, so each character re-rendered ChatPage. - MessageList was not memoized, so it re-rendered the entire message list on every ChatPage render. Memoize MessageList (all its props are stable store slices, unchanged while typing) and debounce the draft write (400ms, flushed on blur and on send). The composer stays responsive and drafts still persist across session switches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Typing in the chat composer lags badly on long chats: dozens of keystrokes surface seconds later. This fixes it with two small, localized changes.
Root cause
The draft-persistence feature writes the composer draft into the global store on every keystroke (
setDraftinChatInput).ChatPagesubscribes to the whole store with a no-selectoruseChatStore(), andMessageListis not memoized, so every keystroke re-renders the entire message list. On a short chat it is invisible; on a long one each render is expensive enough that input visibly stalls.Fix
MessageList. Its props (messages,streamingBlocks,isStreaming) are stable store slices that do not change while typing, so the list no longer re-renders when unrelated state (the draft) updates.setDraft(400ms), flushed on blur and on send, and cancelled on send. The local textarea state still updates instantly, so the composer stays responsive; drafts still persist across session switches.Test plan
npm run buildpasses (tsc + vite).Performance only, no visual change.
[ui-check: allow]