fix: memoize components and improve performance (#579)
This commit is contained in:
parent
a13368cfcd
commit
e839007580
16 changed files with 453 additions and 232 deletions
|
|
@ -3,7 +3,7 @@
|
|||
import type { Message } from 'ai';
|
||||
import cx from 'classnames';
|
||||
import { motion } from 'framer-motion';
|
||||
import type { Dispatch, SetStateAction } from 'react';
|
||||
import { memo, type Dispatch, type SetStateAction } from 'react';
|
||||
|
||||
import type { Vote } from '@/lib/db/schema';
|
||||
|
||||
|
|
@ -14,8 +14,9 @@ import { Markdown } from './markdown';
|
|||
import { MessageActions } from './message-actions';
|
||||
import { PreviewAttachment } from './preview-attachment';
|
||||
import { Weather } from './weather';
|
||||
import equal from 'fast-deep-equal';
|
||||
|
||||
export const PreviewMessage = ({
|
||||
const PurePreviewMessage = ({
|
||||
chatId,
|
||||
message,
|
||||
block,
|
||||
|
|
@ -152,6 +153,16 @@ export const PreviewMessage = ({
|
|||
);
|
||||
};
|
||||
|
||||
export const PreviewMessage = memo(
|
||||
PurePreviewMessage,
|
||||
(prevProps, nextProps) => {
|
||||
if (prevProps.isLoading !== nextProps.isLoading) return false;
|
||||
if (prevProps.isLoading && nextProps.isLoading) return false;
|
||||
if (!equal(prevProps.vote, nextProps.vote)) return false;
|
||||
return true;
|
||||
},
|
||||
);
|
||||
|
||||
export const ThinkingMessage = () => {
|
||||
const role = 'assistant';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue