Skip to content

fix(review): persist file comment drafts across close/reopen#721

Merged
backnotprop merged 4 commits into
backnotprop:mainfrom
codythatsme:main
May 13, 2026
Merged

fix(review): persist file comment drafts across close/reopen#721
backnotprop merged 4 commits into
backnotprop:mainfrom
codythatsme:main

Conversation

@codythatsme
Copy link
Copy Markdown
Contributor

@codythatsme codythatsme commented May 13, 2026

Summary

  • File comment popovers in the code review UI dropped in-progress text whenever the popover was dismissed (click-outside / Escape / close button) — text and images lived in CommentPopover's local useState, so unmount erased them. Reopening on the same file started from a blank textarea.
  • The line-comment toolbar already solves this with a module-level draft map. This PR mirrors that pattern in CommentPopover behind an opt-in draftKey prop so existing call sites that don't want draft persistence are unaffected.
  • Wire both file-comment call sites — AllFilesDiffView and DiffViewer — with draftKey={file:${filePath}}. Drafts are cleared on submit.

Recording

CleanShot.2026-05-13.at.23.33.19.2.mp4

Test plan

  • bun run --cwd apps/review build && bun run build:hook — clean build
  • Open a file-level comment popover, type some text, click outside — reopen the same file's popover, draft is restored
  • Same flow with Escape and the X close button — draft restored in both cases
  • Attach an image, dismiss, reopen — image attachment is restored alongside text
  • Submit the comment — reopen the same file's popover, textarea is empty (draft cleared on submit)
  • Open file A's popover, type, dismiss; open file B's popover — file B is blank (drafts keyed per file, no cross-talk)
  • Line-comment toolbar still behaves as before (regression check on the existing line-comment draft path)

codythatsme and others added 4 commits May 13, 2026 22:40
File comment popover lost in-progress text when dismissed via click-outside / Escape / X — local state died with the unmount. Line-comment toolbar already does this via a module-level draft map; mirror the pattern in `CommentPopover` behind an opt-in `draftKey` prop and wire both file-comment call sites (`AllFilesDiffView`, `DiffViewer`).
File-path-only key leaked drafts across in-place PR switches.
The all-files panel shares one CommentPopover instance across every
file. Switching files (or PR/scope) batches close+open into a single
state transition, so React reuses the instance with stale text in
state and the draft-sync effect writes it under the new draftKey.
Key the popover by the same expression as draftKey so any change in
file, PR, or scope forces a fresh mount that reads its own draft.
Also clear the anchor when the file list reloads so a popover
anchored to a removed DOM node doesn't survive a diff swap.
@backnotprop backnotprop merged commit b04c9e1 into backnotprop:main May 13, 2026
10 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.

2 participants