fix(comments): cascade delete replies when parent comment is deleted

When a parent comment is deleted, remove all its replies from the timeline
instead of promoting them to top-level (orphaned replies have no context).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Naiyuan Qing 2026-03-28 22:03:46 +08:00
parent ba3c8e1b3f
commit 8a9ae0102d

View file

@ -316,11 +316,7 @@ export function IssueDetail({ issueId, onDelete }: IssueDetailProps) {
try {
await api.deleteComment(commentId);
setTimeline((prev) =>
prev
// Promote replies of deleted comment to top-level
.map((e) => e.parent_id === commentId ? { ...e, parent_id: null } : e)
// Remove the deleted comment
.filter((e) => e.id !== commentId)
prev.filter((e) => e.id !== commentId && e.parent_id !== commentId)
);
} catch {
toast.error("Failed to delete comment");
@ -386,9 +382,7 @@ export function IssueDetail({ issueId, onDelete }: IssueDetailProps) {
const { comment_id, issue_id } = payload as CommentDeletedPayload;
if (issue_id === id) {
setTimeline((prev) =>
prev
.map((e) => e.parent_id === comment_id ? { ...e, parent_id: null } : e)
.filter((e) => e.id !== comment_id)
prev.filter((e) => e.id !== comment_id && e.parent_id !== comment_id)
);
}
}, [id]),