Skip to content

Commit 9eb2b6e

Browse files
juliusmarmingecodex
andcommitted
fix(web): hide stale PR state during branch switches
Co-authored-by: codex <[email protected]>
1 parent 3eff03d commit 9eb2b6e

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎apps/web/src/components/BranchToolbar.logic.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
resolveDraftEnvModeAfterBranchChange,
1010
resolveEffectiveEnvMode,
1111
resolveEnvModeLabel,
12+
resolveBranchToolbarPrBranch,
1213
resolveBranchToolbarValue,
1314
resolveLockedWorkspaceLabel,
1415
resolveLocalCheckoutBranchMismatch,
@@ -173,6 +174,35 @@ describe("resolveBranchToolbarValue", () => {
173174
});
174175
});
175176

177+
describe("resolveBranchToolbarPrBranch", () => {
178+
it("uses the explicit thread branch when it matches the displayed branch", () => {
179+
expect(
180+
resolveBranchToolbarPrBranch({
181+
activeThreadBranch: "feature/current",
182+
resolvedActiveBranch: "feature/current",
183+
}),
184+
).toBe("feature/current");
185+
});
186+
187+
it("hides PR state while an optimistic branch switch is in flight", () => {
188+
expect(
189+
resolveBranchToolbarPrBranch({
190+
activeThreadBranch: "feature/current",
191+
resolvedActiveBranch: "feature/next",
192+
}),
193+
).toBeNull();
194+
});
195+
196+
it("does not infer PR state without an explicit thread branch", () => {
197+
expect(
198+
resolveBranchToolbarPrBranch({
199+
activeThreadBranch: null,
200+
resolvedActiveBranch: "feature/current",
201+
}),
202+
).toBeNull();
203+
});
204+
});
205+
176206
describe("resolveLocalCheckoutBranchMismatch", () => {
177207
it("detects when a local thread is associated with a different branch than the checkout", () => {
178208
expect(

‎apps/web/src/components/BranchToolbar.logic.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ export function resolveBranchToolbarValue(input: {
156156
return currentGitBranch ?? activeThreadBranch;
157157
}
158158

159+
export function resolveBranchToolbarPrBranch(input: {
160+
activeThreadBranch: string | null;
161+
resolvedActiveBranch: string | null;
162+
}): string | null {
163+
return input.activeThreadBranch === input.resolvedActiveBranch ? input.activeThreadBranch : null;
164+
}
165+
159166
export function resolveLocalCheckoutBranchMismatch(input: {
160167
effectiveEnvMode: EnvMode;
161168
activeWorktreePath: string | null;

‎apps/web/src/components/BranchToolbarBranchSelector.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { parsePullRequestReference } from "../pullRequestReference";
3535
import { getSourceControlPresentation } from "../sourceControlPresentation";
3636
import {
3737
deriveLocalBranchNameFromRemoteRef,
38+
resolveBranchToolbarPrBranch,
3839
resolveBranchSelectionTarget,
3940
resolveBranchToolbarValue,
4041
resolveDraftEnvModeAfterBranchChange,
@@ -591,7 +592,10 @@ export function BranchToolbarBranchSelector({
591592

592593
// PR pill shown next to the branch selector when the active branch has one.
593594
const branchPr = resolveThreadPr({
594-
threadBranch: activeThreadBranch,
595+
threadBranch: resolveBranchToolbarPrBranch({
596+
activeThreadBranch,
597+
resolvedActiveBranch,
598+
}),
595599
gitStatus: branchStatusQuery.data ?? null,
596600
});
597601
const branchPrStatus = prStatusIndicator(branchPr, branchStatusQuery.data?.sourceControlProvider);

0 commit comments

Comments
 (0)