Avoid re-saving an Unsaved comment
Unsaved comments are drafts for which a save() request has not
been sent yet and hence they don't have a draftID.
If a duplicate save() request is called then two drafts end up
being created. This is possible in some rare scenarios such as
if a reply is sent in the reply dialog using the Cmd+E
shortcut which triggers a request via GrComment listener and
the send() method in GrReplyDialog.
Release-Notes: skip
Google-bug-id: b/253283951
Change-Id: I7ee8feff5cbcfcfd5a55bd1f79d7605604780c82
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
index 721349f..9db3693 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -1178,6 +1178,9 @@
async save() {
if (!isDraftOrUnsaved(this.comment)) throw new Error('not a draft');
+ // If it's an unsaved comment then it does not have a draftID yet which
+ // means sending another save() request will create a new draft
+ if (isUnsaved(this.comment) && this.saving) return;
try {
this.saving = true;