Skip to content

Commit cc62443

Browse files
fix(web): formatted link labels wrap inside table cells (#27781)
1 parent 6d35d09 commit cc62443

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎apps/web/src/components/ChatMarkdown.browser.test.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,23 @@ describe("ChatMarkdown favicon privacy", () => {
296296
});
297297
});
298298

299+
describe("ChatMarkdown external link labels", () => {
300+
it("keeps a leading emoji whole", async () => {
301+
setup();
302+
await using screen = await render(
303+
<ChatMarkdown cwd="/tmp/project" text="[😀 Read the documentation](https://example.com)" />,
304+
);
305+
await vi.waitFor(() => {
306+
const link = screen.container.querySelector("a");
307+
expect(link?.textContent).toContain("😀 Read");
308+
const walker = document.createTreeWalker(link!, NodeFilter.SHOW_TEXT);
309+
const textNodes: string[] = [];
310+
while (walker.nextNode()) textNodes.push(walker.currentNode.nodeValue ?? "");
311+
expect(textNodes.filter((node) => /\p{Surrogate}/u.test(node))).toEqual([]);
312+
});
313+
});
314+
});
315+
299316
describe("ChatMarkdown streaming", () => {
300317
it("runs only a complete single-line shell block after a click", async () => {
301318
setup();

‎apps/web/src/components/chat/MarkdownExternalLink.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const MarkdownLinkFavicon = memo(function MarkdownLinkFavicon({ host }: { host:
5151
function leadingExternalLinkTextLength(text: string): number {
5252
const protocol = /^(?:https?:\/\/)/i.exec(text)?.[0];
5353
if (protocol) return protocol.length;
54-
return Math.min(text.length, 1);
54+
// A whole code point, so a surrogate pair is not split across elements.
55+
return Array.from(text.slice(0, 2))[0]?.length ?? 0;
5556
}
5657

5758
// Keep short labels such as PR numbers intact in narrow table columns.

0 commit comments

Comments
 (0)