Skip to content

Commit f986d9c

Browse files
rainbowFiclaude
andcommitted
fix: use SDK-recommended sort pattern for message ordering
Sort messages by serial using comparison operators as shown in the Chat SDK documentation, rather than findIndex/splice insertion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 559c5d6 commit f986d9c

1 file changed

Lines changed: 1 addition & 10 deletions

File tree

components/ChatBox.jsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,7 @@ export default function ChatBox() {
1717
if (prevMessages.some((existingMessage) => existingMessage.serial === newMessage.serial)) {
1818
return prevMessages;
1919
}
20-
21-
const index = prevMessages.findIndex((existingMessage) => existingMessage.serial > newMessage.serial);
22-
23-
const newMessages = [...prevMessages];
24-
if (index === -1) {
25-
newMessages.push(newMessage);
26-
} else {
27-
newMessages.splice(index, 0, newMessage);
28-
}
29-
return newMessages;
20+
return [...prevMessages, newMessage].sort((a, b) => (a.serial < b.serial ? -1 : b.serial < a.serial ? 1 : 0));
3021
});
3122
},
3223
});

0 commit comments

Comments
 (0)