You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Performance: Stop unnecessary Sidebar re-renders during chat responses
I noticed the Sidebar was re-rendering on every single text chunk from the LLM. This was making the UI feel a bit sluggish and was spamming the console, which made debugging a pain.
A cascade of unnecessary re-renders occurred because parent components were creating 'new' functions for props like onClose and clearChat on every render.
Here's how I approached the issue:
1. Added React.memo to Sidebar.tsx, enabling it to ignore prop changes that aren't actually different.
2. Stabilized the parents Layout.tsx and Chat\Header.tsx by wrapping the functions being passed down ('onClose', etc.) in 'useCallback'; stopping them from being treated as 'new' on every render.
3. Updated the custom hooks, useMessage and useMessageOption, wrapping all of their returned functions in useCallback or useMemo; ensuring they too provide stable/consistent functions to any components that use them.
After these changes the Sidebar should only update when it actually needs to, making the app feel a bit faster and the console much cleaner.
0 commit comments