Skip to content

feat(code-review): mark files as viewed in diff review#2762

Open
MattPua wants to merge 10 commits into
mainfrom
posthog-code/add-mark-file-as-read-in-pr-review
Open

feat(code-review): mark files as viewed in diff review#2762
MattPua wants to merge 10 commits into
mainfrom
posthog-code/add-mark-file-as-read-in-pr-review

Conversation

@MattPua

@MattPua MattPua commented Jun 18, 2026

Copy link
Copy Markdown
Member

Problem

When reviewing a diff there's no way to track which files you've already looked at, no signal when a file changes after you've reviewed it, and nothing to get reviewed files out of the way.

Changes

CleanShot.2026-06-18.at.15.53.53.mp4
  • Adds a Read checkbox to each file header in the diff/review viewer
  • Marking a file read collapses it; unmarking expands it (like GitHub)
  • Already-read files auto-collapse when you reopen the panel
  • If a file changes after you marked it read, it shows a Changed badge (and stays expanded) so you know to look again
  • Shows a read count (read / total) next to the file count
  • Read state is saved per task and survives restarts, across local, branch, PR, and cloud diffs
  • Read state is cleared when a task is archived or its PR is merged, with a size cap so storage stays bounded

How did you test this?

  • Unit tests for the read-state store (mark/unmark, clearing, size-cap eviction) and the change-detection signatures
  • pnpm --filter @posthog/ui typecheck and biome lint pass on the changed files (the one remaining typecheck error is a pre-existing, unrelated issue in canvas/WebsiteLayout.tsx)
  • Not yet exercised in the running app

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

Add a togglable "Viewed" checkbox, right-aligned in each file header in
the review/diff viewer. Marking a file viewed also collapses it (mirrors
GitHub); unmarking re-expands it.

State is local + persisted, keyed by taskId -> file key, so it works
across all diff sources (local, branch, PR, cloud) and survives restarts.

Note: pre-commit hook bypassed; monorepo typecheck fails on a pre-existing
error in canvas/WebsiteLayout.tsx (Button "loading" prop) from main,
unrelated to this change.

Generated-By: PostHog Code
Task-Id: ea2a1d14-f772-40f5-bd7d-3799f77e31b4
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

React Doctor found 5 issues in 2 files · 5 warnings.

5 warnings

src/features/code-review/components/ReviewShell.tsx

src/features/code-review/reviewShellParts.tsx

Reviewed by React Doctor for commit 8b93513.

@MattPua MattPua marked this pull request as draft June 18, 2026 18:43
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
packages/ui/src/features/code-review/reviewShellParts.tsx:206-241
**Nested `<button>` inside `<button>` — invalid HTML**

`FileHeaderRow` renders a `<button>` (line 206) and `ViewedCheckbox` renders another `<button>` inside it (line 251). Nesting interactive elements inside a `<button>` is prohibited by the HTML spec. While React's synthetic event system makes `e.stopPropagation()` work in practice, the resulting DOM is invalid and screen readers / keyboard-navigation tools may behave unpredictably (e.g. some AT software flattens or skips the inner button). A straightforward fix is to change `FileHeaderRow`'s root element to a `<div>` with `role="button"` and `tabIndex={0}`, or to restructure the layout so the viewed checkbox sits adjacent to rather than inside the collapse button.

### Issue 2 of 2
packages/ui/src/features/code-review/reviewViewedStore.ts:28-33
**`clearTask` is defined but never called — store grows unbounded**

The persisted store accumulates a `taskId → fileKey → true` entry for every task the user ever reviews and never prunes them. Over time this silently inflates the `localStorage` entry for `"review-viewed-storage"`. Consider calling `clearTask` when a task is deleted or archived, or add a storage migration / TTL that removes entries older than a configurable window.

Reviews (1): Last reviewed commit: "feat(code-review): mark files as viewed ..." | Re-trigger Greptile

Comment thread packages/ui/src/features/code-review/reviewShellParts.tsx Outdated
Comment thread packages/ui/src/features/code-review/reviewViewedStore.ts Outdated
MattPua added 9 commits June 18, 2026 14:48
- FileHeaderRow: wrap only the toggle target in a button; open-file and
  viewed controls are now siblings, not nested interactive elements
