Performance (#602)

This commit is contained in:
Anthony Puppo 2023-04-19 10:39:19 -04:00 committed by GitHub
parent 24068ea5aa
commit c959264f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

View File

@ -28,11 +28,11 @@ import HomeContext from '@/pages/api/home/home.context';
import Spinner from '../Spinner';
import { ChatInput } from './ChatInput';
import { ChatLoader } from './ChatLoader';
import { ChatMessage } from './ChatMessage';
import { ErrorMessageDiv } from './ErrorMessageDiv';
import { ModelSelect } from './ModelSelect';
import { SystemPrompt } from './SystemPrompt';
import { TemperatureSlider } from './Temperature';
import { MemoizedChatMessage } from './MemoizedChatMessage';
interface Props {
stopConversationRef: MutableRefObject<boolean>;
@ -464,7 +464,7 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
)}
{selectedConversation?.messages.map((message, index) => (
<ChatMessage
<MemoizedChatMessage
key={index}
message={message}
messageIndex={index}

View File

@ -23,7 +23,7 @@ import rehypeMathjax from 'rehype-mathjax';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
interface Props {
export interface Props {
message: Message;
messageIndex: number;
onEdit?: (editedMessage: Message) => void

View File

@ -0,0 +1,9 @@
import { FC, memo } from "react";
import { ChatMessage, Props } from "./ChatMessage";
export const MemoizedChatMessage: FC<Props> = memo(
ChatMessage,
(prevProps, nextProps) => (
prevProps.message.content === nextProps.message.content
)
);

View File

@ -1,4 +1,9 @@
import { FC, memo } from 'react';
import ReactMarkdown, { Options } from 'react-markdown';
export const MemoizedReactMarkdown: FC<Options> = memo(ReactMarkdown);
export const MemoizedReactMarkdown: FC<Options> = memo(
ReactMarkdown,
(prevProps, nextProps) => (
prevProps.children === nextProps.children
)
);