fix: typing in ChatInput no longer causes unnecessary rerenders#136
Merged
fix: typing in ChatInput no longer causes unnecessary rerenders#136
Conversation
✅ Deploy Preview for mcp-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
09fd43f to
44aad8d
Compare
This update refactors the Chat component by streamlining the useChat hook and removing unnecessary state management for input handling. The ChatInput component has been enhanced to handle message submission more effectively, including resetting the textarea after submission. Additionally, a new test suite for the ChatInput component has been added, covering rendering, message submission, and input behavior, ensuring better reliability and maintainability of the chat functionality.
44aad8d to
c916316
Compare
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.
This PR fixes a major performance issue in the chat UI. Previously, typing in the chat prompt input triggered a rerender of the entire chat message list—, including all message rows on every keystroke.
With a test harness of 1,000 messages and CPU throttled to 4x CPU slowdown, this caused severe UI lag (typing a short phrase could take over 10 seconds to appear).
What Changed:
Chatcomponent and the message list only rerender on new messages, not on input changes.Impact (with 1,000 messages, 4x CPU slowdown):
"this is me typing"took over 10 seconds to appearResult:
Closes #128
Note: As a good follow up, implementing #118 will also improve performance.
Screenshots and Videos
Here is the fix in action with 1000 fake bot messages injected and CPU throttling set to 4x slowdown.
Before
CleanShot.2025-07-13.at.09.02.11.mp4
After
CleanShot.2025-07-13.at.09.03.13.mp4