Skip to content

Commit e09809f

Browse files
committed
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.
1 parent 1f96d6d commit e09809f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

apps/web/src/components/Sidebar.logic.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,10 @@ export function sortThreadsForSidebar<
270270
T extends Pick<Thread, "id" | "createdAt" | "updatedAt" | "messages">,
271271
>(threads: readonly T[], sortOrder: SidebarThreadSortOrder): T[] {
272272
return threads.toSorted((left, right) => {
273+
const rightTimestamp = getThreadSortTimestamp(right, sortOrder);
274+
const leftTimestamp = getThreadSortTimestamp(left, sortOrder);
273275
const byTimestamp =
274-
getThreadSortTimestamp(right, sortOrder) - getThreadSortTimestamp(left, sortOrder);
276+
rightTimestamp === leftTimestamp ? 0 : rightTimestamp > leftTimestamp ? 1 : -1;
275277
if (byTimestamp !== 0) return byTimestamp;
276278
return right.id.localeCompare(left.id);
277279
});

0 commit comments

Comments
 (0)