Skip to content

Commit f64a69a

Browse files
t3dotggclaude
andcommitted
Calm down the branch-mismatch banner
The "You're on a different branch" warning fired the moment a mismatched thread was opened, wasn't dismissible, and treated routine branch switching as an anomaly. Reworked per user feedback: - Copy is now a one-line fragment: "Branch changed — was <branch>", info variant with a git-branch icon. The consequence ("sending will continue on the current branch") lives in the chip tooltip. - Banner only renders on send intent (composer focused or has draft content); passive browsing shows nothing beyond the existing branch-picker tint. Once revealed it stays mounted for the current mismatch so it doesn't flicker on blur. - "Move thread here" is gone — sending already rebinds the thread. The single action is "Restore branch", with a confirm dialog only when the working tree has uncommitted changes. - Dismissible, keyed on threadId + both branches, session-scoped for now (server-persisted cross-device ack is a planned follow-up). Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 67a7b1a commit f64a69a

3 files changed

Lines changed: 248 additions & 87 deletions

File tree

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ import type { Thread } from "../types";
1212
import {
1313
MAX_HIDDEN_MOUNTED_PREVIEW_THREADS,
1414
MAX_HIDDEN_MOUNTED_TERMINAL_THREADS,
15+
branchMismatchKey,
1516
buildExpiredTerminalContextToastCopy,
1617
buildThreadTurnInterruptInput,
1718
createLocalDispatchSnapshot,
1819
deriveComposerSendState,
20+
dismissBranchMismatchForSession,
1921
getStartedThreadModelChangeBlockReason,
2022
hasServerAcknowledgedLocalDispatch,
23+
isBranchMismatchDismissedForSession,
2124
reconcileMountedTerminalThreadIds,
2225
reconcileRetainedMountedThreadIds,
2326
resolveThreadMetadataUpdateForNextTurn,
2427
resolveSendEnvMode,
28+
shouldShowBranchMismatchBanner,
2529
shouldWriteThreadErrorToCurrentServerThread,
2630
} from "./ChatView.logic";
2731

@@ -292,6 +296,63 @@ describe("resolveSendEnvMode", () => {
292296
});
293297
});
294298

299+
describe("branchMismatchKey", () => {
300+
it("builds a key from thread id and both branches", () => {
301+
expect(branchMismatchKey("thread-1", { threadBranch: "feat/a", currentBranch: "feat/b" })).toBe(
302+
"thread-1:feat/a:feat/b",
303+
);
304+
});
305+
306+
it("returns null without a thread or mismatch", () => {
307+
expect(branchMismatchKey(null, { threadBranch: "a", currentBranch: "b" })).toBeNull();
308+
expect(branchMismatchKey("thread-1", null)).toBeNull();
309+
});
310+
});
311+
312+
describe("shouldShowBranchMismatchBanner", () => {
313+
const base = {
314+
hasMismatch: true,
315+
isDismissed: false,
316+
composerFocused: false,
317+
composerHasContent: false,
318+
wasShownForCurrentMismatch: false,
319+
};
320+
321+
it("stays hidden during passive browsing", () => {
322+
expect(shouldShowBranchMismatchBanner(base)).toBe(false);
323+
});
324+
325+
it("shows on composer focus or content", () => {
326+
expect(shouldShowBranchMismatchBanner({ ...base, composerFocused: true })).toBe(true);
327+
expect(shouldShowBranchMismatchBanner({ ...base, composerHasContent: true })).toBe(true);
328+
});
329+
330+
it("stays mounted after blur once shown for the current mismatch", () => {
331+
expect(shouldShowBranchMismatchBanner({ ...base, wasShownForCurrentMismatch: true })).toBe(
332+
true,
333+
);
334+
});
335+
336+
it("never shows when dismissed or without a mismatch", () => {
337+
expect(
338+
shouldShowBranchMismatchBanner({ ...base, composerFocused: true, isDismissed: true }),
339+
).toBe(false);
340+
expect(
341+
shouldShowBranchMismatchBanner({ ...base, composerFocused: true, hasMismatch: false }),
342+
).toBe(false);
343+
});
344+
});
345+
346+
describe("session branch mismatch dismissal", () => {
347+
it("tracks dismissed keys and treats other keys as active", () => {
348+
expect(isBranchMismatchDismissedForSession("t1:a:b")).toBe(false);
349+
dismissBranchMismatchForSession("t1:a:b");
350+
expect(isBranchMismatchDismissedForSession("t1:a:b")).toBe(true);
351+
expect(isBranchMismatchDismissedForSession("t1:a:c")).toBe(false);
352+
expect(isBranchMismatchDismissedForSession(null)).toBe(false);
353+
});
354+
});
355+
295356
describe("reconcileMountedTerminalThreadIds", () => {
296357
it("keeps open threads and makes the active thread most recent", () => {
297358
expect(

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,45 @@ export function buildExpiredTerminalContextToastCopy(
289289
};
290290
}
291291

292+
export function branchMismatchKey(
293+
threadId: string | null,
294+
mismatch: { threadBranch: string; currentBranch: string } | null,
295+
): string | null {
296+
if (!threadId || !mismatch) {
297+
return null;
298+
}
299+
return `${threadId}:${mismatch.threadBranch}:${mismatch.currentBranch}`;
300+
}
301+
302+
// The mismatch banner only matters when the user is about to send: passive
303+
// reading of an old thread carries no risk (the branch picker tint already
304+
// covers ambient awareness). `wasShownForCurrentMismatch` keeps the banner
305+
// mounted once revealed so it doesn't flicker away when the composer blurs.
306+
export function shouldShowBranchMismatchBanner(input: {
307+
hasMismatch: boolean;
308+
isDismissed: boolean;
309+
composerFocused: boolean;
310+
composerHasContent: boolean;
311+
wasShownForCurrentMismatch: boolean;
312+
}): boolean {
313+
if (!input.hasMismatch || input.isDismissed) {
314+
return false;
315+
}
316+
return input.composerFocused || input.composerHasContent || input.wasShownForCurrentMismatch;
317+
}
318+
319+
// Session-scoped (module-level so it survives ChatView remounts, e.g. route
320+
// changes). Durable cross-device dismissal is planned as a server-side ack.
321+
const sessionDismissedBranchMismatchKeys = new Set<string>();
322+
323+
export function dismissBranchMismatchForSession(key: string): void {
324+
sessionDismissedBranchMismatchKeys.add(key);
325+
}
326+
327+
export function isBranchMismatchDismissedForSession(key: string | null): boolean {
328+
return key !== null && sessionDismissedBranchMismatchKeys.has(key);
329+
}
330+
292331
export function threadHasStarted(thread: Thread | null | undefined): boolean {
293332
return Boolean(
294333
thread && (thread.latestTurn !== null || thread.messages.length > 0 || thread.session !== null),

0 commit comments

Comments
 (0)