From 31037d3a09de96c87eba56354f976dbf15093671 Mon Sep 17 00:00:00 2001 From: GraysonCAdams Date: Mon, 13 Apr 2026 20:58:54 -0500 Subject: [PATCH] fix: insert new comments at correct sort position MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server sorts top-level comments by hearts desc, then createdAt asc, so a brand-new comment (0 hearts, newest timestamp) belongs at the bottom of the list — not the top. Append the new comment and scroll it into view instead of prepending, keeping the client in sync with the server order. --- src/lib/components/CommentsSheet.svelte | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/components/CommentsSheet.svelte b/src/lib/components/CommentsSheet.svelte index 66957d2..8c7d5d6 100644 --- a/src/lib/components/CommentsSheet.svelte +++ b/src/lib/components/CommentsSheet.svelte @@ -168,13 +168,18 @@ ?.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); }); } else { - comments = [{ ...newComment, replyCount: 0, replies: [] }, ...comments]; + // Server sorts top-level by hearts desc, then createdAt asc. A + // brand-new comment has 0 hearts and the newest timestamp, so it + // belongs at the very bottom — append instead of prepending. + comments = [...comments, { ...newComment, replyCount: 0, replies: [] }]; justPostedId = newComment.id; safeTimeout(() => { justPostedId = null; }, 300); requestAnimationFrame(() => { - document.querySelector('.comments-list')?.scrollTo({ top: 0, behavior: 'smooth' }); + document + .querySelector(`[data-comment-id="${newComment.id}"]`) + ?.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); }); } commentInput?.clear();