From 4c0d89ef812755db088726b466ce0ce19099ea5a Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Thu, 13 Aug 2026 11:15:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20vendor=20formatChatMes?= =?UTF-8?q?sageLinks=20and=20trim=20surrounding=20newlines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copy the `formatChatMessageLinks` function locally so we can iterate on it without patching the upstream dependency. Use the local copy to trim `\n` characters at the beginning and end of chat messages, which were leaking into the rendered output. --- CHANGELOG.md | 1 + .../chat/components/ChatMessageBody.tsx | 2 +- src/frontend/src/features/chat/utils.tsx | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/frontend/src/features/chat/utils.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 6acf2696..44fce3fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ### Changed - 🔥(frontend) drop unused vendored ConnectionObserver +- 🐛(frontend) vendor formatChatMessageLinks and trim surrounding newlines ### Fixed diff --git a/src/frontend/src/features/chat/components/ChatMessageBody.tsx b/src/frontend/src/features/chat/components/ChatMessageBody.tsx index 67381ea4..f9decfdc 100644 --- a/src/frontend/src/features/chat/components/ChatMessageBody.tsx +++ b/src/frontend/src/features/chat/components/ChatMessageBody.tsx @@ -1,6 +1,6 @@ import { ChatRow } from '@/stores/chat' import React, { useMemo } from 'react' -import { formatChatMessageLinks } from '@livekit/components-react' +import { formatChatMessageLinks } from '../utils' import { css } from '@/styled-system/css' import { Text } from '@/primitives' diff --git a/src/frontend/src/features/chat/utils.tsx b/src/frontend/src/features/chat/utils.tsx new file mode 100644 index 00000000..7542e3b1 --- /dev/null +++ b/src/frontend/src/features/chat/utils.tsx @@ -0,0 +1,32 @@ +import { tokenize, createDefaultGrammar } from '@livekit/components-core' +import { ReactNode } from 'react' + +const defaultGrammar = Object.freeze(createDefaultGrammar()) + +export function formatChatMessageLinks(message: string): ReactNode { + const trimmedMessage = message.replace(/^[\r\n]+|[\r\n]+$/g, '') + return tokenize(trimmedMessage, defaultGrammar).map((tok, i) => { + if (typeof tok === `string`) { + return tok + } else { + const content = tok.content.toString() + const href = + tok.type === `url` + ? /^http(s?):\/\//.test(content) + ? content + : `https://${content}` + : `mailto:${content}` + return ( + + {content} + + ) + } + }) +}