Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: handle edit message bug (#5274)

Joaquin Corominaa2d62b3bccf3
diff --git a/frontend/src/components/chat/chat-panel.tsx b/frontend/src/components/chat/chat-panel.tsx
index ccc4e95464..96e432b925 100644
--- a/frontend/src/components/chat/chat-panel.tsx
+++ b/frontend/src/components/chat/chat-panel.tsx
@@ -170,16 +170,6 @@ const ChatMessage: React.FC<ChatMessageProps> = memo(
return;
}
onEdit(index, newValue);
- if (chatState.activeChatId) {
- setChatState((prev: ChatState) =>
- addMessageToChat(
- prev,
- chatState.activeChatId,
- "user",
- newValue,
- ),
- );
- }
}}
onClose={() => {
// noop
@@ -409,11 +399,33 @@ const ChatPanelBody = () => {
};
const handleMessageEdit = (index: number, newValue: string) => {
+ // Truncate both useChat and storage
setMessages((messages) => messages.slice(0, index));
+ if (chatState.activeChatId) {
+ setChatState((prev) => ({
+ ...prev,
+ chats: prev.chats.map((chat) =>
+ chat.id === chatState.activeChatId
+ ? {
+ ...chat,
+ messages: chat.messages.slice(0, index),
+ updatedAt: Date.now(),
+ }
+ : chat,
+ ),
+ }));
+ }
+
+ // Add user message to useChat and storage
append({
role: "user",
content: newValue,
});
+ if (chatState.activeChatId) {
+ setChatState((prev) =>
+ addMessageToChat(prev, chatState.activeChatId, "user", newValue),
+ );
+ }
};
const handleChatInputSubmit = (