From 164e46cbdf4961ded8d15204a83ae4455af1ae3b Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Mon, 9 Sep 2024 23:44:05 -0700 Subject: [PATCH] feat: ignore edits with text part unchanged (#806) --- .changeset/great-kids-worry.md | 5 +++++ packages/react/src/context/providers/MessageProvider.tsx | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 .changeset/great-kids-worry.md diff --git a/.changeset/great-kids-worry.md b/.changeset/great-kids-worry.md new file mode 100644 index 000000000..5f8b82048 --- /dev/null +++ b/.changeset/great-kids-worry.md @@ -0,0 +1,5 @@ +--- +"assistant-ui": patch +--- + +feat: ignore edits with text part unchanged diff --git a/packages/react/src/context/providers/MessageProvider.tsx b/packages/react/src/context/providers/MessageProvider.tsx index 50faf8681..cdee3688d 100644 --- a/packages/react/src/context/providers/MessageProvider.tsx +++ b/packages/react/src/context/providers/MessageProvider.tsx @@ -89,6 +89,9 @@ const useMessageContext = (messageIndex: number) => { "Tried to edit a non-user message. Editing is only supported for user messages. This is likely an internal bug in assistant-ui.", ); + const previousText = getThreadMessageText(message); + if (previousText === text) return; + const nonTextParts = message.content.filter( (part): part is CoreUserContentPart => part.type !== "text" && part.type !== "ui",