The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 22:00 UTC
fix(web): remember the pull request tab when switching threads (#18823)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
SamuelBarnholdt committed
Oct 19, 2026 at 22:35 UTC
adda1db10ca19f8de98bdba04e3fb19c2c939e09
5 files changed
+211
-18
apps/web/src/components/chat/RightPanelSurfaceContent.tsx
+5
-1
@@ -130,7 +130,7 @@ export function RightPanelSurfaceContent(props: {
130
<PullRequestDetailPanel
131
getShortcutContext={props.getShortcutContext}
132
shortcutsEnabled={visible && props.activeSurfaceId === surface.id}
133
- key={`${surface.host ?? ""}:${surface.repository}#${surface.number}`}
133
+ key={`${scopedThreadKey(threadRef)}:${surface.id}`}
134
environmentId={props.environmentId}
135
onSelectPullRequest={(reference) => {
136
useRightPanelStore.getState().openPullRequest(threadRef, {
@@ -147,6 +147,10 @@ export function RightPanelSurfaceContent(props: {
147
repository: surface.repository,
148
number: surface.number,
149
}}
150
+ initialTab={surface.detailTab ?? "summary"}
151
+ onTabChange={(tab) => {
152
+ useRightPanelStore.getState().setPullRequestDetailTab(threadRef, surface.id, tab);
153
+ }}
154
context={pullRequestPanelContext(
155
{
156
projectId: pullRequest.projectId,
apps/web/src/components/pullRequest/PullRequestDetailPanel.browser.test.tsx
+91
@@ -15,6 +15,8 @@ import { createRoot, type Root } from "react-dom/client";
15
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
16
import { page, userEvent } from "vite-plus/test/browser";
17
import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
18
+import { selectActiveRightPanelSurface, useRightPanelStore } from "~/rightPanelStore";
19
+import { RightPanelSurfaceContent } from "../chat/RightPanelSurfaceContent";
20
21
import "~/index.css";
22
@@ -259,6 +261,7 @@ beforeEach(() => {
261
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
262
currentDetail = detail;
263
useComposerDraftStore.setState({ draftsByThreadKey: {} });
264
+ useRightPanelStore.setState({ byThreadKey: {} });
265
usePullRequestReviewStore.setState({ drafts: {}, summaries: {} });
266
hostCommand.mockReset();
267
newThread
@@ -542,6 +545,94 @@ it("folds the title only for the active tab's own scroller", async () => {
545
await vi.waitFor(() => expect(titleFold()).toBe(true));
546
});
547
548
+it("restores the selected PR tab when switching threads and remounting the right panel", async () => {
549
+ const otherThread = { ...threadRef, threadId: ThreadId.make("thread-2") };
550
+ useRightPanelStore.getState().openPullRequest(threadRef, surface);
551
+ useRightPanelStore.getState().openPullRequest(otherThread, surface);
552
+ const codeTab = () => page.getByRole("button", { name: "Expand all files", exact: true });
553
+ const container = document.createElement("div");
554
+ container.className = "flex h-[700px] w-[900px]";
555
+ document.body.append(container);
556
+ const root = createRoot(container);
557
+ roots.push(root);
558
+ const show = (ref: ScopedThreadRef) => {
559
+ const selected = selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, ref);
560
+ return act(async () => {
561
+ root.render(
562
+ <RightPanelSurfaceContent
563
+ surface={selected}
564
+ activeSurfaceId={selected?.id ?? null}
565
+ threadRef={ref}
566
+ environmentId={ref.environmentId}
567
+ visible
568
+ composerDraftTarget={ref}
569
+ keybindings={[]}
570
+ configuredPreviewUrls={[]}
571
+ workspaceMutationId={null}
572
+ getShortcutContext={shortcutContext}
573
+ onSendAnnotation={() => {}}
574
+ onCloseSurface={() => {}}
575
+ terminal={{
576
+ launchContext: null,
577
+ focusRequestId: 0,
578
+ keybindings: [],
579
+ onAddTerminalContext: () => {},
580
+ onSplitTerminal: () => {},
581
+ onSplitTerminalVertical: () => {},
582
+ onNewTerminal: () => {},
583
+ onActiveTerminalChange: () => {},
584
+ onCloseTerminal: () => {},
585
+ }}
586
+ pullRequest={{
587
+ capabilityKnown: true,
588
+ supported: true,
589
+ projectId: detail.projectId,
590
+ pullRequests: [],
591
+ linkedPullRequest: null,
592
+ branchPullRequest: null,
593
+ onBack: undefined,
594
+ }}
595
+ files={{
596
+ projectName: null,
597
+ workspaceRoot: undefined,
598
+ availableEditors: [],
599
+ pendingSurfaceIds: new Set(),
600
+ onOpenFile: () => {},
601
+ onPendingChange: () => {},
602
+ }}
603
+ />,
604
+ );
605
+ });
606
+ };
607
+
608
+ await show(threadRef);
609
+ await expect.element(page.getByTestId("summary-scroller")).toBeVisible();
610
+ await tab("Code").click();
611
+ await expect.element(codeTab()).toBeVisible();
612
+ await show(otherThread);
613
+ await expect.element(page.getByTestId("summary-scroller")).toBeVisible();
614
+ await show(threadRef);
615
+ await expect.element(codeTab()).toBeVisible();
616
+
617
+ useRightPanelStore
618
+ .getState()
619
+ .openPullRequest(threadRef, { ...surface, projectId: "other-project" });
620
+ await show(threadRef);
621
+ await expect.element(page.getByTestId("summary-scroller")).toBeVisible();
622
+ useRightPanelStore.getState().openPullRequest(threadRef, surface);
623
+ await show(threadRef);
624
+ await expect.element(codeTab()).toBeVisible();
625
+
626
+ await act(async () => root.render(null));
627
+ useRightPanelStore.getState().openPullRequest(threadRef, { ...surface, url: detail.url });
628
+ await show(threadRef);
629
+ await expect.element(codeTab()).toBeVisible();
630
+ await tab("Summary").click();
631
+ await show(otherThread);
632
+ await show(threadRef);
633
+ await expect.element(page.getByTestId("summary-scroller")).toBeVisible();
634
+});
635
+
636
it("stays collapsed at the bottom after native scroll clamping and reopens at the top", async () => {
637
await render();
638
const title = page.getByRole("heading", { level: 1, name: "Test pull request" });
apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+27
-16
@@ -65,7 +65,7 @@ import {
65
} from "react";
66
67
import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
68
-import { useRightPanelStore } from "~/rightPanelStore";
68
+import { type PullRequestDetailTab, useRightPanelStore } from "~/rightPanelStore";
69
import { useEnvironmentSettings } from "~/hooks/useSettings";
70
import { useNewThreadHandler } from "~/hooks/useHandleNewThread";
71
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
@@ -196,8 +196,6 @@ import { guideRunKey, useGuideRunStore } from "./guide/guideRunStore";
196
import { useReviewGuideWriter } from "./guide/useReviewGuideWriter";
197
import { useInlineActionConfirm } from "./useInlineActionConfirm";
198
199
-type DetailTab = "summary" | "guide" | "timeline" | "code";
200
-
199
const ACTION_FAILURE_LABELS: Record<PullRequestAction, string> = {
200
merge: "Could not merge this pull request",
201
ready: "Could not mark this ready for review",
@@ -237,7 +235,7 @@ const ACTION_FAILURE_HINTS: Record<PullRequestAction, string> = {
235
const UPDATE_BRANCH_REBASE_FAILURE_HINT =
236
"The host refused it. A rebase stops at the first commit that does not apply cleanly; updating with a merge commit may still work.";
237
240
-const TABS: ReadonlyArray<{ value: DetailTab; label: string }> = [
238
+const TABS: ReadonlyArray<{ value: PullRequestDetailTab; label: string }> = [
239
{ value: "summary", label: "Summary" },
240
{ value: "guide", label: "Guide" },
241
{ value: "timeline", label: "Timeline" },
@@ -587,6 +585,8 @@ export function PullRequestDetailPanel({
585
onBack,
586
onSelectPullRequest,
587
onGuideShown,
588
+ initialTab = "summary",
589
+ onTabChange,
590
}: {
591
environmentId: EnvironmentId;
592
shortcutsEnabled: boolean;
@@ -602,6 +602,8 @@ export function PullRequestDetailPanel({
602
composerDraftTarget?: ScopedThreadRef | DraftId;
603
onBack?: (() => void) | undefined;
604
onGuideShown?: (() => void) | undefined;
605
+ initialTab?: PullRequestDetailTab;
606
+ onTabChange?: ((tab: PullRequestDetailTab) => void) | undefined;
607
}) {
608
const environmentConfigs = useServerConfigs();
609
const projects = useProjects();
@@ -634,7 +636,11 @@ export function PullRequestDetailPanel({
636
: null;
637
const [threadPickerOpen, setThreadPickerOpen] = useState(false);
638
const [openReviewRequest, setOpenReviewRequest] = useState(0);
637
- const [tab, setTab] = useState<DetailTab>("summary");
639
+ const [tab, setTab] = useState<PullRequestDetailTab>(initialTab);
640
+ const selectTab = (next: PullRequestDetailTab) => {
641
+ setTab(next);
642
+ onTabChange?.(next);
643
+ };
644
const [timelineOrder, setTimelineOrder] = useState<"newest" | "oldest">("newest");
645
const [codeCommitScope, setCodeCommitScope] = useState<{
646
readonly pullRequestKey: string;
@@ -647,7 +653,7 @@ export function PullRequestDetailPanel({
653
};
654
const openCommit = (oid: string) => {
655
selectCodeCommit(oid);
650
- setTab("code");
656
+ selectTab("code");
657
};
658
const [codeRevealRequest, setCodeRevealRequest] = useState<{
659
readonly path: string;
@@ -657,32 +663,36 @@ export function PullRequestDetailPanel({
663
selectCodeCommit(null);
664
setCodeRevealRequest((previous) => ({ path, nonce: (previous?.nonce ?? 0) + 1 }));
665
void loadCodeTab();
660
- setTab("code");
666
+ selectTab("code");
667
};
668
const guideOpenRequested = useGuideRunStore(
669
(state) => state.openRequestKey === guideRunKey(environmentId, reference),
670
);
671
if (guideOpenRequested && tab !== "guide") setTab("guide");
672
useEffect(() => {
667
- if (guideOpenRequested) useGuideRunStore.getState().requestOpen(null);
668
- }, [guideOpenRequested]);
673
+ if (!guideOpenRequested) return;
674
+ useGuideRunStore.getState().requestOpen(null);
675
+ onTabChange?.("guide");
676
+ }, [guideOpenRequested, onTabChange]);
677
const tabScopeKey = `${environmentId}:${pullRequestKey}`;
678
const [tabMountState, setTabMountState] = useState(() => ({
679
key: tabScopeKey,
672
- tabs: new Set<DetailTab>(["summary"]),
680
+ tabs: new Set<PullRequestDetailTab>([tab]),
681
}));
682
// A previously visited Code tab must not fetch diffs for every later PR while hidden.
683
const mountedTabs =
676
- tabMountState.key === tabScopeKey ? tabMountState.tabs : new Set<DetailTab>([tab]);
684
+ tabMountState.key === tabScopeKey ? tabMountState.tabs : new Set<PullRequestDetailTab>([tab]);
685
if (tabMountState.key !== tabScopeKey) {
686
setTabMountState({ key: tabScopeKey, tabs: new Set([tab]) });
687
} else if (!tabMountState.tabs.has(tab)) {
688
setTabMountState({ key: tabScopeKey, tabs: new Set(tabMountState.tabs).add(tab) });
689
}
690
// Each tab restores the condensed state its own scrolling left behind.
683
- const [condensedByTab, setCondensedByTab] = useState<Partial<Record<DetailTab, boolean>>>({});
691
+ const [condensedByTab, setCondensedByTab] = useState<
692
+ Partial<Record<PullRequestDetailTab, boolean>>
693
+ >({});
694
const condensed = condensedByTab[tab] ?? false;
685
- const scrollerByTab = useRef<Partial<Record<DetailTab, HTMLDivElement | null>>>({});
695
+ const scrollerByTab = useRef<Partial<Record<PullRequestDetailTab, HTMLDivElement | null>>>({});
696
// Fresh ref callbacks would detach and reattach every scroller on each render.
697
const [scrollerRefs] = useState(() => ({
698
summary: (node: HTMLDivElement | null) => {
@@ -700,7 +710,7 @@ export function PullRequestDetailPanel({
710
// Save the target before collapse: the browser may clamp scrollTop as the viewport grows,
711
// so applying a delta afterward would compensate twice.
712
const compensationRef = useRef<{
703
- tab: DetailTab;
713
+ tab: PullRequestDetailTab;
714
scroller: HTMLDivElement;
715
target: number;
716
} | null>(null);
@@ -1043,7 +1053,7 @@ export function PullRequestDetailPanel({
1053
});
1054
const writeGuide = () => {
1055
void guideWriter.write();
1046
- if (guideWriter.data?.guide == null) setTab("guide");
1056
+ if (guideWriter.data?.guide == null) selectTab("guide");
1057
};
1058
1059
const writeTaskToComposer = (target: ScopedThreadRef | DraftId, task: ThreadTask) => {
@@ -1439,6 +1449,7 @@ export function PullRequestDetailPanel({
1449
(item.value !== "code" || detail === null || detail.capabilities.diff) &&
1450
(item.value !== "guide" || reviewGuidesEnabled),
1451
);
1452
+ // Keep unavailable-tab fallbacks out of the saved selection.
1453
if (!visibleTabs.some((item) => item.value === tab)) setTab("summary");
1454
const can = (action: PullRequestAction) =>
1455
detail?.capabilities.actions.includes(action) === true &&
@@ -2605,7 +2616,7 @@ export function PullRequestDetailPanel({
2616
<PullRequestDetailTabBar
2617
tabs={visibleTabs}
2618
value={tab}
2608
- onValueChange={setTab}
2619
+ onValueChange={selectTab}
2620
onTabIntent={(item) => {
2621
if (item === "code") void loadCodeTab();
2622
}}
apps/web/src/rightPanelStore.test.ts
+57
@@ -3,6 +3,7 @@ import { type EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
3
import { beforeEach, describe, expect, it } from "vite-plus/test";
4
5
import { useClosedViewStore } from "./closedViewStore";
6
+import { reopenClosedView } from "./reopenClosedView";
7
import {
8
migratePersistedRightPanelState,
9
pullRequestSurface,
@@ -1245,6 +1246,62 @@ describe("rightPanelStore", () => {
1246
expect(state.surfaces[1]).not.toHaveProperty("url");
1247
});
1248
1249
+ it("restores each environment, thread and PR surface's detail tab after reload and URL reopen", async () => {
1250
+ const pr = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
1251
+ const otherPr = { ...pr, projectId: "project-b" };
1252
+ const otherEnvironment = scopeThreadRef("env-2" as EnvironmentId, refA.threadId);
1253
+ const selections = [
1254
+ [refA, pr, "code"],
1255
+ [refB, pr, "guide"],
1256
+ [otherEnvironment, pr, "timeline"],
1257
+ [refA, otherPr, "summary"],
1258
+ ] as const;
1259
+ const store = useRightPanelStore.getState();
1260
+ for (const [ref, reference, tab] of selections) {
1261
+ store.openPullRequest(ref, reference);
1262
+ store.setPullRequestDetailTab(ref, pullRequestSurfaceId(reference), "guide");
1263
+ store.setPullRequestDetailTab(ref, pullRequestSurfaceId(reference), tab);
1264
+ }
1265
+
1266
+ store.openPullRequest(refA, pr);
1267
+ const revision = store.getUserActionRevision(refA);
1268
+ store.setPullRequestDetailTab(refA, pullRequestSurfaceId(pr), "timeline");
1269
+ expect(store.openProactive(refA, linkedPullRequest, revision)).toBe(true);
1270
+ expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
1271
+ linkedPullRequest,
1272
+ );
1273
+ store.setPullRequestDetailTab(refA, pullRequestSurfaceId(pr), "code");
1274
+
1275
+ const { storage, name } = useRightPanelStore.persist.getOptions();
1276
+ const saved = await storage!.getItem(name!);
1277
+ expect(saved).not.toBeNull();
1278
+ useRightPanelStore.setState({ byThreadKey: {} });
1279
+ await storage!.setItem(name!, saved!);
1280
+ await useRightPanelStore.persist.rehydrate();
1281
+
1282
+ for (const [ref, reference, tab] of selections) {
1283
+ store.openPullRequest(ref, {
1284
+ ...reference,
1285
+ url: `https://github.com/${reference.repository}/pull/${reference.number}`,
1286
+ });
1287
+ const active = selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, ref);
1288
+ expect(active?.id).toBe(pullRequestSurfaceId(reference));
1289
+ expect(active?.kind === "pull-request" && (active.detailTab ?? "summary")).toBe(tab);
1290
+ store.closeSurface(ref, active!.id);
1291
+ await reopenClosedView(useClosedViewStore.getState().entries[0]!, {
1292
+ workspaceAvailable: true,
1293
+ openPreview: () => {
1294
+ throw new Error("A PR tab must not create a browser session");
1295
+ },
1296
+ });
1297
+ const reopened = selectActiveRightPanelSurface(
1298
+ useRightPanelStore.getState().byThreadKey,
1299
+ ref,
1300
+ );
1301
+ expect(reopened?.kind === "pull-request" && (reopened.detailTab ?? "summary")).toBe(tab);
1302
+ }
1303
+ });
1304
+
1305
it("keeps matching repository and number on different hosts as separate tabs", () => {
1306
const first = { projectId: "project-a", repository: "acme/api", number: 7, host: "github.com" };
1307
const second = { ...first, host: "github.example.com" };
apps/web/src/rightPanelStore.ts
+31
-1
@@ -24,6 +24,8 @@ const RIGHT_PANEL_KINDS = [
24
] as const;
25
export type RightPanelKind = (typeof RIGHT_PANEL_KINDS)[number];
26
27
+export type PullRequestDetailTab = "summary" | "guide" | "timeline" | "code";
28
+
29
export interface DeviceTabTarget {
30
hostId: string;
31
deviceId: string;
@@ -76,6 +78,7 @@ export type RightPanelSurface =
78
repository: string;
79
number: number;
80
url?: string;
81
+ detailTab?: PullRequestDetailTab;
82
}
83
| { id: "pull-requests"; kind: "pull-requests" };
84
@@ -155,8 +158,14 @@ interface RightPanelStoreState {
158
repository: string;
159
number: number;
160
url?: string;
161
+ detailTab?: PullRequestDetailTab;
162
},
163
) => void;
164
+ setPullRequestDetailTab: (
165
+ ref: ScopedThreadRef,
166
+ surfaceId: string,
167
+ detailTab: PullRequestDetailTab,
168
+ ) => void;
169
openTerminal: (ref: ScopedThreadRef, terminalId: string) => void;
170
splitTerminal: (
171
ref: ScopedThreadRef,
@@ -277,6 +286,7 @@ export function pullRequestSurface(target: {
286
repository: string;
287
number: number;
288
url?: string;
289
+ detailTab?: PullRequestDetailTab;
290
}): PullRequestSurface {
291
return {
292
id: pullRequestSurfaceId(target),
@@ -287,6 +297,7 @@ export function pullRequestSurface(target: {
297
repository: target.repository,
298
number: target.number,
299
...(typeof target.url === "string" ? { url: target.url } : {}),
300
+ ...(target.detailTab === undefined ? {} : { detailTab: target.detailTab }),
301
};
302
}
303
@@ -704,12 +715,31 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
715
? {
716
...next,
717
surfaces: next.surfaces.map((entry) =>
707
- entry.id === surface.id ? surface : entry,
718
+ entry.id === surface.id && entry.kind === "pull-request"
719
+ ? { ...entry, ...surface }
720
+ : entry,
721
),
722
}
723
: next;
724
}),
725
),
726
+ setPullRequestDetailTab: (ref, surfaceId, detailTab) =>
727
+ set((state) => {
728
+ const threadKey = scopedThreadKey(ref);
729
+ const existing = state.byThreadKey[threadKey]?.surfaces.find(
730
+ (surface) => surface.id === surfaceId,
731
+ );
732
+ if (existing?.kind !== "pull-request" || (existing.detailTab ?? "summary") === detailTab)
733
+ return state;
734
+ return automaticUpdate(state, threadKey, (current) => ({
735
+ ...current,
736
+ surfaces: current.surfaces.map((surface) =>
737
+ surface.id === surfaceId && surface.kind === "pull-request"
738
+ ? { ...surface, detailTab }
739
+ : surface,
740
+ ),
741
+ }));
742
+ }),
743
openFile: (ref, requestedPath, line) =>
744
set((state) =>
745
userAction(state, scopedThreadKey(ref), (current) => {