Skip to content

Commit 3cb03a1

Browse files
fix(web): PR panel attention pulse stays scoped to the thread
Switching threads kept the prior attention baseline, so the same PR surface with a different request id pulsed without a click. Scope the baseline by the panel's width storage key, and drop the redundant store reopen case now covered by the existing surface-tracking test. Co-authored-by: Cursor <[email protected]>
1 parent 2a04a5b commit 3cb03a1

3 files changed

Lines changed: 86 additions & 41 deletions

File tree

‎apps/web/src/components/RightPanelTabs.test.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EnvironmentId, type ThreadPullRequestLink } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

44
import {
5+
nextPullRequestAttentionPulse,
56
resolvePullRequestTabLink,
67
surfaceShortcutActionForKey,
78
surfaceShortcutTargetsTypingContext,
@@ -167,3 +168,37 @@ describe("pull request tab snapshots", () => {
167168
).toBe(newer);
168169
});
169170
});
171+
172+
describe("pull request attention pulse", () => {
173+
const baseline = {
174+
scope: "thread-a",
175+
surfaceId: "pull-request:project:repo:1",
176+
requestId: 2,
177+
key: 0,
178+
};
179+
180+
it("pulses when the focused PR's attention id bumps in the same panel", () => {
181+
expect(
182+
nextPullRequestAttentionPulse(baseline, {
183+
scope: "thread-a",
184+
id: "pull-request:project:repo:1",
185+
requestId: 3,
186+
}),
187+
).toEqual({ ...baseline, requestId: 3, key: 1 });
188+
});
189+
190+
it("baselines without pulsing when the panel scope changes for the same PR", () => {
191+
expect(
192+
nextPullRequestAttentionPulse(baseline, {
193+
scope: "thread-b",
194+
id: "pull-request:project:repo:1",
195+
requestId: 5,
196+
}),
197+
).toEqual({
198+
scope: "thread-b",
199+
surfaceId: "pull-request:project:repo:1",
200+
requestId: 5,
201+
key: 0,
202+
});
203+
});
204+
});

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

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,44 +1022,67 @@ function RightPanelTab(
10221022
);
10231023
}
10241024

1025+
export type PullRequestAttentionPulse = {
1026+
scope: string | null;
1027+
surfaceId: string | null;
1028+
requestId: number;
1029+
key: number;
1030+
};
1031+
1032+
/** Same focused PR in the same panel with a bumped request id → pulse; a new scope only baselines. */
1033+
export function nextPullRequestAttentionPulse(
1034+
current: PullRequestAttentionPulse,
1035+
focused: { scope: string; id: string; requestId: number } | null,
1036+
): PullRequestAttentionPulse {
1037+
if (focused === null) {
1038+
return current.surfaceId === null && current.scope === null
1039+
? current
1040+
: { scope: null, surfaceId: null, requestId: 0, key: current.key };
1041+
}
1042+
const sameSurface = current.scope === focused.scope && current.surfaceId === focused.id;
1043+
if (sameSurface && current.requestId !== focused.requestId) {
1044+
return {
1045+
scope: focused.scope,
1046+
surfaceId: focused.id,
1047+
requestId: focused.requestId,
1048+
key: current.key + 1,
1049+
};
1050+
}
1051+
if (!sameSurface || current.requestId !== focused.requestId) {
1052+
return {
1053+
scope: focused.scope,
1054+
surfaceId: focused.id,
1055+
requestId: focused.requestId,
1056+
key: current.key,
1057+
};
1058+
}
1059+
return current;
1060+
}
1061+
10251062
export function RightPanelTabs(props: RightPanelTabsProps) {
10261063
const focusedSurface = props.surfaces.find((surface) => surface.id === props.activeSurfaceId);
1064+
// widthStorageKey is per-thread in chat, so a thread switch does not inherit the prior baseline.
1065+
const attentionScope = props.widthStorageKey ?? props.environmentId ?? "";
10271066
const focusedPullRequestAttention =
10281067
focusedSurface?.kind === "pull-request"
1029-
? { id: focusedSurface.id, requestId: focusedSurface.attentionRequestId ?? 0 }
1068+
? {
1069+
scope: attentionScope,
1070+
id: focusedSurface.id,
1071+
requestId: focusedSurface.attentionRequestId ?? 0,
1072+
}
10301073
: null;
1031-
// Same PR still focused with a bumped request id: the link did something; pulse the panel.
10321074
const [pullRequestAttentionPulse, setPullRequestAttentionPulse] = useState({
1075+
scope: null as string | null,
10331076
surfaceId: null as string | null,
10341077
requestId: 0,
10351078
key: 0,
10361079
});
1037-
if (focusedPullRequestAttention) {
1038-
if (
1039-
pullRequestAttentionPulse.surfaceId === focusedPullRequestAttention.id &&
1040-
pullRequestAttentionPulse.requestId !== focusedPullRequestAttention.requestId
1041-
) {
1042-
setPullRequestAttentionPulse({
1043-
surfaceId: focusedPullRequestAttention.id,
1044-
requestId: focusedPullRequestAttention.requestId,
1045-
key: pullRequestAttentionPulse.key + 1,
1046-
});
1047-
} else if (
1048-
pullRequestAttentionPulse.surfaceId !== focusedPullRequestAttention.id ||
1049-
pullRequestAttentionPulse.requestId !== focusedPullRequestAttention.requestId
1050-
) {
1051-
setPullRequestAttentionPulse({
1052-
surfaceId: focusedPullRequestAttention.id,
1053-
requestId: focusedPullRequestAttention.requestId,
1054-
key: pullRequestAttentionPulse.key,
1055-
});
1056-
}
1057-
} else if (pullRequestAttentionPulse.surfaceId !== null) {
1058-
setPullRequestAttentionPulse({
1059-
surfaceId: null,
1060-
requestId: 0,
1061-
key: pullRequestAttentionPulse.key,
1062-
});
1080+
const nextAttentionPulse = nextPullRequestAttentionPulse(
1081+
pullRequestAttentionPulse,
1082+
focusedPullRequestAttention,
1083+
);
1084+
if (nextAttentionPulse !== pullRequestAttentionPulse) {
1085+
setPullRequestAttentionPulse(nextAttentionPulse);
10631086
}
10641087
const ownsDesktopTitleBar = isElectron && props.mode === "inline";
10651088
const browserProfiles = useBrowserDefaults().profiles;

‎apps/web/src/rightPanelStore.test.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,19 +1015,6 @@ describe("rightPanelStore", () => {
10151015
expect(state.surfaces[1]).not.toHaveProperty("url");
10161016
});
10171017

1018-
it("bumps attention when reopening the pull request already in the panel", () => {
1019-
const pr = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
1020-
useRightPanelStore.getState().openPullRequest(refA, pr);
1021-
expect(
1022-
selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA),
1023-
).toMatchObject({ attentionRequestId: 1 });
1024-
1025-
useRightPanelStore.getState().openPullRequest(refA, pr);
1026-
expect(
1027-
selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA),
1028-
).toMatchObject({ attentionRequestId: 2 });
1029-
});
1030-
10311018
it("restores each environment, thread and PR surface's detail tab after reload and URL reopen", async () => {
10321019
const pr = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
10331020
const otherPr = { ...pr, projectId: "project-b" };

0 commit comments

Comments
 (0)