From 738ce3ec7b3d732b58028e9aea378b83c0d23a59 Mon Sep 17 00:00:00 2001 From: Addison King Date: Tue, 24 Nov 2026 18:18:53 -0500 Subject: [PATCH] fix(web): cmd+click sidebar issue badge opens in browser --- .../src/components/ChatView.browser.test.tsx | 40 ++++++++++++++++++- .../components/sidebar/SidebarThreadRow.tsx | 18 +++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx index f799339454475..1f47d4a12a053 100644 --- a/apps/web/src/components/ChatView.browser.test.tsx +++ b/apps/web/src/components/ChatView.browser.test.tsx @@ -1,5 +1,9 @@ import { createMemoryHistory } from "@tanstack/react-router"; -import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment"; +import { + scopeProjectRef, + scopedThreadKey, + scopeThreadRef, +} from "@t3tools/client-runtime/environment"; import { EnvironmentId, IssueTrackerKind, @@ -243,10 +247,12 @@ it("opens a linked Linear issue from an inactive thread's sidebar badge", async // AppRoot brings its own router. router: false, }); - const badge = page.getByRole("button", { + const badge = page.getByRole("link", { name: `Issue ${issue.displayKey}: ${issue.title}, Open`, }); await expect.element(badge).toBeVisible(); + expect(badge.element()).toHaveAttribute("href", issue.url); + expect(badge.element()).toHaveAttribute("target", "_blank"); expect(badge.element().querySelector("span")).toHaveClass(/text-emerald-600/); expect(badge.element()).toHaveTextContent("123"); expect(badge.element()).not.toHaveTextContent("#"); @@ -263,6 +269,36 @@ it("opens a linked Linear issue from an inactive thread's sidebar badge", async await vi.waitFor(() => expect(groupedBadge.element().querySelector("span")).toHaveClass(/text-emerald-600/), ); + // Modified clicks on the single-issue badge fall through to the anchor so the browser opens it + // instead of navigating or opening the in-app panel. + for (const modifier of [{ metaKey: true }, { ctrlKey: true }] as const) { + let sawUnpreventedClick = false; + // Register on the React root after mount so this runs after React's delegated click handler + // even when the handler calls stopPropagation(), preventing Chromium from opening a real tab. + const preventExternalNavigation = (event: MouseEvent) => { + if (event.target !== badge.element()) return; + sawUnpreventedClick = !event.defaultPrevented; + event.preventDefault(); + }; + _app.container.addEventListener("click", preventExternalNavigation); + try { + const modifiedClick = new MouseEvent("click", { + bubbles: true, + cancelable: true, + ...modifier, + }); + await act(() => badge.element().dispatchEvent(modifiedClick)); + } finally { + _app.container.removeEventListener("click", preventExternalNavigation); + } + expect(sawUnpreventedClick).toBe(true); + expect(router.history.location.pathname).toBe(`/${ENVIRONMENT_ID}/${first.id}`); + expect( + useRightPanelStore.getState().byThreadKey[ + scopedThreadKey(scopeThreadRef(ENVIRONMENT_ID, linked.id)) + ], + ).toBeUndefined(); + } await userEvent.hover(badge); const issueName = `Issue ${issue.displayKey}: ${liveTitle}`; const previewLink = page.getByRole("link", { name: issueName }); diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx index 9387988979e55..29d32bc2780aa 100644 --- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx @@ -1181,14 +1181,32 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP : gt("{count, plural, one {{count} linked issue} other {{count} linked issues}}", { count: issueCount, }); + const opensIssueList = issueCount > 1; const issueBadge = firstIssue ? ( + ) + } aria-label={issueLabel} onPointerDown={(event) => event.stopPropagation()} onClick={(event) => { event.stopPropagation(); + if ( + !opensIssueList && + (event.metaKey || + event.ctrlKey || + event.shiftKey || + event.altKey || + event.button === 1) + ) { + return; + } + event.preventDefault(); openLinkedItems(); }} />