Skip to content

Keep local review comments when switching Markdown back to a diff - #170

Merged
cpojer merged 1 commit into
nkzw-tech:mainfrom
henryqdineen:hqd-preserve-review-comments-markdown-refresh
Sep 15, 2026
Merged

cpojer merged 1 commit into
nkzw-tech:mainfrom
henryqdineen:hqd-preserve-review-comments-markdown-refresh

Conversation

@henryqdineen

Copy link
Copy Markdown
Contributor

Clicking "View as Diff" on a Markdown file discarded every review comment in the session, including comments on unrelated files.

toggleMarkdownPreview calls onRefreshMarkdown when leaving preview mode for an editable working-tree section, so Markdown edits are flushed and the repository state is re-read. That refresh in refreshMarkdownFile then did setReviewComments(getReviewCommentsFromState(orderedState)). getReviewCommentsFromState only projects state.reviewComments, which holds backend comments and is populated for pull request sources. The refresh path only runs for working-tree and branch-working-tree sources, where that field is always empty, so the call replaced the entire comment list with [].

Locally created comments never set isReadOnly and live only in React state, so all of them were lost: comment on a few lines of a JS file, toggle a Markdown file to its diff, and the comments are gone.

This adds getRefreshedReviewComments, which merges the refreshed backend comments over the local ones via the existing mergeReviewComments helper. Backend comments still win on matching ids, and local comments survive the refresh. The other getReviewCommentsFromState call sites are deliberate full reloads (initial load, source switch, whitespace preference change) and are unchanged.

Testing

core/__tests__/review-comments.test.ts covers both directions: local comments (including empty drafts) survive a refresh that returns no backend comments, and read-only comments are replaced by the refreshed state. Both fail against the previous behavior. Also verified by hand in the app on a working tree with a JS and a Markdown file.

🤖 Generated with Claude Code

Toggling a Markdown file back to its diff refreshes the repository state to
pick up the edits. That refresh replaced the whole review comment list with
`getReviewCommentsFromState`, which only projects comments that come from the
backend. Working trees have none, so every locally created comment was
dropped, including comments on unrelated files.

Merge the refreshed comments over the local ones instead, so backend comments
still win on matching ids while local comments survive the refresh.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cpojer
cpojer merged commit 4c75ef8 into nkzw-tech:main Sep 15, 2026
1 check passed
@cpojer

cpojer commented Sep 15, 2026

Copy link
Copy Markdown
Member

Thank you! New release coming in a bit.

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