TypeScript
fix(web): pull request header no longer flickers when scrolled to the bottom (#15678)
Rakshith Bhat7f1ecf3463ec
diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.browser.test.tsxindex 31fc9a3e440..ee611b8b14c 100644--- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.browser.test.tsx+++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.browser.test.tsx@@ -406,6 +406,43 @@ it("folds the title only for the active tab's own scroller", async () => {await vi.waitFor(() => expect(titleFold()).toBe(true));});+it("stays collapsed at the bottom after native scroll clamping and reopens at the top", async () => {+ await render();+ const title = page.getByRole("heading", { level: 1, name: "Test pull request" });+ await expect.element(title).toBeVisible();+ const scroller = page.getByTestId("summary-scroller").element() as HTMLElement;+ const content = scroller.lastElementChild as HTMLElement;+ // Leave only a short scroll range so folding the header makes the browser clamp it.+ content.style.height = `${scroller.clientHeight - 24}px`;+ const expandedHeight = scroller.clientHeight;+ const expandedBottom = scroller.scrollHeight - scroller.clientHeight;++ await act(async () => {+ const scrolled = new Promise<void>((resolve) =>+ scroller.addEventListener("scroll", () => resolve(), { once: true }),+ );+ scroller.scrollTop = scroller.scrollHeight;+ await scrolled;+ });++ await vi.waitFor(() => {+ expect(title.element().closest("[inert]")).not.toBeNull();+ expect(scroller.clientHeight).toBeGreaterThan(expandedHeight);+ expect(scroller.scrollTop).toBeGreaterThan(0);+ expect(scroller.scrollTop).toBeLessThan(expandedBottom);+ expect(scroller.scrollTop).toBe(scroller.scrollHeight - scroller.clientHeight);+ });++ await act(async () => {+ const scrolled = new Promise<void>((resolve) =>+ scroller.addEventListener("scroll", () => resolve(), { once: true }),+ );+ scroller.scrollTop = 0;+ await scrolled;+ });+ await vi.waitFor(() => expect(title.element().closest("[inert]")).toBeNull());+});+it("shows the current checkout recovery detail on the first failure and on retry", async () => {const first = new GitManagerError({cwd: "/workspace",diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsxindex 50626f0451f..9adaa35a722 100644--- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx+++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx@@ -697,10 +697,12 @@ export function PullRequestDetailPanel({}));const foldRef = useRef<HTMLDivElement | null>(null);const condensedRowRef = useRef<HTMLDivElement | null>(null);+ // Save the target before collapse: the browser may clamp scrollTop as the viewport grows,+ // so applying a delta afterward would compensate twice.const compensationRef = useRef<{tab: DetailTab;scroller: HTMLDivElement;- delta: number;+ target: number;} | null>(null);useLayoutEffect(() => {const compensation = compensationRef.current;@@ -712,10 +714,7 @@ export function PullRequestDetailPanel({scrollerByTab.current[tab] !== compensation.scroller)return;- compensation.scroller.scrollTop = Math.max(- 0,- compensation.scroller.scrollTop + compensation.delta,- );+ compensation.scroller.scrollTop = Math.max(0, compensation.target);}, [condensed, tab]);const lastSelectedMergeMethod = useUiStateStore((state) => state.pullRequestMergeMethod);const setLastSelectedMergeMethod = useUiStateStore((state) => state.setPullRequestMergeMethod);@@ -2771,7 +2770,7 @@ export function PullRequestDetailPanel({if (top < 4 && foldHeight > 0) next = false;} else if (foldHeight > 0 && top > foldHeight + 32) {const chromeDelta = foldHeight - (condensedRowRef.current?.scrollHeight ?? 0);- compensationRef.current = { tab, scroller, delta: -chromeDelta };+ compensationRef.current = { tab, scroller, target: top - chromeDelta };next = true;}if (next !== previous) setCondensedByTab({ ...condensedByTab, [tab]: next });