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.
Unified · Split
| @@ -270,8 +270,10 @@ export function sortThreadsForSidebar< · 269 unmodified lines | ||
| 270 | 270 | T extends Pick<Thread, "id" | "createdAt" | "updatedAt" | "messages">, |
| 271 | 271 | >(threads: readonly T[], sortOrder: SidebarThreadSortOrder): T[] { |
| 272 | 272 | return threads.toSorted((left, right) => { |
| 273 | + const rightTimestamp = getThreadSortTimestamp(right, sortOrder); | |
| 274 | + const leftTimestamp = getThreadSortTimestamp(left, sortOrder); | |
| 273 | 275 | const byTimestamp = |
| 274 | − getThreadSortTimestamp(right, sortOrder) - getThreadSortTimestamp(left, sortOrder); | |
| 276 | + rightTimestamp === leftTimestamp ? 0 : rightTimestamp > leftTimestamp ? 1 : -1; | |
| 275 | 277 | if (byTimestamp !== 0) return byTimestamp; |
| 276 | 278 | return right.id.localeCompare(left.id); |
| 277 | 279 | }); |