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.
This commit is contained in:
1 file changed
+3
-1
@@ -270,8 +270,10 @@ export function sortThreadsForSidebar<
|
||||
T extends Pick<Thread, "id" | "createdAt" | "updatedAt" | "messages">,
|
||||
>(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);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user