Skip to content

Commit

Permalink
fix: memoize response from isMessageAIGenerated
Browse files Browse the repository at this point in the history
  • Loading branch information
isekovanic committed Dec 5, 2024
1 parent 8fd9e97 commit d3397d6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/Message/MessageSimple.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import clsx from 'clsx';

import { MessageErrorIcon } from './icons';
Expand Down Expand Up @@ -89,6 +89,10 @@ const MessageSimpleWithContext = <

const hasAttachment = messageHasAttachments(message);
const hasReactions = messageHasReactions(message);
const isAIGenerated = useMemo(() => isMessageAIGenerated?.(message), [
isMessageAIGenerated,
message,
]);

if (message.customType === CUSTOM_MESSAGE_TYPE.date) {
return null;
Expand All @@ -102,7 +106,7 @@ const MessageSimpleWithContext = <
const showReplyCountButton = !threadList && !!message.reply_count;
const allowRetry = message.status === 'failed' && message.errorStatusCode !== 403;
const isBounced = isMessageBounced(message);
const isEdited = isMessageEdited(message) && !isMessageAIGenerated?.(message);
const isEdited = isMessageEdited(message) && !isAIGenerated;

let handleClick: (() => void) | undefined = undefined;

Expand Down Expand Up @@ -188,7 +192,7 @@ const MessageSimpleWithContext = <
{message.attachments?.length && !message.quoted_message ? (
<Attachment actionHandler={handleAction} attachments={message.attachments} />
) : null}
{isMessageAIGenerated?.(message) ? (
{isAIGenerated ? (
<StreamedMessageText message={message} renderText={renderText} />
) : (
<MessageText message={message} renderText={renderText} />
Expand Down

0 comments on commit d3397d6

Please sign in to comment.