@devries-cameron20 / t3code Mirror · read-only / commits / fd08b170b6
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 10:45 UTC

fix(web): punctuation after a file chip stays on the chip's line (#26871)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Paweł committed Oct 31, 2026 at 02:44 UTC fd08b170b6bec43291b385f1b2813a9d1b97d585
3 files changed +78 -1
apps/web/src/components/ChatMarkdown.tsx
+5 -1
@@ -206,6 +206,7 @@ import {
206 import { MarkdownExternalLinkContent } from "./chat/MarkdownExternalLink";
207 import { MarkdownFileLink } from "./chat/MarkdownFileLink";
208 import { canUseMarkdownFileShellActions } from "./chat/MarkdownFileLink.logic";
209 +import { rehypeChipPunctuation } from "./chat/markdownChipPunctuation";
210 import { handleMarkdownFragmentClick, rehypeHeadingIds } from "./chat/markdownFragments";
211 import { rehypeTextDirection } from "./chat/markdownTextDirection";
212 import { hastHasText, hastPlainTextDeep, plainHastText } from "./chat/markdownHast.logic";
@@ -391,11 +392,13 @@ const CHAT_MARKDOWN_RENDER_REHYPE_PLUGINS = [
392 ...CHAT_MARKDOWN_REHYPE_PLUGINS,
393 rehypeHeadingIds,
394 rehypeTextDirection,
395 + rehypeChipPunctuation,
396 ] satisfies NonNullable<ReactMarkdownOptions["rehypePlugins"]>;
397
398 const CHAT_MARKDOWN_LITERAL_HTML_REHYPE_PLUGINS = [
399 rehypeHeadingIds,
400 rehypeTextDirection,
401 + rehypeChipPunctuation,
402 ] satisfies NonNullable<ReactMarkdownOptions["rehypePlugins"]>;
403
404 function markdownUrlTransform(href: string) {
@@ -1323,7 +1326,8 @@ const CHAT_MARKDOWN_COMPONENTS = {
1326 chip
1327 ) : (
1328 <span data-markdown-copy={copyMarkdown}>
1326 - {children} {chip}
1329 + <span className="whitespace-normal">{children} </span>
1330 + {chip}
1331 </span>
1332 );
1333 },
apps/web/src/components/chat/markdownChipPunctuation.test.ts new
+32
@@ -0,0 +1,32 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { rehypeChipPunctuation } from "./markdownChipPunctuation";
4 +
5 +const text = (value: string) => ({ type: "text", value });
6 +const element = (tagName: string, children: object[]) => ({
7 + type: "element",
8 + tagName,
9 + properties: {} as Record<string, unknown>,
10 + children,
11 +});
12 +
13 +function paired(block: ReturnType<typeof element>) {
14 + rehypeChipPunctuation()({ type: "root", children: [block] });
15 + return block.children;
16 +}
17 +
18 +describe("rehypeChipPunctuation", () => {
19 + it("pairs a link with the punctuation that follows it", () => {
20 + const link = element("a", [text("a.ts")]);
21 + expect(paired(element("p", [text("See "), link, text("... next")]))).toEqual([
22 + text("See "),
23 + expect.objectContaining({ tagName: "span", children: [link, text("...")] }),
24 + text(" next"),
25 + ]);
26 + });
27 +
28 + it("leaves code blocks alone", () => {
29 + const children = [element("code", [text("a.ts")]), text(".")];
30 + expect(paired(element("pre", [...children]))).toEqual(children);
31 + });
32 +});
apps/web/src/components/chat/markdownChipPunctuation.ts new
+41
@@ -0,0 +1,41 @@
1 +type HastNode = {
2 + type?: string;
3 + tagName?: string;
4 + value?: string;
5 + properties?: Record<string, unknown>;
6 + children?: HastNode[];
7 +};
8 +
9 +const LEADING_PUNCTUATION = /^[.,:;!?…)\]}"'’”]+/;
10 +
11 +// Browsers allow a wrap after inline-flex chips even before punctuation.
12 +export function rehypeChipPunctuation() {
13 + const visit = (node: HastNode): void => {
14 + if (node.tagName === "pre" || !node.children) return;
15 + const children: HastNode[] = [];
16 + for (const child of node.children) {
17 + visit(child);
18 + const previous = children.at(-1);
19 + const punctuation =
20 + child.type === "text" && (previous?.tagName === "a" || previous?.tagName === "code")
21 + ? LEADING_PUNCTUATION.exec(child.value ?? "")?.[0]
22 + : undefined;
23 + if (!previous || !punctuation) {
24 + children.push(child);
25 + continue;
26 + }
27 + children[children.length - 1] = {
28 + type: "element",
29 + tagName: "span",
30 + properties: {
31 + className: ["has-[[data-slot=context-chip-label]]:whitespace-nowrap"],
32 + },
33 + children: [previous, { type: "text", value: punctuation }],
34 + };
35 + const rest = (child.value ?? "").slice(punctuation.length);
36 + if (rest) children.push({ ...child, value: rest });
37 + }
38 + node.children = children;
39 + };
40 + return visit;
41 +}