From a51cc76afabcf9ecfd64cb43fbab79b59c82becd Mon Sep 17 00:00:00 2001 From: Dexploarer <211557447+Dexploarer@users.noreply.github.com> Date: Mon, 27 Apr 2026 00:59:48 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20conversation=20l?= =?UTF-8?q?ist=20sorting=20to=20prevent=20unnecessary=20re-renders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added useMemo to the conversation list sorting and replaced the expensive `new Date().getTime()` allocation with lexicographical string comparison via `localeCompare` on ISO 8601 timestamps. --- .jules/bolt.md | 3 +++ apps/app/src/components/ConversationsSidebar.tsx | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000000..895bfbeecf --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2025-04-27 - Fast Lexicographical Time Sorting +**Learning:** In heavily used UI components like React sidebars that display lists updated in real-time, relying on `.sort()` blocks combined with inline `new Date(string).getTime()` allocation causes measurable re-render lag due to memory allocation and date parsing overhead on every tick. For standard ISO 8601 strings (like `updatedAt`), the sorting structure is inherently chronologically sound and allows for fast alphabetical comparison. +**Action:** When implementing real-time list sorting by ISO timestamp on the frontend, always combine array memoization (`useMemo`) with native `.localeCompare()` instead of allocating `Date` objects on every re-render. diff --git a/apps/app/src/components/ConversationsSidebar.tsx b/apps/app/src/components/ConversationsSidebar.tsx index 75d768bee2..2ef7e2dae4 100644 --- a/apps/app/src/components/ConversationsSidebar.tsx +++ b/apps/app/src/components/ConversationsSidebar.tsx @@ -2,7 +2,7 @@ * Conversations sidebar component — left sidebar with conversation list. */ -import { useEffect, useRef, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { useApp } from "../AppContext"; interface ConversationsSidebarProps { @@ -54,11 +54,12 @@ export function ConversationsSidebar({ } }, [editingId]); - const sortedConversations = [...conversations].sort((a, b) => { - const aTime = new Date(a.updatedAt).getTime(); - const bTime = new Date(b.updatedAt).getTime(); - return bTime - aTime; - }); + // ⚡ Bolt: Memoize the sorting and use localeCompare for timestamps instead of parsing Date + const sortedConversations = useMemo(() => { + return [...conversations].sort((a, b) => + b.updatedAt.localeCompare(a.updatedAt), + ); + }, [conversations]); const handleDoubleClick = (conv: { id: string; title: string }) => { setEditingId(conv.id);