TypeScript
fix(web): keep long PR badge lists within the viewport (#18941)
Kevin Bravo219afe344cb1
diff --git a/apps/web/src/components/ThreadStatusIndicators.subscriptions.browser.test.tsx b/apps/web/src/components/ThreadStatusIndicators.subscriptions.browser.test.tsxindex 9d5a2c12293..09d3c382310 100644--- a/apps/web/src/components/ThreadStatusIndicators.subscriptions.browser.test.tsx+++ b/apps/web/src/components/ThreadStatusIndicators.subscriptions.browser.test.tsx@@ -1,7 +1,16 @@-import { ProjectId, ThreadId, type VcsStatusResult } from "@t3tools/contracts";-import { act } from "react";+import {+ ProjectId,+ ThreadId,+ type ThreadPullRequestLink,+ type VcsStatusResult,+} from "@t3tools/contracts";+import { act, type MouseEvent } from "react";import { createRoot } from "react-dom/client";import { afterEach, expect, it, vi } from "vite-plus/test";+import { page, userEvent } from "vite-plus/test/browser";++import "../index.css";+import { Button } from "./ui/button";import { AppAtomRegistryProvider } from "../rpc/atomRegistry";import { makeThreadFixture } from "../test-fixtures";@@ -75,7 +84,7 @@ vi.mock(import("../state/pullRequests"), async (importOriginal) => {summaries(input.number)) as never,};});-import { ThreadRowLeadingStatus } from "./ThreadStatusIndicators";+import { ThreadPullRequestBadgeControl, ThreadRowLeadingStatus } from "./ThreadStatusIndicators";afterEach(() => {vi.unstubAllGlobals();@@ -174,3 +183,66 @@ it("leases only visible palette results while retaining observed and cached PR bcontainer.remove();}});++it("keeps a long PR hover list in the viewport and lets the last row be selected", async () => {+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);+ const previousViewport = { width: window.innerWidth, height: window.innerHeight };+ await page.viewport(800, 480);+ const pullRequests = Array.from({ length: 40 }, (_, index): ThreadPullRequestLink => ({+ host: "github.com",+ repository: "example/repo",+ number: index + 1,+ url: `https://github.com/example/repo/pull/${index + 1}`,+ source: "manual",+ linkedAt: "2026-01-01T00:00:00Z",+ snapshot: null,+ stack: null,+ }));+ const onOpenPullRequest = vi.fn((event: MouseEvent<HTMLElement>) => event.preventDefault());+ const container = document.createElement("div");+ document.body.append(container);+ const root = createRoot(container);+ try {+ await act(async () =>+ root.render(+ <div style={{ position: "fixed", top: 220, left: 300 }}>+ <ThreadPullRequestBadgeControl+ render={<Button size="xs" />}+ badge={{ kind: "pull-request", others: 39, state: "open" }}+ pullRequests={pullRequests}+ number={1}+ url={pullRequests[0]!.url}+ status={null}+ onOpenList={() => {}}+ onOpenPullRequest={onOpenPullRequest}+ />+ </div>,+ ),+ );+ await act(() => userEvent.hover(container.querySelector("button")!));+ const popup = () => document.querySelector<HTMLElement>('[data-slot="tooltip-popup"]')!;+ await expect.poll(() => popup()?.querySelectorAll("a").length).toBe(40);+ await expect.poll(() => popup().getBoundingClientRect().top).toBeGreaterThanOrEqual(0);+ await expect+ .poll(() => popup().getBoundingClientRect().bottom)+ .toBeLessThanOrEqual(window.innerHeight);++ const lastRow = popup().querySelector<HTMLAnchorElement>("li:last-child a")!;+ expect(lastRow.getBoundingClientRect().top).toBeGreaterThan(+ popup().getBoundingClientRect().bottom,+ );+ await act(() => userEvent.wheel(popup(), { delta: { y: 10_000 } }));+ await expect+ .poll(() => lastRow.getBoundingClientRect().bottom)+ .toBeLessThanOrEqual(popup().getBoundingClientRect().bottom);+ expect(lastRow.getBoundingClientRect().top).toBeGreaterThanOrEqual(+ popup().getBoundingClientRect().top,+ );+ await act(() => userEvent.click(lastRow));+ expect(onOpenPullRequest).toHaveBeenCalledExactlyOnceWith(expect.anything(), lastRow.href);+ } finally {+ await act(async () => root.unmount());+ container.remove();+ await page.viewport(previousViewport.width, previousViewport.height);+ }+});diff --git a/apps/web/src/components/ThreadStatusIndicators.tsx b/apps/web/src/components/ThreadStatusIndicators.tsxindex 6ec5aec1ec1..6688e06d1ab 100644--- a/apps/web/src/components/ThreadStatusIndicators.tsx+++ b/apps/web/src/components/ThreadStatusIndicators.tsx@@ -298,7 +298,7 @@ function PullRequestBadge({variant="glass"className="pointer-events-auto w-80 max-w-[calc(100vw-2rem)] text-left whitespace-normal">- <div className="-mx-1">+ <div className="-mx-1 max-h-[calc(var(--available-height)-0.5rem-2px)] overflow-y-auto overscroll-contain">{visibleThreadPullRequests(pullRequests).length > 0 ? (<ThreadPullRequestsMiniListpullRequests={pullRequests}@@ -398,7 +398,7 @@ function ThreadPullRequestMiniListItem({href={url}target="_blank"rel="noopener noreferrer"- className="flex min-w-0 items-center gap-2 rounded-sm px-1 py-1 hover:bg-accent focus-visible:bg-accent focus-visible:outline-2 focus-visible:outline-ring"+ className="flex min-w-0 items-center gap-2 rounded-sm px-1 py-1 hover:bg-accent focus-visible:bg-accent focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"onPointerDown={(event) => event.stopPropagation()}onClick={(event) => onOpenPullRequest(event, url)}>