Skip to content

Commit d3924bd

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 ef296f6 commit d3924bd

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
@@ -1026,44 +1026,67 @@ function RightPanelTab(
10261026
);
10271027
}
10281028

1029+
export type PullRequestAttentionPulse = {
1030+
scope: string | null;
1031+
surfaceId: string | null;
1032+
requestId: number;
1033+
key: number;
1034+
};
1035+
1036+
/** Same focused PR in the same panel with a bumped request id → pulse; a new scope only baselines. */
1037+
export function nextPullRequestAttentionPulse(
1038+
current: PullRequestAttentionPulse,
1039+
focused: { scope: string; id: string; requestId: number } | null,
1040+
): PullRequestAttentionPulse {
1041+
if (focused === null) {
1042+
return current.surfaceId === null && current.scope === null
1043+
? current
1044+
: { scope: null, surfaceId: null, requestId: 0, key: current.key };
1045+
}
1046+
const sameSurface = current.scope === focused.scope && current.surfaceId === focused.id;
1047+
if (sameSurface && current.requestId !== focused.requestId) {
1048+
return {
1049+
scope: focused.scope,
1050+
surfaceId: focused.id,
1051+
requestId: focused.requestId,
1052+
key: current.key + 1,
1053+
};
1054+
}
1055+
if (!sameSurface || current.requestId !== focused.requestId) {
1056+
return {
1057+
scope: focused.scope,
1058+
surfaceId: focused.id,
1059+
requestId: focused.requestId,
1060+
key: current.key,
1061+
};
1062+
}
1063+
return current;
1064+
}
1065+
10291066
export function RightPanelTabs(props: RightPanelTabsProps) {
10301067
const focusedSurface = props.surfaces.find((surface) => surface.id === props.activeSurfaceId);
1068+
// widthStorageKey is per-thread in chat, so a thread switch does not inherit the prior baseline.
1069+
const attentionScope = props.widthStorageKey ?? props.environmentId ?? "";
10311070
const focusedPullRequestAttention =
10321071
focusedSurface?.kind === "pull-request"
1033-
? { id: focusedSurface.id, requestId: focusedSurface.attentionRequestId ?? 0 }
1072+
? {
1073+
scope: attentionScope,
1074+
id: focusedSurface.id,
1075+
requestId: focusedSurface.attentionRequestId ?? 0,
1076+
}
10341077
: null;
1035-
// Same PR still focused with a bumped request id: the link did something; pulse the panel.
10361078
const [pullRequestAttentionPulse, setPullRequestAttentionPulse] = useState({
1079+
scope: null as string | null,
10371080
surfaceId: null as string | null,
10381081
requestId: 0,
10391082
key: 0,
10401083
});
1041-
if (focusedPullRequestAttention) {
1042-
if (
1043-
pullRequestAttentionPulse.surfaceId === focusedPullRequestAttention.id &&
1044-
pullRequestAttentionPulse.requestId !== focusedPullRequestAttention.requestId
1045-
) {
1046-
setPullRequestAttentionPulse({
1047-
surfaceId: focusedPullRequestAttention.id,
1048-
requestId: focusedPullRequestAttention.requestId,
1049-
key: pullRequestAttentionPulse.key + 1,
1050-
});
1051-
} else if (
1052-
pullRequestAttentionPulse.surfaceId !== focusedPullRequestAttention.id ||
1053-
pullRequestAttentionPulse.requestId !== focusedPullRequestAttention.requestId
1054-
) {
1055-
setPullRequestAttentionPulse({
1056-
surfaceId: focusedPullRequestAttention.id,
1057-
requestId: focusedPullRequestAttention.requestId,
1058-
key: pullRequestAttentionPulse.key,
1059-
});
1060-
}
1061-
} else if (pullRequestAttentionPulse.surfaceId !== null) {
1062-
setPullRequestAttentionPulse({
1063-
surfaceId: null,
1064-
requestId: 0,
1065-
key: pullRequestAttentionPulse.key,
1066-
});
1084+
const nextAttentionPulse = nextPullRequestAttentionPulse(
1085+
pullRequestAttentionPulse,
1086+
focusedPullRequestAttention,
1087+
);
1088+
if (nextAttentionPulse !== pullRequestAttentionPulse) {
1089+
setPullRequestAttentionPulse(nextAttentionPulse);
10671090
}
10681091
const ownsDesktopTitleBar = isElectron && props.mode === "inline";
10691092
const browserProfiles = useBrowserDefaults().profiles;

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,19 +1054,6 @@ describe("rightPanelStore", () => {
10541054
expect(surface()).not.toHaveProperty("revealUrl");
10551055
});
10561056

1057-
it("bumps attention when reopening the pull request already in the panel", () => {
1058-
const pr = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
1059-
useRightPanelStore.getState().openPullRequest(refA, pr);
1060-
expect(
1061-
selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA),
1062-
).toMatchObject({ attentionRequestId: 1 });
1063-
1064-
useRightPanelStore.getState().openPullRequest(refA, pr);
1065-
expect(
1066-
selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA),
1067-
).toMatchObject({ attentionRequestId: 2 });
1068-
});
1069-
10701057
it("restores each environment, thread and PR surface's detail tab after reload and URL reopen", async () => {
10711058
const pr = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
10721059
const otherPr = { ...pr, projectId: "project-b" };

0 commit comments

Comments
 (0)