Skip to content

Commit 9a572b5

Browse files
committed
fix(web): scope PR title collapse to tab scrollers
1 parent ba79610 commit 9a572b5

6 files changed

Lines changed: 167 additions & 43 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestCodeTab.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ function getReviewPositionAnchor(position: PullRequestReviewPosition): {
192192
* drafted rather than being posted as it is typed.
193193
*/
194194
function PullRequestCodeTab({
195+
scrollerRef,
195196
environmentId,
196197
reference,
197198
detail,
@@ -204,6 +205,7 @@ function PullRequestCodeTab({
204205
onRefresh,
205206
refreshToken = 0,
206207
}: {
208+
scrollerRef: (node: HTMLDivElement | null) => void;
207209
environmentId: EnvironmentId;
208210
reference: PullRequestRef;
209211
detail: PullRequestDetailView;
@@ -1327,7 +1329,9 @@ function PullRequestCodeTab({
13271329
const withToolbar = (body: ReactNode) => (
13281330
<div className="flex h-full min-h-0 flex-col">
13291331
{toolbar}
1330-
<div className="min-h-0 flex-1 overflow-auto">{body}</div>
1332+
<div ref={scrollerRef} className="min-h-0 flex-1 overflow-auto">
1333+
{body}
1334+
</div>
13311335
</div>
13321336
);
13331337

@@ -1507,6 +1511,7 @@ function PullRequestCodeTab({
15071511
// interaction, but its native host outline clips and competes with the focus
15081512
// indicators on its actual controls.
15091513
className="h-full overflow-auto [scrollbar-gutter:stable]"
1514+
containerRef={scrollerRef}
15101515
viewerRef={setViewer}
15111516
items={items}
15121517
selectedLines={selectedLines}

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.test.tsx‎

Lines changed: 115 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,43 +101,49 @@ vi.mock("./PullRequestThreadLinks", () => ({ PullRequestThreadLinks: () => null
101101
vi.mock("./PullRequestSummaryTab", () => ({
102102
PullRequestSummaryTab: ({
103103
onFixFinding,
104+
scrollerRef,
104105
}: ComponentProps<typeof import("./PullRequestSummaryTab").PullRequestSummaryTab>) => (
105-
<button
106-
onClick={() =>
107-
onFixFinding?.({
108-
kind: "check",
109-
check: { name: "Unit tests", status: "failure", description: "Test failed", url: null },
110-
})
111-
}
112-
>
113-
Fix check
114-
</button>
106+
<div ref={scrollerRef} data-test-scroll="summary">
107+
<button
108+
onClick={() =>
109+
onFixFinding?.({
110+
kind: "check",
111+
check: { name: "Unit tests", status: "failure", description: "Test failed", url: null },
112+
})
113+
}
114+
>
115+
Fix check
116+
</button>
117+
</div>
115118
),
116119
}));
117120
vi.mock("./PullRequestCodeTab", () => ({
118121
default: ({
119122
onAddToAgentSelection,
123+
scrollerRef,
120124
}: ComponentProps<typeof import("./PullRequestCodeTab").default>) => (
121-
<button
122-
onClick={() =>
123-
onAddToAgentSelection?.({
124-
request: "Fix this line",
125-
comment: {
126-
id: "note-1",
127-
sectionId: "file:a.ts",
128-
sectionTitle: "a.ts",
129-
filePath: "a.ts",
130-
startIndex: 0,
131-
endIndex: 0,
132-
rangeLabel: "L1",
133-
text: "Please fix",
134-
diff: "+broken()",
135-
},
136-
})
137-
}
138-
>
139-
Add to agent
140-
</button>
125+
<div ref={scrollerRef} data-test-scroll="code">
126+
<button
127+
onClick={() =>
128+
onAddToAgentSelection?.({
129+
request: "Fix this line",
130+
comment: {
131+
id: "note-1",
132+
sectionId: "file:a.ts",
133+
sectionTitle: "a.ts",
134+
filePath: "a.ts",
135+
startIndex: 0,
136+
endIndex: 0,
137+
rangeLabel: "L1",
138+
text: "Please fix",
139+
diff: "+broken()",
140+
},
141+
})
142+
}
143+
>
144+
Add to agent
145+
</button>
146+
</div>
141147
),
142148
}));
143149

@@ -336,3 +342,82 @@ describe.each([
336342
}
337343
});
338344
});
345+
346+
it("changes the title only for the active tab's main scroller", async () => {
347+
const scrollers = new Map<string, { scrollTop: number; scrollHeight: number }>();
348+
await act(async () => {
349+
renderer = create(
350+
<PullRequestDetailPanel
351+
environmentId={threadRef.environmentId}
352+
reference={detail}
353+
context="page"
354+
shortcutsEnabled={false}
355+
getShortcutContext={() => ({
356+
terminalFocus: false,
357+
terminalOpen: false,
358+
previewFocus: false,
359+
previewOpen: false,
360+
isWeb: true,
361+
isDesktop: false,
362+
})}
363+
/>,
364+
{
365+
createNodeMock: (element) => {
366+
const props = element.props as Record<string, unknown>;
367+
const name = props["data-test-scroll"] as string | undefined;
368+
if (name) {
369+
const scroller = { scrollTop: 0, scrollHeight: 300 };
370+
scrollers.set(name, scroller);
371+
return scroller;
372+
}
373+
return { scrollHeight: props.inert === false ? 100 : 20 };
374+
},
375+
},
376+
);
377+
});
378+
379+
const mainScroll = renderer.root.findByProps({
380+
className: "relative flex min-h-0 flex-1 flex-col overflow-hidden",
381+
});
382+
const titleFold = () => {
383+
let node = renderer.root.findByType("h1");
384+
while (typeof node.props.inert !== "boolean") node = node.parent!;
385+
return node;
386+
};
387+
const summary = scrollers.get("summary")!;
388+
const nested = { scrollTop: 200 };
389+
await act(async () => mainScroll.props.onScrollCapture({ target: nested }));
390+
expect(titleFold().props.inert).toBe(false);
391+
summary.scrollTop = 180;
392+
nested.scrollTop = 0;
393+
await act(async () => {
394+
mainScroll.props.onScrollCapture({ target: summary });
395+
mainScroll.props.onScrollCapture({ target: nested });
396+
});
397+
expect(titleFold().props.inert).toBe(true);
398+
expect(summary.scrollTop).toBe(100);
399+
expect(nested.scrollTop).toBe(0);
400+
401+
await act(async () => mainScroll.props.onScrollCapture({ target: { scrollTop: 0 } }));
402+
expect(titleFold().props.inert).toBe(true);
403+
summary.scrollTop = 0;
404+
await act(async () => mainScroll.props.onScrollCapture({ target: summary }));
405+
expect(titleFold().props.inert).toBe(false);
406+
407+
await click("Code");
408+
const code = scrollers.get("code")!;
409+
summary.scrollTop = 180;
410+
await act(async () => mainScroll.props.onScrollCapture({ target: summary }));
411+
expect(titleFold().props.inert).toBe(false);
412+
code.scrollTop = 180;
413+
await act(async () => mainScroll.props.onScrollCapture({ target: code }));
414+
expect(titleFold().props.inert).toBe(true);
415+
expect(code.scrollTop).toBe(100);
416+
await click("Summary");
417+
expect(titleFold().props.inert).toBe(false);
418+
await click("Code");
419+
expect(titleFold().props.inert).toBe(true);
420+
code.scrollTop = 0;
421+
await act(async () => mainScroll.props.onScrollCapture({ target: code }));
422+
expect(titleFold().props.inert).toBe(false);
423+
});

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -548,18 +548,44 @@ export function PullRequestDetailPanel({
548548
setChromeCondensed(chromeStateByTab.current[tab] ?? false);
549549
}, [tab]);
550550
const condensed = chromeCondensed;
551-
const scrollerRef = useRef<HTMLElement | null>(null);
551+
const scrollerByTab = useRef<Partial<Record<DetailTab, HTMLDivElement | null>>>({});
552+
const scrollerRefs = useMemo(
553+
() => ({
554+
summary: (node: HTMLDivElement | null) => {
555+
scrollerByTab.current.summary = node;
556+
},
557+
timeline: (node: HTMLDivElement | null) => {
558+
scrollerByTab.current.timeline = node;
559+
},
560+
code: (node: HTMLDivElement | null) => {
561+
scrollerByTab.current.code = node;
562+
},
563+
}),
564+
[],
565+
);
552566
const foldRef = useRef<HTMLDivElement | null>(null);
553567
const condensedRowRef = useRef<HTMLDivElement | null>(null);
554568
// Refund after the fold commits so the content under the reader does not jump with its height.
555-
const compensationRef = useRef<number | null>(null);
569+
const compensationRef = useRef<{
570+
tab: DetailTab;
571+
scroller: HTMLDivElement;
572+
delta: number;
573+
} | null>(null);
556574
useLayoutEffect(() => {
557-
if (compensationRef.current === null) return;
558-
const scroller = scrollerRef.current;
559-
const delta = compensationRef.current;
575+
const compensation = compensationRef.current;
576+
if (compensation === null) return;
560577
compensationRef.current = null;
561-
if (scroller) scroller.scrollTop = Math.max(0, scroller.scrollTop + delta);
562-
}, [condensed]);
578+
if (
579+
!condensed ||
580+
compensation.tab !== tab ||
581+
scrollerByTab.current[tab] !== compensation.scroller
582+
)
583+
return;
584+
compensation.scroller.scrollTop = Math.max(
585+
0,
586+
compensation.scroller.scrollTop + compensation.delta,
587+
);
588+
}, [condensed, tab]);
563589
const lastSelectedMergeMethod = useUiStateStore((state) => state.pullRequestMergeMethod);
564590
const setLastSelectedMergeMethod = useUiStateStore((state) => state.setPullRequestMergeMethod);
565591
// Server-side and per project, like every other project setting. The
@@ -2686,8 +2712,8 @@ export function PullRequestDetailPanel({
26862712
<div
26872713
className="relative flex min-h-0 flex-1 flex-col overflow-hidden"
26882714
onScrollCapture={(event) => {
2689-
const scroller = event.target as HTMLElement;
2690-
scrollerRef.current = scroller;
2715+
const scroller = scrollerByTab.current[tab];
2716+
if (event.target !== scroller || scroller === null || scroller === undefined) return;
26912717
const top = scroller.scrollTop;
26922718
setChromeCondensed((previous) => {
26932719
let next = previous;
@@ -2702,7 +2728,7 @@ export function PullRequestDetailPanel({
27022728
next = false;
27032729
}
27042730
} else if (foldHeight > 0 && top > foldHeight + 32) {
2705-
compensationRef.current = -chromeDelta;
2731+
compensationRef.current = { tab, scroller, delta: -chromeDelta };
27062732
next = true;
27072733
}
27082734
chromeStateByTab.current[tab] = next;
@@ -2722,6 +2748,7 @@ export function PullRequestDetailPanel({
27222748
{mountedTabs.has("summary") ? (
27232749
<div className={cn("absolute inset-0", tab !== "summary" && "invisible")}>
27242750
<PullRequestSummaryTab
2751+
scrollerRef={scrollerRefs.summary}
27252752
environmentId={environmentId}
27262753
threadRef={threadRef}
27272754
reference={reference}
@@ -2749,6 +2776,7 @@ export function PullRequestDetailPanel({
27492776
/>
27502777
) : (
27512778
<PullRequestTimelineTab
2779+
scrollerRef={scrollerRefs.timeline}
27522780
detail={detail}
27532781
environmentId={environmentId}
27542782
threadRef={threadRef}
@@ -2764,6 +2792,7 @@ export function PullRequestDetailPanel({
27642792
<div className={cn("absolute inset-0", tab !== "code" && "invisible")}>
27652793
<Suspense fallback={<DiffPanelLoadingState label="Loading pull request diff..." />}>
27662794
<PullRequestCodeTab
2795+
scrollerRef={scrollerRefs.code}
27672796
onAddToAgentSelection={addSelectionToAgent}
27682797
environmentId={environmentId}
27692798
reference={reference}

‎apps/web/src/components/pullRequest/PullRequestSummaryTab.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ afterEach(() => {
7979
function render(value = detail) {
8080
return (
8181
<PullRequestSummaryTab
82+
scrollerRef={() => {}}
8283
environmentId={EnvironmentId.make("environment")}
8384
threadRef={null}
8485
reference={value}

‎apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ function CommentGroup({
455455
const COMMENT_PAGE = 10;
456456

457457
export function PullRequestSummaryTab({
458+
scrollerRef,
458459
environmentId,
459460
threadRef,
460461
reference,
@@ -469,6 +470,7 @@ export function PullRequestSummaryTab({
469470
onRefresh,
470471
onRefreshChecks = onRefresh,
471472
}: {
473+
scrollerRef: (node: HTMLDivElement | null) => void;
472474
environmentId: EnvironmentId;
473475
threadRef: ScopedThreadRef | null;
474476
reference: PullRequestRef;
@@ -708,7 +710,7 @@ export function PullRequestSummaryTab({
708710
};
709711

710712
return (
711-
<div className="h-full overflow-y-auto" data-pull-request-summary-scroll>
713+
<div ref={scrollerRef} className="h-full overflow-y-auto" data-pull-request-summary-scroll>
712714
<section className="px-4 pt-2.5 pb-1">
713715
<div className="space-y-2">
714716
<MetaRow icon={<UsersIcon className="size-3.5" />} label="Reviewers">

‎apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ function ReviewVerdictEvent({
538538
}
539539

540540
export function PullRequestTimelineTab({
541+
scrollerRef,
541542
detail,
542543
environmentId,
543544
threadRef = null,
@@ -546,6 +547,7 @@ export function PullRequestTimelineTab({
546547
onOpenCommit,
547548
onRefresh,
548549
}: {
550+
scrollerRef: (node: HTMLDivElement | null) => void;
549551
detail: PullRequestDetailView;
550552
environmentId: EnvironmentId;
551553
threadRef?: ScopedThreadRef | null;
@@ -577,7 +579,7 @@ export function PullRequestTimelineTab({
577579
};
578580

579581
return (
580-
<div className="h-full overflow-y-auto px-4 py-5">
582+
<div ref={scrollerRef} className="h-full overflow-y-auto px-4 py-5">
581583
<div className="mx-auto max-w-3xl">
582584
<div className="relative">
583585
<span aria-hidden className="absolute bottom-5 left-[15px] top-1 w-px bg-border/45" />

0 commit comments

Comments
 (0)