Elffuss BraidHub

kikocis/continue public

b06f5503dce8 · 958 BRawPermalink
1import React, { useCallback } from "react";
2
3import type { ChatHistoryItem } from "../../../../../core/index.js";
4import { MemoizedMessage } from "../components/MemoizedMessage.js";
5
6export function useMessageRenderer() {
7 const renderMessage = useCallback((item: ChatHistoryItem, index: number) => {
8 // Generate a unique key by combining message role, content hash, and timestamp
9 // This provides a stable identifier that won't change during re-renders
10 const messageContent =
11 typeof item.message.content === "string"
12 ? item.message.content
13 : JSON.stringify(item.message.content);
14
15 const toolCallsKey = item.toolCallStates
16 ? item.toolCallStates.map((tc) => tc.toolCallId).join("-")
17 : "";
18
19 const uniqueKey = `${item.message.role}-${messageContent.slice(0, 50)}-${toolCallsKey}-${index}`;
20
21 return <MemoizedMessage key={uniqueKey} item={item} index={index} />;
22 }, []);
23
24 return { renderMessage };
25}