From 1e7dc6af46381f3756d078d2307cc4d41a758a85 Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Thu, 2 Apr 2026 18:40:25 -0700 Subject: [PATCH] Don't clobber sort order --- frontend/src/App.tsx | 1 + frontend/src/components/ConversationPane.tsx | 3 +++ frontend/src/components/MessageList.tsx | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 44fdb7d..8f8b3aa 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -508,6 +508,7 @@ export function App() { health, favorites, messages: sortedMessages, + preSorted: activeContactIsRoom, messagesLoading, loadingOlder, hasOlderMessages, diff --git a/frontend/src/components/ConversationPane.tsx b/frontend/src/components/ConversationPane.tsx index 34f196c..15cab04 100644 --- a/frontend/src/components/ConversationPane.tsx +++ b/frontend/src/components/ConversationPane.tsx @@ -44,6 +44,7 @@ interface ConversationPaneProps { notificationsPermission: NotificationPermission | 'unsupported'; favorites: Favorite[]; messages: Message[]; + preSorted?: boolean; messagesLoading: boolean; loadingOlder: boolean; hasOlderMessages: boolean; @@ -114,6 +115,7 @@ export function ConversationPane({ notificationsPermission, favorites, messages, + preSorted, messagesLoading, loadingOlder, hasOlderMessages, @@ -275,6 +277,7 @@ export function ConversationPane({ void; onJumpToBottom?: () => void; + preSorted?: boolean; } // URL regex for linkifying plain text @@ -283,6 +284,7 @@ export function MessageList({ loadingNewer = false, onLoadNewer, onJumpToBottom, + preSorted = false, }: MessageListProps) { const listRef = useRef(null); const prevMessagesLengthRef = useRef(0); @@ -486,8 +488,11 @@ export function MessageList({ // Note: Deduplication is handled by useConversationMessages.observeMessage() // and the database UNIQUE constraint on (type, conversation_key, text, sender_timestamp) const sortedMessages = useMemo( - () => [...messages].sort((a, b) => a.received_at - b.received_at || a.id - b.id), - [messages] + () => + preSorted + ? messages + : [...messages].sort((a, b) => a.received_at - b.received_at || a.id - b.id), + [messages, preSorted] ); const unreadMarkerIndex = useMemo(() => { if (unreadMarkerLastReadAt === undefined) {