:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): keep the whole PR number visible in ref chips (#99219)
Paul D'Ambraff5442afd4d7
diff --git a/products/desktop/packages/ui/src/features/editor/components/GithubPrRefChip.test.tsx b/products/desktop/packages/ui/src/features/editor/components/GithubPrRefChip.test.tsxindex e07fc464c595..1777e7491f39 100644--- a/products/desktop/packages/ui/src/features/editor/components/GithubPrRefChip.test.tsx+++ b/products/desktop/packages/ui/src/features/editor/components/GithubPrRefChip.test.tsx@@ -54,7 +54,7 @@ describe("GithubPrRefChip", () => {});expect(usePrChecksMock).toHaveBeenCalledWith(null);- const link = screen.getByText("PostHog/posthog#23985").closest("a");+ const link = screen.getByText("#23985").closest("a");expect(link).not.toBeNull();await userEvent.hover(link as HTMLAnchorElement);diff --git a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.stories.tsx b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.stories.tsxindex d5377ae24aea..74bc7706ae48 100644--- a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.stories.tsx+++ b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.stories.tsx@@ -37,7 +37,9 @@ export const PullRequestNumberWidth: Story = {render: () => (<div className="flex flex-col items-start gap-4 text-[13px]"><div className="flex flex-col gap-1">- <span className="text-(--gray-11)">Before</span>+ <span className="text-(--gray-11)">+ Without preservation: the number ellipsizes+ </span><div className="w-[22ch]"><GithubRefChipLinkhref="https://github.com/example-org/example-repo/pull/123456789"@@ -49,7 +51,9 @@ export const PullRequestNumberWidth: Story = {</div></div><div className="flex flex-col gap-1">- <span className="text-(--gray-11)">After</span>+ <span className="text-(--gray-11)">+ With preservation: the number stays whole+ </span><div className="w-[22ch]"><GithubRefChipLinkhref="https://github.com/example-org/example-repo/pull/123456789"diff --git a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.test.tsx b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.test.tsxindex fa1961a18d3b..be0de6ee0255 100644--- a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.test.tsx+++ b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.test.tsx@@ -16,8 +16,29 @@ describe("GithubRefChip", () => {expect(carrier?.getAttribute(GITHUB_REF_URL_ATTR)).toBe(href);});- it("truncates a pull request label from the start so its number survives", () => {- render(+ it("keeps the whole pull request number outside the truncating span", () => {+ const { container } = render(+ <GithubRefChip+ href="https://github.com/PostHog/posthog/pull/123456789"+ kind="pr"+ >+ PostHog/posthog#123456789+ </GithubRefChip>,+ );++ const label = container.querySelector(".truncate");+ expect(label).toHaveTextContent("PostHog/posthog");+ expect(label).not.toHaveAttribute("dir");+ expect(label).toHaveStyle({+ maxWidth: "min(16rem, calc(100% - 1rem - 10ch))",+ });+ const number = screen.getByText("#123456789");+ expect(number).toHaveClass("shrink-0");+ expect(number.parentElement).not.toHaveAttribute("dir");+ });++ it("clips the chip so a long preserved number cannot paint past the edge", () => {+ const { container } = render(<GithubRefChiphref="https://github.com/PostHog/posthog/pull/123456789"kind="pr"@@ -26,10 +47,7 @@ describe("GithubRefChip", () => {</GithubRefChip>,);- const label = screen.getByText("PostHog/posthog#123456789");- expect(label).toHaveAttribute("dir", "ltr");- expect(label.parentElement).toHaveAttribute("dir", "rtl");- expect(label.parentElement).toHaveClass("truncate");+ expect(container.querySelector("a")).toHaveClass("overflow-hidden");});it("leaves a label that puts its number first alone", () => {diff --git a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsxindex a40758478c2d..d9a645cc437b 100644--- a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx+++ b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx@@ -24,12 +24,20 @@ interface GithubRefChipLinkProps}/**- * Truncation removes the end of a label, which for `owner/repo#number` is the- * number that tells two pull requests apart. Only labels that end in a number- * qualify: `#12 - Title` already keeps its number at the front.+ * Splits `owner/repo#number` into the part that may truncate and the number+ * that may not, so neither the start nor the end of the number is ellipsized.+ * Only labels that end in a number qualify: `#12 - Title` already keeps its+ * number at the front.*/-function endsWithRefNumber(label: ReactNode): boolean {- return typeof label === "string" && /#\d+$/.test(label);+function splitRefNumber(label: ReactNode): [string, string] | null {+ if (typeof label !== "string") {+ return null;+ }+ const match = label.match(/^(.*)(#\d+)$/);+ if (!match) {+ return null;+ }+ return [match[1], match[2]];}/**@@ -54,11 +62,14 @@ export const GithubRefChipLink = forwardRef<},ref,) {- // A right-to-left box puts the ellipsis at the start, so the trailing number- // survives truncation. The inner isolate keeps the text itself left-to-right.- // The label stays one text node on purpose: a number in its own flex item- // puts a line break into copied text.- const ellipsisAtStart = preservePrNumber && endsWithRefNumber(children);+ // The number lives in its own span that cannot shrink, so a truncating label+ // keeps the whole number readable instead of ellipsizing one end of it.+ const split = preservePrNumber ? splitRefNumber(children) : null;+ // ch because the unit scales with the label's own font: the preserved number+ // keeps roughly this many digits readable at any text size, and the label+ // span's max-width subtracts the same width so a long number cannot push the+ // chip past its cap.+ const numberCh = split ? split[1].length : 0;return (<Buttonref={ref}@@ -77,7 +88,10 @@ export const GithubRefChipLink = forwardRef<}{...buttonProps}className={cn(- "cli-file-mention focus-visible:-outline-offset-1 mx-0.5 inline-block max-w-full cursor-pointer! select-text whitespace-nowrap pl-1.5 align-baseline leading-[1.375rem] no-underline",+ // overflow-hidden: nothing in the content box shrinks below its+ // content size, so a long preserved number would otherwise paint past+ // the chip edge.+ "cli-file-mention focus-visible:-outline-offset-1 mx-0.5 inline-block max-w-full cursor-pointer! select-text overflow-hidden whitespace-nowrap pl-1.5 align-baseline leading-[1.375rem] no-underline",buttonProps.className,)}>@@ -91,16 +105,19 @@ export const GithubRefChipLink = forwardRef</><span// 1rem is the icon and its margin, which share the chip's content box- // with the label. Without that subtraction the label paints past the- // chip edge in a narrow panel instead of truncating.- className={cn(- "inline-block max-w-[min(16rem,calc(100%-1rem))] truncate align-top",- toneClass,- )}- dir={ellipsisAtStart ? "rtl" : undefined}+ // with the label; numberCh is the preserved number's width. Without+ // those subtractions the label paints past the chip edge in a narrow+ // panel instead of truncating.+ className={cn("inline-block truncate align-top", toneClass)}+ style={{+ maxWidth: `min(16rem, calc(100% - 1rem - ${numberCh}ch))`,+ }}>- {ellipsisAtStart ? <span dir="ltr">{children}</span> : children}+ {split ? split[0] : children}</span>+ {split && (+ <span className={cn("shrink-0 align-top", toneClass)}>{split[1]}</span>+ )}</Button>);});diff --git a/products/desktop/packages/ui/src/features/editor/components/PrRefChip.test.tsx b/products/desktop/packages/ui/src/features/editor/components/PrRefChip.test.tsxindex 08119297e2e9..7c0c7e8e074e 100644--- a/products/desktop/packages/ui/src/features/editor/components/PrRefChip.test.tsx+++ b/products/desktop/packages/ui/src/features/editor/components/PrRefChip.test.tsx@@ -18,7 +18,7 @@ describe("PrRefChip", () => {const href = "https://github.com/PostHog/posthog/pull/23985";async function hoverChip(): Promise<void> {- const link = screen.getByText("PostHog/posthog#23985").closest("a");+ const link = screen.getByText("#23985").closest("a");expect(link).not.toBeNull();await userEvent.hover(link as HTMLAnchorElement);}diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsxindex f738497274eb..4c47417afd02 100644--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx@@ -108,7 +108,8 @@ Verdict: valid.<ChatMarkdown content="Review https://github.com/PostHog/posthog/pull/23985" />,);- expect(html).toContain("PostHog/posthog#23985");+ expect(html).toContain(">PostHog/posthog</span>");+ expect(html).toContain(">#23985</span>");expect(html).toContain('aria-label="Open"');expect(html).toContain('data-github-ref-url="https://github.com/PostHog/posthog/pull/23985"',@@ -120,7 +121,8 @@ Verdict: valid."https://github.com/PostHog/posthog/pull/86811/changes#r3832262653";const html = renderStatic(<ChatMarkdown content={href} />);- expect(html).toContain("Comment on PR #86811");+ expect(html).toContain(">Comment on PR </span>");+ expect(html).toContain(">#86811</span>");expect(html).toContain(`data-github-ref-url="${href}"`);});});diff --git a/products/desktop/packages/ui/src/features/sessions/components/copyContextMenu.integration.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/copyContextMenu.integration.test.tsxindex 9a9aa8c066c1..6037c709a910 100644--- a/products/desktop/packages/ui/src/features/sessions/components/copyContextMenu.integration.test.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/copyContextMenu.integration.test.tsx@@ -73,7 +73,7 @@ describe("conversation context-menu copy (integration)", () => {render(<Harness />);// Right-click the chip label, exactly as a user would.- const label = screen.getByText("PostHog/posthog#63995");+ const label = screen.getByText("#63995");fireEvent.contextMenu(label);const copyItem = await screen.findByText("Copy");