From 86d66d53f889ab796adee204fd3330e7a5809b83 Mon Sep 17 00:00:00 2001 From: Blake Fischer <bfischer1121@gmail.com> Date: Mon, 17 Mar 2025 19:21:54 -0600 Subject: [PATCH 1/3] fix: messages memoization --- components/messages.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/messages.tsx b/components/messages.tsx index 045f3ae55..c9d000263 100644 --- a/components/messages.tsx +++ b/components/messages.tsx @@ -69,8 +69,11 @@ function PureMessages({ export const Messages = memo(PureMessages, (prevProps, nextProps) => { if (prevProps.isArtifactVisible && nextProps.isArtifactVisible) return true; + const prevIsLoading = (prevProps.status === 'submitted' || prevProps.status === 'streaming'); + const nextIsLoading = (nextProps.status === 'submitted' || nextProps.status === 'streaming'); + if (prevProps.status !== nextProps.status) return false; - if (prevProps.status && nextProps.status) return false; + if (prevIsLoading && nextIsLoading) return false; if (prevProps.messages.length !== nextProps.messages.length) return false; if (!equal(prevProps.messages, nextProps.messages)) return false; if (!equal(prevProps.votes, nextProps.votes)) return false; From fdc1e69ccc84892744d6a25ec5d1e6f559a95bbf Mon Sep 17 00:00:00 2001 From: Blake Fischer <bfischer1121@gmail.com> Date: Mon, 17 Mar 2025 19:22:49 -0600 Subject: [PATCH 2/3] fix: show stop button while streaming --- components/multimodal-input.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/multimodal-input.tsx b/components/multimodal-input.tsx index d47a7a8ce..c951ea460 100644 --- a/components/multimodal-input.tsx +++ b/components/multimodal-input.tsx @@ -253,7 +253,7 @@ function PureMultimodalInput({ </div> <div className="absolute bottom-0 right-0 p-2 w-fit flex flex-row justify-end"> - {status === 'submitted' ? ( + {(status === 'submitted' || status === 'streaming') ? ( <StopButton stop={stop} setMessages={setMessages} /> ) : ( <SendButton From 4fc7c25226962220b09f29d8f8cf7d1c3e42148a Mon Sep 17 00:00:00 2001 From: Blake Fischer <bfischer1121@gmail.com> Date: Mon, 17 Mar 2025 21:45:50 -0600 Subject: [PATCH 3/3] fix: set content before sending to provider --- app/(chat)/chat/[id]/page.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/(chat)/chat/[id]/page.tsx b/app/(chat)/chat/[id]/page.tsx index 66c027a53..26a5ee421 100644 --- a/app/(chat)/chat/[id]/page.tsx +++ b/app/(chat)/chat/[id]/page.tsx @@ -35,12 +35,18 @@ export default async function Page(props: { params: Promise<{ id: string }> }) { }); function convertToUIMessages(messages: Array<DBMessage>): Array<UIMessage> { + const textFromParts = (message.parts as UIMessage['parts']) + .filter((part) => part.type === 'text') + .map((part) => part.text) + .join('\n') + .trim(); + return messages.map((message) => ({ id: message.id, parts: message.parts as UIMessage['parts'], role: message.role as UIMessage['role'], // Note: content will soon be deprecated in @ai-sdk/react - content: '', + content: textFromParts, createdAt: message.createdAt, experimental_attachments: (message.attachments as Array<Attachment>) ?? [],