Description
ThreadListItemComponent in thread-list.tsx renders inside a .map() for every chat thread. When the parent re-renders (e.g., switching active thread, toggling archive filter), all thread rows re-render even if their individual props haven't changed. Wrapping the component in React.memo lets React skip re-rendering rows whose props are referentially equal.
Vercel React Best Practices Rule: rerender-memo (5.5)
File to change
surfsense_web/components/assistant-ui/thread-list.tsx
What to do
- Add
memo to the React import:
import { memo } from "react";
- Convert
ThreadListItemComponent (lines 218-275) from a plain function to a memoized component:
// Before
function ThreadListItemComponent({
thread, isActive, isArchived, onClick, onArchive, onUnarchive, onDelete,
}: ThreadListItemComponentProps) {
return ( ... );
}
// After
const ThreadListItemComponent = memo(function ThreadListItemComponent({
thread, isActive, isArchived, onClick, onArchive, onUnarchive, onDelete,
}: ThreadListItemComponentProps) {
return ( ... );
});
No other changes needed to the component internals.
Note: For memo to be fully effective, the callbacks passed to each row should also be stable. Currently (lines 195-198), inline arrow functions create new references each render. That's a potential follow-up, but even without it, memo helps when thread and isActive are unchanged (the most common case).
Acceptance criteria
ThreadListItemComponent is wrapped in React.memo
- Thread list still works: clicking, archiving, unarchiving, deleting all function correctly
- In React DevTools Profiler, unchanged thread rows show as "Did not render" when another row is clicked
Description
ThreadListItemComponentinthread-list.tsxrenders inside a.map()for every chat thread. When the parent re-renders (e.g., switching active thread, toggling archive filter), all thread rows re-render even if their individual props haven't changed. Wrapping the component inReact.memolets React skip re-rendering rows whose props are referentially equal.Vercel React Best Practices Rule:
rerender-memo(5.5)File to change
surfsense_web/components/assistant-ui/thread-list.tsxWhat to do
memoto the React import:ThreadListItemComponent(lines 218-275) from a plain function to a memoized component:No other changes needed to the component internals.
Acceptance criteria
ThreadListItemComponentis wrapped inReact.memo