@devries-cameron20 / t3code-1 / commits / eb5612dda8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): prevent long links from creating per-character elements (#26843)

Co-authored-by: ALMs <255698775+saimircelaj0@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net>

ALMs committed Oct 31, 2026 at 04:21 UTC eb5612dda8b3bb5c7372718eba65b98aacc3ddb5
2 files changed +64 -12
apps/web/src/components/chat/MarkdownExternalLink.browser.test.tsx new
+54
@@ -0,0 +1,54 @@
1 +import { expect, it, vi } from "vite-plus/test";
2 +
3 +import { render } from "../../../test/render";
4 +import "../../index.css";
5 +
6 +import { MarkdownLinkContext } from "./ChatMarkdownMedia";
7 +import { MarkdownExternalLinkContent } from "./MarkdownExternalLink";
8 +
9 +it.each(["plain", "formatted"] as const)(
10 + "keeps %s long links bounded in the DOM without losing text or wrapping",
11 + async (kind) => {
12 + const link = (url: string) => (
13 + <div className="chat-markdown w-64">
14 + <table>
15 + <tbody>
16 + <tr>
17 + <td>
18 + <a href={url}>
19 + <MarkdownExternalLinkContent
20 + host="github.com"
21 + plainText={kind === "plain" ? url : null}
22 + >
23 + <MarkdownLinkContext value>
24 + {url}
25 + {kind === "formatted" ? <strong> details</strong> : null}
26 + </MarkdownLinkContext>
27 + </MarkdownExternalLinkContent>
28 + </a>
29 + </td>
30 + </tr>
31 + </tbody>
32 + </table>
33 + </div>
34 + );
35 + const url = (length: number) => `https://github.com/search?q=${"a".repeat(length)}`;
36 + await using screen = await render(link(url(128)));
37 + const initialElementCount = screen.container.querySelectorAll("a *").length;
38 +
39 + const longUrl = url(16_000);
40 + await screen.rerender(link(longUrl));
41 + await vi.waitFor(() => {
42 + const anchor = screen.container.querySelector("a")!;
43 + const table = screen.container.querySelector("table")!;
44 + expect(anchor.getAttribute("href")).toBe(longUrl);
45 + expect(anchor.textContent).toBe(longUrl + (kind === "formatted" ? " details" : ""));
46 + expect(anchor.querySelectorAll("*")).toHaveLength(initialElementCount);
47 + if (kind === "formatted")
48 + expect(anchor.querySelector("strong")?.textContent).toBe(" details");
49 + expect(table.scrollWidth).toBeLessThanOrEqual(
50 + screen.container.firstElementChild!.clientWidth,
51 + );
52 + });
53 + },
54 +);
apps/web/src/components/chat/MarkdownExternalLink.tsx
+10 -12
@@ -1,6 +1,6 @@
1 import { faviconUrlForOrigin } from "@t3tools/shared/favicon";
2 import { GlobeIcon } from "lucide-react";
3 -import { Children, Fragment, memo, useState, type ReactNode } from "react";
3 +import { Children, memo, useState, type ReactNode } from "react";
4
5 import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
6
@@ -54,18 +54,16 @@ function leadingExternalLinkTextLength(text: string): number {
54 return Math.min(text.length, 1);
55 }
56
57 -// Long words such as URLs can break after any character so they fit narrow
58 -// table columns. Short ones, like a PR number, stay whole.
57 +// Keep short labels such as PR numbers intact in narrow table columns.
58 function breakableExternalLinkText(text: string): ReactNode[] {
59 return Array.from(text.matchAll(/\s+|\S+/g), ({ 0: word, index: start }) =>
61 - word.length <= 16
62 - ? word
63 - : Array.from(word, (character, offset) => (
64 - <Fragment key={`${start + offset}:${character}`}>
65 - {character}
66 - <wbr />
67 - </Fragment>
68 - )),
60 + word.length <= 16 ? (
61 + word
62 + ) : (
63 + <span key={start} className="[overflow-wrap:anywhere]">
64 + {word}
65 + </span>
66 + ),
67 );
68 }
69
@@ -110,7 +108,7 @@ export function MarkdownExternalLinkContent({
108
109 return (
110 <>
113 - <span className="whitespace-nowrap">
111 + <span className="[overflow-wrap:anywhere]">
112 <MarkdownLinkFavicon host={host} />
113 {firstChild}
114 </span>