π OpenHands: AI-Driven Development
fix(frontend): Memoize messages (#6006)
sp.wack4c59cff2a300
diff --git a/frontend/.eslintrc b/frontend/.eslintrcindex 29896d083c..03d7498d3a 100644--- a/frontend/.eslintrc+++ b/frontend/.eslintrc@@ -73,6 +73,7 @@}}],+ "react/prop-types": "off","react/no-array-index-key": "off","react-hooks/exhaustive-deps": "off","import/no-extraneous-dependencies": "off",diff --git a/frontend/src/components/features/chat/messages.tsx b/frontend/src/components/features/chat/messages.tsxindex e1bd346374..74439e17a6 100644--- a/frontend/src/components/features/chat/messages.tsx+++ b/frontend/src/components/features/chat/messages.tsx@@ -1,3 +1,4 @@+import React from "react";import { ChatMessage } from "#/components/features/chat/chat-message";import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons";import { ImageCarousel } from "../images/image-carousel";@@ -8,32 +9,36 @@ interface MessagesProps {isAwaitingUserConfirmation: boolean;}-export function Messages({- messages,- isAwaitingUserConfirmation,-}: MessagesProps) {- return messages.map((message, index) => {- if (message.type === "error" || message.type === "action") {+export const Messages: React.FC<MessagesProps> = React.memo(+ ({ messages, isAwaitingUserConfirmation }) =>+ messages.map((message, index) => {+ if (message.type === "error" || message.type === "action") {+ return (+ <ExpandableMessage+ key={index}+ type={message.type}+ id={message.translationID}+ message={message.content}+ success={message.success}+ />+ );+ }+return (- <ExpandableMessage+ <ChatMessagekey={index}- type={message.type}- id={message.translationID}+ type={message.sender}message={message.content}- success={message.success}- />+ >+ {message.imageUrls && message.imageUrls.length > 0 && (+ <ImageCarousel size="small" images={message.imageUrls} />+ )}+ {messages.length - 1 === index &&+ message.sender === "assistant" &&+ isAwaitingUserConfirmation && <ConfirmationButtons />}+ </ChatMessage>);- }+ }),+);- return (- <ChatMessage key={index} type={message.sender} message={message.content}>- {message.imageUrls && message.imageUrls.length > 0 && (- <ImageCarousel size="small" images={message.imageUrls} />- )}- {messages.length - 1 === index &&- message.sender === "assistant" &&- isAwaitingUserConfirmation && <ConfirmationButtons />}- </ChatMessage>- );- });-}+Messages.displayName = "Messages";