Skip to content

fix(code-review): refresh staged/unstaged diffs on index changes#2202

Open
adboio wants to merge 1 commit into
mainfrom
posthog-code/fix-staged-unstaged-diff-refresh
Open

fix(code-review): refresh staged/unstaged diffs on index changes#2202
adboio wants to merge 1 commit into
mainfrom
posthog-code/fix-staged-unstaged-diff-refresh

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented May 18, 2026

Summary

  • External git operations (terminal git add, commits, etc.) write .git/index but the file watcher's onGitStateChanged handler only invalidated branch queries, so cached getDiffCached and getDiffUnstaged results stayed stale. The Local Review viewer kept showing the previous staged version after staging through the terminal.
  • Dropped the hasStagedFiles gate on getDiffCached so the staged section appears/disappears in lockstep with the query result rather than racing the changed-files query (which is itself gated by isActive since feat: virtualized and optimized diff rendering #2113).

Repro before fix

  1. Edit fileX, git add fileX, then edit fileX again so it has both staged and unstaged changes.
  2. Open the Review tab — only the staged version shows; the unstaged entry is missing or stale.
  3. Run git add fileX from the terminal — viewer keeps showing the prior split instead of collapsing into a single combined staged diff.

Test plan

  • pnpm dev, open a local repo task
  • Make staged + unstaged changes to the same file via terminal — both sections render with that file
  • Run git add <file> in the terminal while the Review tab is open — the "Changes" section drops the file and "Staged Changes" updates to include the combined diff
  • In-app stage/unstage button (+ in Changes panel) still works
  • pnpm --filter code typecheck passes
  • pnpm --filter code test passes

Created with PostHog Code

External git operations (terminal `git add`, commits) write `.git/index`
but the file watcher's `onGitStateChanged` handler only invalidated
branch-related queries, leaving the cached `getDiffCached` and
`getDiffUnstaged` results stale. The renderer kept showing the previous
staged version even after the index changed.

Also drop the `hasStagedFiles` gate on `getDiffCached` so the staged
section appears/disappears in lockstep with the query result rather than
racing against a separately-derived flag from `changedFiles`.

Generated-By: PostHog Code
Task-Id: 4d1b802b-2174-457f-84f1-6d969eab2e34
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 18, 2026

Reviews (1): Last reviewed commit: "fix(code-review): refresh staged/unstage..." | 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