Skip to content

Commit b40c0f1

Browse files
t3dotggclaude
andcommitted
Fix banner intent gate: drop focus signal, scope hysteresis
Cursor Bugbot caught two real gating bugs: - ChatView autofocuses the composer on every thread open, so "composer focused" was always true and the banner showed during passive reading anyway. Draft content is now the only intent signal. - revealedBranchMismatchKey was never cleared, so a mismatch that resolved and later recurred bypassed the gate. The key now resets whenever the active mismatch changes or resolves. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent f64a69a commit b40c0f1

3 files changed

Lines changed: 21 additions & 32 deletions

File tree

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,32 +313,30 @@ describe("shouldShowBranchMismatchBanner", () => {
313313
const base = {
314314
hasMismatch: true,
315315
isDismissed: false,
316-
composerFocused: false,
317316
composerHasContent: false,
318317
wasShownForCurrentMismatch: false,
319318
};
320319

321-
it("stays hidden during passive browsing", () => {
320+
it("stays hidden during passive browsing (even though the composer autofocuses)", () => {
322321
expect(shouldShowBranchMismatchBanner(base)).toBe(false);
323322
});
324323

325-
it("shows on composer focus or content", () => {
326-
expect(shouldShowBranchMismatchBanner({ ...base, composerFocused: true })).toBe(true);
324+
it("shows once the composer has draft content", () => {
327325
expect(shouldShowBranchMismatchBanner({ ...base, composerHasContent: true })).toBe(true);
328326
});
329327

330-
it("stays mounted after blur once shown for the current mismatch", () => {
328+
it("stays mounted after the draft clears once shown for the current mismatch", () => {
331329
expect(shouldShowBranchMismatchBanner({ ...base, wasShownForCurrentMismatch: true })).toBe(
332330
true,
333331
);
334332
});
335333

336334
it("never shows when dismissed or without a mismatch", () => {
337335
expect(
338-
shouldShowBranchMismatchBanner({ ...base, composerFocused: true, isDismissed: true }),
336+
shouldShowBranchMismatchBanner({ ...base, composerHasContent: true, isDismissed: true }),
339337
).toBe(false);
340338
expect(
341-
shouldShowBranchMismatchBanner({ ...base, composerFocused: true, hasMismatch: false }),
339+
shouldShowBranchMismatchBanner({ ...base, composerHasContent: true, hasMismatch: false }),
342340
).toBe(false);
343341
});
344342
});

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,20 @@ export function branchMismatchKey(
301301

302302
// The mismatch banner only matters when the user is about to send: passive
303303
// 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.
304+
// covers ambient awareness). Draft content is the intent signal — composer
305+
// focus is useless here because ChatView autofocuses the composer on every
306+
// thread open. `wasShownForCurrentMismatch` keeps the banner mounted once
307+
// revealed so it doesn't flicker away when the draft is cleared.
306308
export function shouldShowBranchMismatchBanner(input: {
307309
hasMismatch: boolean;
308310
isDismissed: boolean;
309-
composerFocused: boolean;
310311
composerHasContent: boolean;
311312
wasShownForCurrentMismatch: boolean;
312313
}): boolean {
313314
if (!input.hasMismatch || input.isDismissed) {
314315
return false;
315316
}
316-
return input.composerFocused || input.composerHasContent || input.wasShownForCurrentMismatch;
317+
return input.composerHasContent || input.wasShownForCurrentMismatch;
317318
}
318319

319320
// Session-scoped (module-level so it survives ChatView remounts, e.g. route

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

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3825,9 +3825,8 @@ function ChatViewContent(props: ChatViewProps) {
38253825
);
38263826
const [isRestoringThreadBranch, setIsRestoringThreadBranch] = useState(false);
38273827
const [branchRestoreConfirmOpen, setBranchRestoreConfirmOpen] = useState(false);
3828-
const [composerIntentFocused, setComposerIntentFocused] = useState(false);
3829-
// Once revealed for a given mismatch, the banner stays mounted through
3830-
// composer blur so it doesn't flicker in and out while the user works.
3828+
// Once revealed for a given mismatch, the banner stays mounted until the
3829+
// mismatch changes or resolves, so clearing the draft doesn't flicker it.
38313830
const [revealedBranchMismatchKey, setRevealedBranchMismatchKey] = useState<string | null>(null);
38323831
// Dismissal lives in a module-level set (survives remounts); this tick just
38333832
// forces a re-render so the banner leaves immediately.
@@ -3851,15 +3850,19 @@ function ChatViewContent(props: ChatViewProps) {
38513850
const showBranchMismatchBanner = shouldShowBranchMismatchBanner({
38523851
hasMismatch: localCheckoutBranchMismatch !== null,
38533852
isDismissed: isBranchMismatchDismissedForSession(activeBranchMismatchKey),
3854-
composerFocused: composerIntentFocused,
38553853
composerHasContent: composerHasDraftContent,
38563854
wasShownForCurrentMismatch:
38573855
revealedBranchMismatchKey !== null && revealedBranchMismatchKey === activeBranchMismatchKey,
38583856
});
38593857
useEffect(() => {
3860-
if (showBranchMismatchBanner) {
3861-
setRevealedBranchMismatchKey(activeBranchMismatchKey);
3862-
}
3858+
setRevealedBranchMismatchKey((revealed) => {
3859+
if (showBranchMismatchBanner) {
3860+
return activeBranchMismatchKey;
3861+
}
3862+
// Hysteresis is scoped to an uninterrupted mismatch: reset when the
3863+
// mismatch resolves or changes so a recurrence re-gates on intent.
3864+
return revealed !== null && revealed !== activeBranchMismatchKey ? null : revealed;
3865+
});
38633866
}, [activeBranchMismatchKey, showBranchMismatchBanner]);
38643867
const handleSwitchCheckoutToThread = useCallback(async () => {
38653868
if (
@@ -5618,20 +5621,7 @@ function ChatViewContent(props: ChatViewProps) {
56185621
)}
56195622
>
56205623
<div className="chat-composer-glass-host relative z-10 w-full rounded-[22px]">
5621-
<div
5622-
ref={attachDraftHeroComposerAnchorRef}
5623-
className="relative z-10"
5624-
onFocusCapture={() => setComposerIntentFocused(true)}
5625-
onBlurCapture={(event) => {
5626-
if (
5627-
event.relatedTarget instanceof Node &&
5628-
event.currentTarget.contains(event.relatedTarget)
5629-
) {
5630-
return;
5631-
}
5632-
setComposerIntentFocused(false);
5633-
}}
5634-
>
5624+
<div ref={attachDraftHeroComposerAnchorRef} className="relative z-10">
56355625
<ChatComposer
56365626
composerRef={composerRef}
56375627
composerDraftTarget={composerDraftTarget}

0 commit comments

Comments
 (0)