Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(chat): add toggle to hide website icon on message links (#16521)

Arvin Xu64ac08888cac
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.json
index 7fb38f0a12b..e2270fe8835 100644
--- a/locales/en-US/setting.json
+++ b/locales/en-US/setting.json
@@ -615,6 +615,9 @@
"settingChatAppearance.fontSize.marks.normal": "Standard",
"settingChatAppearance.fontSize.title": "Font Size",
"settingChatAppearance.highlighterTheme.title": "Code Highlight Theme",
+ "settingChatAppearance.linkIcon.desc": "Turn this off if you don't need it.",
+ "settingChatAppearance.linkIcon.previewMessage": "Check out <site></site> and <repo></repo> for more details.",
+ "settingChatAppearance.linkIcon.title": "Show icons in message links",
"settingChatAppearance.mermaidTheme.title": "Mermaid Theme",
"settingChatAppearance.title": "Chat Appearance",
"settingChatAppearance.transitionMode.desc": "Choose how chat messages appear",
diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.json
index 9177e90b3e6..2b21965ca45 100644
--- a/locales/zh-CN/setting.json
+++ b/locales/zh-CN/setting.json
@@ -615,6 +615,9 @@
"settingChatAppearance.fontSize.marks.normal": "标准",
"settingChatAppearance.fontSize.title": "字体大小",
"settingChatAppearance.highlighterTheme.title": "代码高亮主题",
+ "settingChatAppearance.linkIcon.desc": "如果不需要显示,可关闭此项。",
+ "settingChatAppearance.linkIcon.previewMessage": "查看 <site></site> 和 <repo></repo> 了解更多。",
+ "settingChatAppearance.linkIcon.title": "在消息链接中显示图标",
"settingChatAppearance.mermaidTheme.title": "Mermaid 主题",
"settingChatAppearance.title": "聊天外观",
"settingChatAppearance.transitionMode.desc": "选择聊天消息的显示方式",
diff --git a/packages/locales/src/default/setting.ts b/packages/locales/src/default/setting.ts
index f2d0d66c684..3c8488145ac 100644
--- a/packages/locales/src/default/setting.ts
+++ b/packages/locales/src/default/setting.ts
@@ -684,6 +684,10 @@ export default {
'settingChatAppearance.fontSize.marks.normal': 'Standard',
'settingChatAppearance.fontSize.title': 'Font Size',
'settingChatAppearance.highlighterTheme.title': 'Code Highlight Theme',
+ 'settingChatAppearance.linkIcon.desc': "Turn this off if you don't need it.",
+ 'settingChatAppearance.linkIcon.previewMessage':
+ 'Check out <site></site> and <repo></repo> for more details.',
+ 'settingChatAppearance.linkIcon.title': 'Show icons in message links',
'settingChatAppearance.mermaidTheme.title': 'Mermaid Theme',
'settingChatAppearance.title': 'Chat Appearance',
'settingChatAppearance.transitionMode.desc': 'Choose how chat messages appear',
diff --git a/packages/types/src/user/settings/general.ts b/packages/types/src/user/settings/general.ts
index 6352ee10816..1f6642d4362 100644
--- a/packages/types/src/user/settings/general.ts
+++ b/packages/types/src/user/settings/general.ts
@@ -15,6 +15,12 @@ export interface UserGeneralConfig {
* @default true
*/
enableAutoScrollOnStreaming?: boolean;
+ /**
+ * Whether to show the website/favicon icon before links in chat messages.
+ * Turning it off renders plain links, which copy cleanly into email and other apps.
+ * @default true
+ */
+ enableMessageLinkIcon?: boolean;
fontSize: number;
highlighterTheme?: HighlighterProps['theme'];
isDevMode: boolean;
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/LinkChip.tsx b/src/features/Conversation/Markdown/plugins/Link/Render/LinkChip.tsx
index 2109cbbf623..1d507e98216 100644
--- a/src/features/Conversation/Markdown/plugins/Link/Render/LinkChip.tsx
+++ b/src/features/Conversation/Markdown/plugins/Link/Render/LinkChip.tsx
@@ -22,13 +22,13 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
interface LinkChipProps {
href?: string;
- icon: ReactNode;
+ icon?: ReactNode;
label: string;
}
const LinkChip = memo<LinkChipProps>(({ href, icon, label }) => (
<a className={styles.chip} href={href} rel="noopener noreferrer" target="_blank">
- <span className={styles.icon}>{icon}</span>
+ {icon && <span className={styles.icon}>{icon}</span>}
{label}
</a>
));
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx b/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx
new file mode 100644
index 00000000000..a9765e939b3
--- /dev/null
+++ b/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx
@@ -0,0 +1,104 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { render } from '@testing-library/react';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import Render from './index';
+
+// `enableMessageLinkIcon` is read via useUserStore(selector). We drive the
+// selector's return value through this module-level flag so each case can flip
+// the "Link Icon" setting on/off without a real store.
+let mockShowIcon = true;
+
+vi.mock('@/store/user', () => ({
+ useUserStore: (selector: (s: unknown) => unknown) => selector(undefined),
+}));
+
+vi.mock('@/store/user/selectors', () => ({
+ userGeneralSettingsSelectors: {
+ enableMessageLinkIcon: () => mockShowIcon,
+ },
+}));
+
+const renderLink = (properties: Record<string, unknown>) =>
+ render(
+ <Render id="msg-1" node={{ properties }} tagName="lobeLink" type="element">
+ {null}
+ </Render>,
+ );
+
+afterEach(() => {
+ mockShowIcon = true;
+});
+
+describe('Link Render — message link icon toggle', () => {
+ describe('when enableMessageLinkIcon is ON (default)', () => {
+ it('renders a generic link with a leading favicon icon', () => {
+ mockShowIcon = true;
+ const { container } = renderLink({
+ linkDomain: 'thecoffee.club',
+ linkHref: 'https://thecoffee.club',
+ linkKind: 'generic',
+ linkLabel: 'https://thecoffee.club',
+ });
+ const anchor = container.querySelector('a')!;
+ expect(anchor).toBeTruthy();
+ expect(anchor.getAttribute('href')).toBe('https://thecoffee.club');
+ // icon span + favicon <img> present before the label
+ expect(anchor.querySelector('span')).toBeTruthy();
+ expect(anchor.querySelector('img')).toBeTruthy();
+ expect(anchor.textContent).toContain('https://thecoffee.club');
+ });
+
+ it('renders a github link with an icon (svg)', () => {
+ mockShowIcon = true;
+ const { container } = renderLink({
+ linkHref: 'https://github.com/lobehub/lobehub',
+ linkKind: 'github',
+ linkLabel: 'lobehub/lobehub',
+ });
+ const anchor = container.querySelector('a')!;
+ expect(anchor.querySelector('span')).toBeTruthy();
+ expect(anchor.querySelector('svg')).toBeTruthy();
+ });
+ });
+
+ describe('when enableMessageLinkIcon is OFF', () => {
+ it('renders a generic link as a plain anchor with NO icon', () => {
+ mockShowIcon = false;
+ const { container } = renderLink({
+ linkDomain: 'thecoffee.club',
+ linkHref: 'https://thecoffee.club',
+ linkKind: 'generic',
+ linkLabel: 'https://thecoffee.club',
+ });
+ const anchor = container.querySelector('a')!;
+ expect(anchor).toBeTruthy();
+ expect(anchor.getAttribute('href')).toBe('https://thecoffee.club');
+ // no icon span, no favicon img — copies cleanly into email/other apps
+ expect(anchor.querySelector('span')).toBeNull();
+ expect(anchor.querySelector('img')).toBeNull();
+ expect(anchor.textContent).toBe('https://thecoffee.club');
+ });
+
+ it('drops the icon for every link kind (github / linear / email)', () => {
+ mockShowIcon = false;
+ for (const properties of [
+ {
+ linkHref: 'https://github.com/lobehub/lobehub',
+ linkKind: 'github',
+ linkLabel: 'lobehub/lobehub',
+ },
+ { linkHref: 'https://linear.app/x/issue/ABC-1', linkKind: 'linear', linkLabel: 'ABC-1' },
+ { linkHref: 'mailto:[email protected]', linkKind: 'email', linkLabel: '[email protected]' },
+ ]) {
+ const { container } = renderLink(properties);
+ const anchor = container.querySelector('a')!;
+ expect(anchor.querySelector('span')).toBeNull();
+ expect(anchor.querySelector('svg')).toBeNull();
+ expect(anchor.querySelector('img')).toBeNull();
+ }
+ });
+ });
+});
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/index.tsx b/src/features/Conversation/Markdown/plugins/Link/Render/index.tsx
index bbed80d9d5d..a7deeae3eab 100644
--- a/src/features/Conversation/Markdown/plugins/Link/Render/index.tsx
+++ b/src/features/Conversation/Markdown/plugins/Link/Render/index.tsx
@@ -4,6 +4,9 @@ import { Github } from '@lobehub/icons';
import { Mail } from 'lucide-react';
import { memo } from 'react';
+import { useUserStore } from '@/store/user';
+import { userGeneralSettingsSelectors } from '@/store/user/selectors';
+
import { type MarkdownElementProps } from '../../type';
import { type LobeLinkKind } from '../parse';
import FaviconIcon from './FaviconIcon';
@@ -21,9 +24,14 @@ interface LobeLinkProperties {
const Render = memo<MarkdownElementProps<LobeLinkProperties>>(({ node }) => {
const { linkHref, linkKind, linkLabel, linkDomain } = node?.properties || {};
+ const showIcon = useUserStore(userGeneralSettingsSelectors.enableMessageLinkIcon);
const label = linkLabel || linkHref || '';
+ if (!showIcon) {
+ return <LinkChip href={linkHref} label={label} />;
+ }
+
if (linkKind === 'github') {
return <LinkChip href={linkHref} icon={<Github size={ICON_SIZE} />} label={label} />;
}
diff --git a/src/routes/(main)/settings/chat-appearance/features/ChatAppearance/LinkIconPreview.tsx b/src/routes/(main)/settings/chat-appearance/features/ChatAppearance/LinkIconPreview.tsx
new file mode 100644
index 00000000000..8dee569e892
--- /dev/null
+++ b/src/routes/(main)/settings/chat-appearance/features/ChatAppearance/LinkIconPreview.tsx
@@ -0,0 +1,74 @@
+'use client';
+
+import { createStaticStyles } from 'antd-style';
+import { memo } from 'react';
+import { Trans } from 'react-i18next';
+
+import { type LobeLinkKind } from '@/features/Conversation/Markdown/plugins/Link/parse';
+import LinkRender from '@/features/Conversation/Markdown/plugins/Link/Render';
+
+const styles = createStaticStyles(({ css, cssVar }) => ({
+ bubble: css`
+ align-self: flex-start;
+
+ padding-block: 10px;
+ padding-inline: 14px;
+ border-radius: 12px;
+
+ font-size: 14px;
+ line-height: 1.8;
+ color: ${cssVar.colorText};
+
+ background: ${cssVar.colorFillTertiary};
+ `,
+}));
+
+interface SampleLinkProps {
+ domain?: string;
+ href: string;
+ kind: LobeLinkKind;
+ label: string;
+}
+
+// Reuse the real message link renderer so the preview reflects the live
+// `enableMessageLinkIcon` setting exactly as chat messages do.
+const SampleLink = memo<SampleLinkProps>(({ kind, href, label, domain }) => (
+ <LinkRender
+ id={`link-icon-preview-${kind}`}
+ node={{ properties: { linkDomain: domain, linkHref: href, linkKind: kind, linkLabel: label } }}
+ tagName="lobeLink"
+ type="element"
+ >
+ {null}
+ </LinkRender>
+));
+
+const LinkIconPreview = memo(() => (
+ <div className={styles.bubble}>
+ <Trans
+ i18nKey="settingChatAppearance.linkIcon.previewMessage"
+ ns="setting"
+ components={{
+ repo: (
+ <SampleLink
+ href="https://github.com/lobehub/lobehub"
+ kind="github"
+ label="lobehub/lobehub"
+ />
+ ),
+ site: (
+ <SampleLink
+ domain="lobehub.com"
+ href="https://lobehub.com"
+ kind="generic"
+ label="lobehub.com"
+ />
+ ),
+ }}
+ />
+ </div>
+));
+
+LinkIconPreview.displayName = 'LinkIconPreview';
+
+export default LinkIconPreview;
diff --git a/src/routes/(main)/settings/chat-appearance/features/ChatAppearance/index.tsx b/src/routes/(main)/settings/chat-appearance/features/ChatAppearance/index.tsx
index 5ac8760604e..bd965f38cc6 100644
--- a/src/routes/(main)/settings/chat-appearance/features/ChatAppearance/index.tsx
+++ b/src/routes/(main)/settings/chat-appearance/features/ChatAppearance/index.tsx
@@ -21,6 +21,7 @@ import { settingsSelectors } from '@/store/user/selectors';
import ChatPreview from './ChatPreview';
import ChatTransitionPreview from './ChatTransitionPreview';
import HighlighterPreview from './HighlighterPreview';
+import LinkIconPreview from './LinkIconPreview';
import MermaidPreview from './MermaidPreview';
const ChatAppearance = memo(() => {
@@ -95,6 +96,27 @@ const ChatAppearance = memo(() => {
{null}
</FormGroup>
+ <FormGroup
+ collapsible={false}
+ desc={t('settingChatAppearance.linkIcon.desc')}
+ gap={16}
+ title={t('settingChatAppearance.linkIcon.title')}
+ variant={'filled'}
+ extra={
+ <Flexbox horizontal align={'center'} gap={8}>
+ {loadingStates.enableMessageLinkIcon && (
+ <Icon spin icon={Loader2Icon} size={16} style={{ opacity: 0.5 }} />
+ )}
+ <Switch
+ checked={general.enableMessageLinkIcon ?? true}
+ onChange={(checked) => handleChange('enableMessageLinkIcon', checked)}
+ />
+ </Flexbox>
+ }
+ >
+ <LinkIconPreview />
+ </FormGroup>
+
<FormGroup
collapsible={false}
desc={t('settingChatAppearance.fontSize.desc')}
diff --git a/src/store/user/slices/settings/selectors/general.ts b/src/store/user/slices/settings/selectors/general.ts
index dca934684b5..b2c5ec9cc66 100644
--- a/src/store/user/slices/settings/selectors/general.ts
+++ b/src/store/user/slices/settings/selectors/general.ts
@@ -33,12 +33,14 @@ const currentResponseLanguage = (s: UserStore): Locales => {
const telemetry = (s: UserStore) => generalConfig(s).telemetry;
const enableAutoScrollOnStreaming = (s: UserStore) =>
generalConfig(s).enableAutoScrollOnStreaming ?? true;
+const enableMessageLinkIcon = (s: UserStore) => generalConfig(s).enableMessageLinkIcon ?? true;
export const userGeneralSettingsSelectors = {
animationMode,
config: generalConfig,
contextMenuMode,
enableAutoScrollOnStreaming,
+ enableMessageLinkIcon,
fontSize,
highlighterTheme,
mermaidTheme,