Skip to content

Warn before clearing review mode when unsaved comment drafts exist - #9043

Merged
Alex Ross (alexr00) merged 3 commits into
microsoft:mainfrom
diptomistry:fix/7556-warn-unsaved-comment-drafts-on-merge
Oct 29, 2026
Merged

Alex Ross (alexr00) merged 3 commits into
microsoft:mainfrom
diptomistry:fix/7556-warn-unsaved-comment-drafts-on-merge

Conversation

@diptomistry

Copy link
Copy Markdown
Contributor

Fixes #7556

Per Alex Ross (@alexr00)'s guidance (Option 1), warn before clearing when there are
unsaved file-comment drafts.

  • Add ReviewCommentController.hasUnsavedCommentDrafts()
  • Show a modal warning before clearing review mode on merged/closed PRs
  • Discard: clear as before. Cancel: keep review mode, don't re-prompt on poll

Testing:

  • Checkout a PR in review mode, start a file comment (type text, don't submit), merge the PR from elsewhere, wait for refresh → warning appears
  • Choose Discard → review mode clears and draft is gone
  • Repeat, choose Cancel (dismiss) → draft and review mode stay; another refresh does not re-prompt
  • Same Cancel/Discard flow after closing a PR (not merging)
  • Merge/close with no open comment draft → no warning; review mode clears as before
  • Pending review comments already on GitHub still remain submittable after clear

When a PR is merged or closed, ReviewManager clears review mode, which
disposes ReviewCommentController and drops any text only present in the
local comment input. Prompt the user before clearing if drafts exist, and
remember a "cancel" choice so polling doesn't re-prompt.

Fixes microsoft#7556
Copilot AI balanced review requested due to automatic review settings October 8, 2026 15:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@diptomistry

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@alexr00 Alex Ross (alexr00) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

Some additional changes requested based on AI code review.

Copilot PRs get a warning even when nothing was typed.
tryAddCopilotMention automatically inserts Copilot into empty comment boxes on Copilot PRs. hasUnsavedCommentDrafts treats that text as a draft, so merging a Copilot PR with any comment box open triggers the warning. Ignore text that is just the auto-inserted mention.

Choosing Cancel skips the rest of the refresh but still records it as done.
The cancel branches at reviewManager.ts:770 and reviewManager.ts:783 return early, so the active PR, the changes view and the layout are never updated. But _isShowingLastReviewChanges (line 752) and _lastCommitSha have already been updated. Whatever triggered this pass (newly pulled commits, or toggling "show changes since review") is lost, because the next pass hits the "no meaningful state change" early return. Once the user chooses to keep review mode, the code should continue the normal flow, the same as with useReviewMode.merged: true.

Comment thread src/view/reviewManager.ts Resolved
Comment thread src/view/reviewCommentController.ts Resolved
Comment thread src/view/reviewManager.ts Resolved
Keep review mode when a merged or closed PR has real drafts, warn without
blocking validation, and let the user exit later. Ignore the auto-inserted
Copilot mention and match comment URIs exactly.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 17:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@alexr00 Alex Ross (alexr00) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to repro the original issue so that I can verify the fix:

  1. Check out a PR
  2. Write a comment in a file, but don't submit
  3. Go to GitHub.com and close the PR
  4. In the active PR view, refresh.
  5. Review mode is not actually exited, even though I have:
  "githubPullRequests.useReviewMode": {
    "merged": true,
    "closed": false
  },

@alexr00 Alex Ross (alexr00) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repro steps:

  1. Check out the PR, then reload the window (or check out the branch with plain git) so _switchedToPullRequest isn't set.
  2. Start a file comment and don't submit it.
  3. Close the PR on GitHub.
  4. Move the local branch while keeping it in sync with upstream: git commit --allow-empty -m repro, then git push. Pulling a commit someone else pushed also works.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 11:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@alexr00 Alex Ross (alexr00) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

@alexr00 Alex Ross (alexr00) self-assigned this Oct 29, 2026
@alexr00
Alex Ross (alexr00) enabled auto-merge (squash) October 29, 2026 11:13
@alexr00

Copy link
Copy Markdown
Member

/AzurePipelines run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
2 pipeline(s) were filtered out due to trigger conditions.

@alexr00
Alex Ross (alexr00) merged commit fc58859 into microsoft:main Oct 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In progress comments are lost when updating after PR is merged

5 participants