perf: wrap ToolCall, CodeBlock, ThinkingBlock, ImageBlock in React.memo

Prevents unnecessary re-renders of these frequently rendered child
components when parent message list updates but individual props
haven't changed.
This commit is contained in:
Nicolas Varrot
2026-02-22 21:03:31 +00:00
parent 4163124c6a
commit 9faa5014a6
4 changed files with 12 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import { useState, useCallback, useMemo, useEffect, useRef } from 'react';
import { useState, useCallback, useMemo, useEffect, useRef, memo } from 'react';
import { ChevronRight, ChevronDown, Check, Copy, WrapText, AlignLeft } from 'lucide-react';
import hljs from '../lib/highlight';
import { copyToClipboard } from '../lib/clipboard';
@@ -260,7 +260,7 @@ function extractImageFromResult(result: string): { src: string; remaining: strin
return null;
}
export function ToolCall({ name, input, result }: { name: string; input?: Record<string, unknown>; result?: string }) {
export const ToolCall = memo(function ToolCall({ name, input, result }: { name: string; input?: Record<string, unknown>; result?: string }) {
const t = useT();
const [open, setOpen] = useState(false);
const [wrap, setWrap] = useState(true);
@@ -359,4 +359,4 @@ export function ToolCall({ name, input, result }: { name: string; input?: Record
)}
</div>
);
}
});