@devries-cameron20 / t3code-1 / commits / cefe45b7de
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): returning to a thread no longer jumps to its pull request tab (#13608)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Sairaj committed Oct 20, 2026 at 10:38 UTC cefe45b7dee753abac40e3bf625d3ed1b29e81e5
3 files changed +82 -19
apps/web/src/hooks/useProactivePanels.ts
+15 -17
@@ -16,6 +16,9 @@ import {
16 shouldRetargetThreadPullRequestPanel,
17 } from "../components/ChatView.logic";
18
19 +// Settings and drafts unmount ChatView; remember links until the page reloads.
20 +const observedThreadPullRequests = new Map<string, ThreadLinkedPullRequest | null>();
21 +
22 /**
23 * Opens the right panel on its own when there is something new to look at: a
24 * change request linked to the thread, or the diff of a turn that just
@@ -65,16 +68,11 @@ export function useProactivePanels(input: {
68 const proactivePanelObservationRef = useRef<ReturnType<
69 typeof observeProactivePanelUserChoice
70 > | null>(null);
68 - const observedThreadPullRequestRef = useRef<{
69 - readonly threadKey: string;
70 - readonly reference: ThreadLinkedPullRequest | null;
71 - } | null>(null);
71 const threadKey = threadRef ? scopedThreadKey(threadRef) : null;
72
73 useEffect(() => {
74 if (threadKey === null || threadRef === null) {
75 proactivePanelObservationRef.current = null;
77 - observedThreadPullRequestRef.current = null;
76 return;
77 }
78 const panels = useRightPanelStore.getState();
@@ -90,18 +88,16 @@ export function useProactivePanels(input: {
88 userActionRevision,
89 } = observation;
90 const openSurface = selectActiveRightPanelSurface(panels.byThreadKey, threadRef);
93 - const previousPullRequest = observedThreadPullRequestRef.current;
94 - observedThreadPullRequestRef.current = {
95 - threadKey: threadKey,
96 - reference: linkedThreadPullRequest,
97 - };
98 - const followSelectedPullRequest =
99 - previousPullRequest?.threadKey === threadKey &&
100 - shouldRetargetThreadPullRequestPanel(
101 - previousPullRequest.reference,
102 - linkedThreadPullRequest,
103 - openSurface,
104 - );
91 + const previousPullRequest = observedThreadPullRequests.get(threadKey) ?? null;
92 + // A missing link during loading must not erase the last observed one.
93 + if (linkedThreadPullRequest !== null || !threadDetailLoading) {
94 + observedThreadPullRequests.set(threadKey, linkedThreadPullRequest);
95 + }
96 + const followSelectedPullRequest = shouldRetargetThreadPullRequestPanel(
97 + previousPullRequest,
98 + linkedThreadPullRequest,
99 + openSurface,
100 + );
101 // Following the selected linked PR does not open an unrelated panel, so it
102 // remains available with proactive panels off. It still respects a later choice.
103 if (followSelectedPullRequest && linkedThreadPullRequest !== null) {
@@ -109,6 +105,7 @@ export function useProactivePanels(input: {
105 threadRef,
106 pullRequestSurface(linkedThreadPullRequest),
107 userActionRevision,
108 + true,
109 );
110 }
111 if (!clientSettingsHydrated) return;
@@ -124,6 +121,7 @@ export function useProactivePanels(input: {
121 };
122 if (eligibleLink && pullRequestsCapabilityKnown) {
123 if (
124 + !followSelectedPullRequest &&
125 pullRequestsSurfaceAvailable &&
126 (visiblePullRequestCount > 1 || !hasLinkedPullRequestDetail || !supportsPullRequests)
127 ) {
apps/web/src/rightPanelStore.test.ts
+56 -1
@@ -302,8 +302,63 @@ describe("rightPanelStore", () => {
302 });
303 });
304
305 - it("allows automatic panels for a later turn after a manual choice", () => {
305 + it.each([
306 + {
307 + surface: linkedPullRequest,
308 + choose: () => useRightPanelStore.getState().openFile(refA, "notes.md"),
309 + },
310 + {
311 + surface: { id: "pull-requests", kind: "pull-requests" } as const,
312 + choose: () => useRightPanelStore.getState().openBrowser(refA, "tab-a"),
313 + },
314 + ])(
315 + "preserves the selected tab and hidden panel when $surface.kind already exists",
316 + ({ surface, choose }) => {
317 + const store = useRightPanelStore.getState();
318 + store.openProactive(refA, surface, store.getUserActionRevision(refA));
319 + choose();
320 + const chosen = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
321 +
322 + // Re-entry captures a fresh revision; the existing tab must still preserve the choice.
323 + expect(store.openProactive(refA, surface, store.getUserActionRevision(refA))).toBe(false);
324 + expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
325 + chosen,
326 + );
327 +
328 + store.close(refA);
329 + expect(store.openProactive(refA, surface, store.getUserActionRevision(refA))).toBe(false);
330 + expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
331 + ...chosen,
332 + isOpen: false,
333 + });
334 + },
335 + );
336 +
337 + it("retargets an existing PR tab but respects a later manual choice", () => {
338 + const store = useRightPanelStore.getState();
339 + const relinkedPullRequest = pullRequestSurface({ ...linkedPullRequest, number: 43 });
340 + store.openPullRequest(refA, relinkedPullRequest);
341 + store.openPullRequest(refA, linkedPullRequest);
342 + const revision = store.getUserActionRevision(refA);
343 +
344 + expect(store.openProactive(refA, relinkedPullRequest, revision, true)).toBe(true);
345 + expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
346 + relinkedPullRequest,
347 + );
348 +
349 + store.close(refA);
350 + expect(store.openProactive(refA, linkedPullRequest, revision, true)).toBe(false);
351 + expect(
352 + selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA),
353 + ).toMatchObject({
354 + activeSurfaceId: relinkedPullRequest.id,
355 + isOpen: false,
356 + });
357 + });
358 +
359 + it("refocuses an existing diff for a later turn after a manual choice", () => {
360 const store = useRightPanelStore.getState();
361 + store.openProactive(refA, completedDiff, store.getUserActionRevision(refA));
362 const firstTurnRevision = store.getUserActionRevision(refA);
363 store.openFile(refA, "src/app.ts");
364 expect(store.openProactive(refA, completedDiff, firstTurnRevision)).toBe(false);
apps/web/src/rightPanelStore.ts
+11 -1
@@ -122,6 +122,7 @@ interface RightPanelStoreState {
122 | Extract<RightPanelSurface, { kind: "pull-request" | "pull-requests" }>
123 | { kind: "diff"; turnId: RunId },
124 expectedUserActionRevision: number,
125 + activateExisting?: boolean,
126 ) => boolean;
127 open: (
128 ref: ScopedThreadRef,
@@ -600,7 +601,7 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
601 closeRevisionByThreadKey: {},
602 getUserActionRevision: (ref) =>
603 get().userActionRevisionByThreadKey[scopedThreadKey(ref)] ?? 0,
603 - openProactive: (ref, request, expectedUserActionRevision) => {
604 + openProactive: (ref, request, expectedUserActionRevision, activateExisting = false) => {
605 let opened = false;
606 set((state) => {
607 const threadKey = scopedThreadKey(ref);
@@ -626,6 +627,15 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
627 ) {
628 return state;
629 }
630 + // Keep an existing PR tab where the user left it when revisiting a thread.
631 + if (
632 + !activateExisting &&
633 + selectThreadRightPanelState(state.byThreadKey, ref).surfaces.some(
634 + (entry) => entry.id === request.id,
635 + )
636 + ) {
637 + return state;
638 + }
639 opened = true;
640 return automaticUpdate(state, threadKey, (current) => upsertSurface(current, request));
641 });