- reviewViewedStore: bound the persisted store via LRU eviction
  (MAX_TASKS) and drop tasks with no viewed files; remove unused clearTask

Generated-By: PostHog Code
Task-Id: ea2a1d14-f772-40f5-bd7d-3799f77e31b4
Store a content signature when a file is marked read and compare it
against the current diff to surface a "Changed" state. Rename the
user-facing control to "read". Bound persisted state with archival
pruning plus an LRU backstop, memoize signatures by file identity, and
skip pruning the task whose review is open.

Generated-By: PostHog Code
Task-Id: c2ac4ecc-f009-4e38-91fb-81f17ccfd91b
… merges

Archived tasks won't be re-reviewed, so drop their persisted read state as
part of the archive orchestration (covers single and bulk). Likewise clear
it once the reviewed task's PR is merged. Adds a clearTask action to the
review-viewed store.

Generated-By: PostHog Code
Task-Id: c2ac4ecc-f009-4e38-91fb-81f17ccfd91b
Display "<read>/<total> read" next to the file count in the review toolbar,
counting only files marked read at their current signature. Lower the
persisted-size backstop from 4000 to 500 entries.

Generated-By: PostHog Code
Task-Id: c2ac4ecc-f009-4e38-91fb-81f17ccfd91b
Generated-By: PostHog Code
Task-Id: c2ac4ecc-f009-4e38-91fb-81f17ccfd91b
…e local read signature

- ReviewShell passed a bare Task to useTaskPrStatus, so cloudPrUrl/
  taskRunEnvironment were undefined and the PR-merge read-state clear never
  fired for cloud tasks. Resolve cloudPrUrl via useCloudPrUrl and pass the run
  environment, matching the other useTaskPrStatus call sites.
- Local read signatures hashed parsed hunks, which change when the
  hide-whitespace toggle re-fetches a different diff, falsely flipping read
  files to "Changed". Base the signature on the git blob object ids from the
  patch index line instead: content-identifying and unaffected by the toggle
  (falls back to hunk geometry when absent).

Generated-By: PostHog Code
Task-Id: c2ac4ecc-f009-4e38-91fb-81f17ccfd91b
…Tasks action

clearTask(id) and pruneArchived([id]) did the same single-key delete, and
"pruneArchived" read wrong for the merge path. Collapse both into a single
clearTasks(ids) action used by archive, merge, and the archived-task backstop.

Generated-By: PostHog Code
Task-Id: c2ac4ecc-f009-4e38-91fb-81f17ccfd91b
…isFileRead, cap 250

- Add unit tests for reviewViewedStore (mark/unmark, clearTasks, entry-cap
  eviction + active-task retention) and the signature helpers (patch hash,
  blob-id preference / whitespace stability, fallbacks).
- Keep currentSignatures' reference stable across collapse toggles so toggling
  one file no longer re-renders every ViewedCheckbox via context.
- Extract isFileRead() so the toolbar count and the checkbox share one predicate.
- Raise the persisted-entry backstop from 150 to 250.

Generated-By: PostHog Code
Task-Id: c2ac4ecc-f009-4e38-91fb-81f17ccfd91b
Collapse state is ephemeral while read state persists, so previously-read
files came back expanded on each open. On the first open per task (once
signatures load), collapse files whose stored signature still matches —
mirroring GitHub. Changed-since-read files stay expanded, and the one-shot
guard means manually re-expanding a read file afterwards sticks.

Generated-By: PostHog Code
Task-Id: c2ac4ecc-f009-4e38-91fb-81f17ccfd91b
@MattPua MattPua marked this pull request as ready for review June 18, 2026 20:05
@MattPua MattPua requested review from a team and charlesvien June 18, 2026 20:05
@charlesvien charlesvien requested a review from adboio June 18, 2026 20:10
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "feat(code-review): auto-collapse already..." | Re-trigger Greptile

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.

1 participant