Fix saving comment while auto-saving is in progress
If you save a comment while auto-saving (of the unsaved draft) is
still in progress, then two replies would be created, because save does
not use the ID of the auto-saved draft.
The fix is to return the saved DraftInfo object from the model when
saveDraft() is called and assign that directly to this.comment instead
of waiting for the element update.
An alternative fix would have been to call `await this.updateComplete`,
but that would have been relying on timing and scheduling of tasks,
which seemed to fragile.
Google-Bug-Id: b/209550143
Change-Id: I3b08dc2a69c8036d85215a1d3600121783b38e33
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 1b3ab79..ef69d0a 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -43,6 +43,7 @@
import {GrConfirmDeleteCommentDialog} from '../gr-confirm-delete-comment-dialog/gr-confirm-delete-comment-dialog';
import {
Comment,
+ DraftInfo,
isDraftOrUnsaved,
isRobot,
isUnsaved,
@@ -172,7 +173,7 @@
* without the user noticing.
*/
@state()
- autoSaving?: Promise<void>;
+ autoSaving?: Promise<DraftInfo>;
@state()
changeNum?: NumericChangeId;
@@ -1079,7 +1080,9 @@
try {
this.saving = true;
this.unableToSave = false;
- if (this.autoSaving) await this.autoSaving;
+ if (this.autoSaving) {
+ this.comment = await this.autoSaving;
+ }
// Depending on whether `messageToSave` is empty we treat this either as
// a discard or a save action.
const messageToSave = this.messageText.trimEnd();