fix(replies-preview): stable sort when recency yields identical Infinity values

This commit is contained in:
plebeius
2026-03-01 19:05:36 +08:00
parent dfa203a506
commit c9e9506ebd
+6 -2
View File
@@ -27,8 +27,12 @@ export function getPreviewDisplayReplies<T extends CommentLike>(replies: T[], vi
return Number.NEGATIVE_INFINITY;
};
const newestFirst = [...replies].sort((a, b) => getRecency(b) - getRecency(a));
return newestFirst.slice(0, visibleCount).reverse();
const tagged = replies.map((reply, i) => ({ reply, recency: getRecency(reply), i }));
tagged.sort((a, b) => (a.recency !== b.recency ? b.recency - a.recency : a.i - b.i));
return tagged
.slice(0, visibleCount)
.reverse()
.map((t) => t.reply);
}
export interface ComputeOmittedParams {