fix(review): persist file comment drafts across close/reopen#721
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Escape/ close button) —textandimageslived inCommentPopover's localuseState, so unmount erased them. Reopening on the same file started from a blank textarea.CommentPopoverbehind an opt-indraftKeyprop so existing call sites that don't want draft persistence are unaffected.AllFilesDiffViewandDiffViewer— withdraftKey={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 buildEscapeand the X close button — draft restored in both cases