Skip to content

Commit cd91de5

Browse files
committed
fix(web): keep external link labels breakable
Review follow-up on the #8807 port. Routing agent images through the expanded preview wrapped an anchor's children in MarkdownLinkContext, which made MarkdownExternalLinkContent's first child an element rather than the leading text string it splits with <wbr/>. External links mixing leading text with inline formatting rendered their whole label as one whitespace-nowrap run and overflowed the chat column. The provider now wraps the result instead of the children. The defect is upstream's too.
1 parent 723f1ea commit cd91de5

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,14 @@ describe("ChatMarkdown Windows file links", () => {
332332
expect(html).not.toContain("d:alert");
333333
expect(html).not.toContain("chat-markdown-file-link");
334334
});
335+
336+
it("keeps external link labels breakable when they mix text and formatting", () => {
337+
const markup = renderToStaticMarkup(
338+
<ChatMarkdown text="[a very long external link label that should wrap **bold**](https://example.com/x)" />,
339+
);
340+
341+
// The leading text is split with <wbr/> so a long label wraps inside the
342+
// chat column instead of overflowing it.
343+
expect(markup).toContain("<wbr");
344+
});
335345
});

apps/web/src/components/ChatMarkdown.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,9 +2229,15 @@ function ChatMarkdown({
22292229
}}
22302230
>
22312231
{faviconHost && hastHasText(node) ? (
2232-
<MarkdownExternalLinkContent host={faviconHost} plainText={plainHastText(node)}>
2233-
{linkChildren}
2234-
</MarkdownExternalLinkContent>
2232+
// The provider wraps the result rather than the children:
2233+
// MarkdownExternalLinkContent inspects its first child for the
2234+
// leading text it splits with <wbr/>, and an element there
2235+
// makes the whole label one unbreakable run.
2236+
<MarkdownLinkContext value>
2237+
<MarkdownExternalLinkContent host={faviconHost} plainText={plainHastText(node)}>
2238+
{children}
2239+
</MarkdownExternalLinkContent>
2240+
</MarkdownLinkContext>
22352241
) : (
22362242
linkChildren
22372243
)}

0 commit comments

Comments
 (0)