From e09809f495b3b1ca793db1ffdec539179b0ea367 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 24 Mar 2026 19:10:49 +0000 Subject: [PATCH] Fix NaN from NEGATIVE_INFINITY subtraction in sortThreadsForSidebar When two threads both yield Number.NEGATIVE_INFINITY timestamps, the subtraction (-Infinity) - (-Infinity) produces NaN, which bypasses the ID-based tiebreaker and causes unpredictable sort order. Use explicit comparison (=== / >) instead of subtraction, matching the pattern already used in sortProjectsForSidebar. --- apps/web/src/components/Sidebar.logic.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index f25a116446..9ce12d3b8c 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -270,8 +270,10 @@ export function sortThreadsForSidebar< T extends Pick, >(threads: readonly T[], sortOrder: SidebarThreadSortOrder): T[] { return threads.toSorted((left, right) => { + const rightTimestamp = getThreadSortTimestamp(right, sortOrder); + const leftTimestamp = getThreadSortTimestamp(left, sortOrder); const byTimestamp = - getThreadSortTimestamp(right, sortOrder) - getThreadSortTimestamp(left, sortOrder); + rightTimestamp === leftTimestamp ? 0 : rightTimestamp > leftTimestamp ? 1 : -1; if (byTimestamp !== 0) return byTimestamp; return right.id.localeCompare(left.id); });