From 0ef41cc23bf8af4117a4462cdb7ccf7cf3d76282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Tue, 10 Nov 2026 16:32:36 +0100 Subject: [PATCH] desktop: Disallow attachments when editing a draft comment Drafts are kept in local storage and publish only their bodies, so a file attached while editing one never reached the COB and peers saw a broken link. The draft composer already disallowed attaching; editing didn't. --- .../src/components/CommentAnnotation.svelte | 4 +++ desktop/src/components/Revision.svelte | 3 +- desktop/src/components/Thread.svelte | 5 +++ desktop/src/lib/codeComments.ts | 5 +++ desktop/src/lib/draftReviewStorage.ts | 1 + desktop/tests/e2e/repo/editingEmbeds.spec.ts | 31 +++++++++++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/desktop/src/components/CommentAnnotation.svelte b/desktop/src/components/CommentAnnotation.svelte index 576d9f10b..080146584 100644 --- a/desktop/src/components/CommentAnnotation.svelte +++ b/desktop/src/components/CommentAnnotation.svelte @@ -5,6 +5,7 @@ import partial from "lodash/partial"; + import { draftAttachmentsDisabled } from "@app/lib/codeComments"; import { formatAnchor, formatAnchorLines, @@ -112,6 +113,9 @@ resolvedBy={comments.resolvedBy} inline draft={isDraftThread} + disableAttachments={isDraftThread + ? draftAttachmentsDisabled + : undefined} origin={comments.threadOrigins?.[thread.root.id]} reactOnComment={isDraftThread ? undefined : comments.reactOnComment} createReply={(comments.canReply ?? true) diff --git a/desktop/src/components/Revision.svelte b/desktop/src/components/Revision.svelte index 11d96bcec..c1daf3431 100644 --- a/desktop/src/components/Revision.svelte +++ b/desktop/src/components/Revision.svelte @@ -19,6 +19,7 @@ import type { CommentOwner } from "@app/lib/codeCommentActions"; import { commentActions } from "@app/lib/codeCommentActions"; import type { CodeComments } from "@app/lib/codeComments"; + import { draftAttachmentsDisabled } from "@app/lib/codeComments"; import { resolutionsByComment } from "@app/lib/commentResolutions"; import { STANDALONE_COMMENTS } from "@app/lib/commentSources"; import { diffOptions } from "@app/lib/diffOptions.svelte"; @@ -525,7 +526,7 @@ // to it.) canReply: !draftReview, hideThreadFileHeader: true, - disableAttachments: "Publish your review to attach files", + disableAttachments: draftAttachmentsDisabled, }; }); diff --git a/desktop/src/components/Thread.svelte b/desktop/src/components/Thread.svelte index f5a704f2c..701e2b666 100644 --- a/desktop/src/components/Thread.svelte +++ b/desktop/src/components/Thread.svelte @@ -48,6 +48,8 @@ // activity timeline for the outer rail to connect to. inline?: boolean; draft?: boolean; + // See `ExtendedTextarea`. + disableAttachments?: boolean | string; origin?: CommentOrigin; // Rendered on the root comment's authorship line while it is hovered. The // replies do not get it: it says something about the thread, not a comment. @@ -73,6 +75,7 @@ canResolve = false, inline = false, draft = false, + disableAttachments, origin, hoverNote, highlightedCommentId, @@ -220,6 +223,7 @@ timestamp={reply.edits[0].timestamp} body={reply.edits.slice(-1)[0].body} embeds={embedMap(reply.embeds)} + {disableAttachments} editComment={canModifyComment(reply.author.did) && editComment?.bind(null, reply.id)} reactOnComment={reactOnComment?.bind(null, reply.id)} @@ -274,6 +278,7 @@ timestamp={root.edits.slice(-1)[0].timestamp} body={root.edits.slice(-1)[0].body} embeds={embedMap(root.embeds)} + {disableAttachments} editComment={canModifyComment(root.author.did) && editComment?.bind(null, root.id)} reactOnComment={reactOnComment?.bind(null, root.id)} diff --git a/desktop/src/lib/codeComments.ts b/desktop/src/lib/codeComments.ts index 40d03364c..4bd89d920 100644 --- a/desktop/src/lib/codeComments.ts +++ b/desktop/src/lib/codeComments.ts @@ -77,3 +77,8 @@ export interface CodeComments { rid: string; threads: Thread[]; } + +// Drafts are kept in local storage and publish only their bodies. An +// uploaded file stays unreferenced in the repo until a COB lists it, so +// the node's `git gc` can prune it, and peers never receive it. +export const draftAttachmentsDisabled = "Publish your review to attach files"; diff --git a/desktop/src/lib/draftReviewStorage.ts b/desktop/src/lib/draftReviewStorage.ts index ff572426b..b781f7b3a 100644 --- a/desktop/src/lib/draftReviewStorage.ts +++ b/desktop/src/lib/draftReviewStorage.ts @@ -210,6 +210,7 @@ export const draftReviewStorage = { }); }, + // Draft comments have no embeds, see `draftAttachmentsDisabled`. addComment( id: string, comment: { diff --git a/desktop/tests/e2e/repo/editingEmbeds.spec.ts b/desktop/tests/e2e/repo/editingEmbeds.spec.ts index ce911dab3..bf72f62e8 100644 --- a/desktop/tests/e2e/repo/editingEmbeds.spec.ts +++ b/desktop/tests/e2e/repo/editingEmbeds.spec.ts @@ -314,3 +314,34 @@ test("changing a review's verdict keeps its embeds", async ({ page, peer }) => { await expect(page.getByRole("button", { name: /Rejected/ })).toBeVisible(); expect(await storedEmbeds()).toEqual([embed]); }); + +test("files can't be attached when editing a draft review comment", async ({ + page, + peer, +}) => { + const { rid, patchId } = await createProject(peer); + await page.goto(`/repos/${rid}/patches/${patchId}?view=changes`); + await page + .locator( + '[data-unified] [data-column-number="3"]:not([data-line-type="change-deletion"])', + ) + .hover(); + await page.locator("[data-utility-button]").click(); + await page.getByPlaceholder("Leave a comment").fill("Loud enough"); + await page + .getByLabel("extended-textarea") + .filter({ has: page.getByPlaceholder("Leave a comment") }) + .getByRole("button", { name: /^Start review/ }) + .click(); + + await page.getByText("Loud enough").hover(); + const toggle = page.getByTitle("Comment actions").last(); + await toggle.click(); + await toggle + .locator(`xpath=following::*[@role="button"][normalize-space()="Edit"][1]`) + .click(); + + await expect( + page.locator('[id^="edit-"]').getByRole("button", { name: "Attach" }), + ).toBeDisabled(); +});