fix(git): reflect in-place branch checkout#3760
Conversation
|
😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details. |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Generated-By: PostHog Code Task-Id: 255e673e-95cb-4359-93b7-23521296cc34
12c18e0 to
b1326e5
Compare
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/ui/src/features/git-interaction/components/BranchSelector.tsx:233-237
**Retained checkout masks prop updates**
When the current branch changes again for the same repository after a successful in-place checkout, the retained mutation result continues taking precedence over `currentBranch`, causing the selector to remain stuck on the earlier branch.
Reviews (1): Last reviewed commit: "fix(git): reflect in-place branch checko..." | Re-trigger Greptile |
|
Note 🤖 stamphog reviewed Greptile's unresolved review comment identifies a real, unaddressed bug: the new checkedOutBranch logic keeps showing the stale mutation result whenever repoPath matches, so a later currentBranch prop change is masked — reintroducing the same stale-display bug class this PR claims to fix.
Gate mechanics and policy version
|
|
The bug is real. Looking at lines 233-237: const checkedOutBranch =
checkoutMutation.data &&
checkoutMutation.variables.directoryPath === repoPath
? checkoutMutation.data.currentBranch
: currentBranch;Once The fix is to stop preferring mutation data once Add a ref: const preCheckoutBranchRef = useRef<string | null>(null);Capture it before mutating (in preCheckoutBranchRef.current = currentBranch;
checkoutMutation.mutate({
directoryPath: repoPath as string,
branchName,
});Then update the derived value: This way:
A test covering the "subsequent prop change after checkout" case (checking out branch A, then receiving |
Generated-By: PostHog Code Task-Id: 93cd97d8-a251-49d7-a021-8010439e4108
There was a problem hiding this comment.
Contained UI bug fix to branch-selector display logic with an added regression test; the diff's new previousBranch-comparison guard directly resolves the reviewer's "retained checkout masks prop updates" concern, and the change sits outside risky territory.
- 👍 on the PR from greptile-apps[bot].
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 9L, 1F substantive, 80L/2F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1b-small (80L, 2F, single-area, fix) |
| stamphog 2.0.0b3 | .stamphog/policy.yml @ 0d728bc · reviewed head 1f5dab3 |
Problem
Switching branches from the task header succeeded, but the selector continued showing stale workspace metadata.
Changes
How did you test this?
pnpm --filter @posthog/ui test -- packages/ui/src/features/git-interaction/components/BranchSelector.test.tsx(1,998 tests passed)pnpm --filter @posthog/ui typecheckpnpm biome check packages/ui/src/features/git-interaction/components/BranchSelector.tsx packages/ui/src/features/git-interaction/components/BranchSelector.test.tsxpnpm typecheckAutomatic notifications
Created with PostHog Code