Skip to content

Commit

Permalink
chore: add changeset (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Sep 7, 2024
1 parent 2dfdeb2 commit cc5e7d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-bears-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

perf: memoize tool Ul components
13 changes: 3 additions & 10 deletions packages/react/src/primitives/message/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,9 @@ export const MessagePrimitiveContent: FC<MessagePrimitiveContentProps> = ({

const contentLength = useMessage((s) => s.message.content.length) || 1;

return new Array(contentLength).fill(null).map((_, idx) => {
const partIndex = idx; // use the index as key, as message is generally append only
return (
<MessageContentPart
key={partIndex}
partIndex={partIndex}
components={components}
/>
);
});
return Array.from({ length: contentLength }, (_, index) => (
<MessageContentPart key={index} partIndex={index} components={components} />
));
};

MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
13 changes: 3 additions & 10 deletions packages/react/src/primitives/thread/ThreadMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,9 @@ export const ThreadPrimitiveMessagesImpl: FC<ThreadPrimitiveMessagesProps> = ({
const messagesLength = useThreadMessages((t) => t.length);
if (messagesLength === 0) return null;

return new Array(messagesLength).fill(null).map((_, idx) => {
const messageIndex = idx; // keep the same key when switching branches for better a11y support
return (
<ThreadMessage
key={messageIndex}
messageIndex={messageIndex}
components={components}
/>
);
});
return Array.from({ length: messagesLength }, (_, index) => (
<ThreadMessage key={index} messageIndex={index} components={components} />
));
};

ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
Expand Down

0 comments on commit cc5e7d4

Please sign in to comment.