generated from cording12/next-fast-turbo
-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
Description
ChunkCard in source-detail-panel.tsx renders a MarkdownViewer (which uses Streamdown + KaTeX) for each document chunk. When activeChunkIndex or scroll state changes, all chunk cards re-render even though their markdown content hasn't changed. Since MarkdownViewer is expensive, memoizing ChunkCard can significantly reduce wasted work.
Vercel React Best Practices Rule: rerender-memo (5.5)
File to change
surfsense_web/components/new-chat/source-detail-panel.tsx
What to do
-
Add
memoto the React import (alongside the existingforwardRef). -
Wrap the existing
forwardRefcomponent inmemo(lines 58-105):
// Before
const ChunkCard = forwardRef<HTMLDivElement, ChunkCardProps>(
({ chunk, index, totalChunks, isCited }, ref) => {
return ( ... );
}
);
// After
const ChunkCard = memo(forwardRef<HTMLDivElement, ChunkCardProps>(
({ chunk, index, totalChunks, isCited }, ref) => {
return ( ... );
}
));Acceptance criteria
ChunkCardis wrapped inmemo- Cited chunk highlighting still works
- Scrolling to cited chunk still works
- Non-active chunks don't re-render when active chunk changes (verifiable in React DevTools Profiler)
Reactions are currently unavailable