Skip to content

Conversation

nickytonline
Copy link
Member

@nickytonline nickytonline commented Jul 11, 2025

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:

  • The chat prompt input is now uncontrolled (no longer driven by parent state).
  • The parent Chat component and the message list only rerender on new messages, not on input changes.

Impact (with 1,000 messages, 4x CPU slowdown):

Before After
Commit Time ~1,500–1,700ms per keystroke ~16ms per keystroke
Message Renders All 1,000+ messages rerendered on every keystroke Only the input updates
User Experience Typing "this is me typing" took over 10 seconds to appear UI is responsive and fast

Result:

  • Typing performance is now constant and smooth, no matter how many messages are in the chat.
  • This fix protects performance for all users, on all devices.

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

Copy link

netlify bot commented Jul 11, 2025

Deploy Preview for mcp-storybook ready!

Name Link
🔨 Latest commit c916316
🔍 Latest deploy log https://app.netlify.com/projects/mcp-storybook/deploys/6873affdce754c000873e8ee
😎 Deploy Preview https://deploy-preview-136--mcp-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nickytonline nickytonline marked this pull request as ready for review July 11, 2025 20:05
@nickytonline nickytonline force-pushed the unnecessary-renders branch 3 times, most recently from 09fd43f to 44aad8d Compare July 11, 2025 20:14
@nickytonline nickytonline requested review from zeucapua and wasaga July 11, 2025 20:17
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.
@nickytonline nickytonline force-pushed the unnecessary-renders branch from 44aad8d to c916316 Compare July 13, 2025 13:09
@wasaga wasaga merged commit f5a82dd into main Jul 13, 2025
6 checks passed
@wasaga wasaga deleted the unnecessary-renders branch July 13, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typing in ChatInput component should not cause chat messages to rerender
2 participants