fix(citations): only render citation badges for links in citationMap

Project URLs and regular links should be rendered as plain underlined
links, not as citation badges. Only links that are actual citations
(present in citationMap) should be rendered as badges.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
ruitanglin
2026-02-06 15:15:45 +08:00
parent c87f176fac
commit 7a3a5f5196

View File

@@ -77,8 +77,8 @@ export function MessageListItem({
/** /**
* Custom link component that handles citations and external links * Custom link component that handles citations and external links
* For AI messages: external links (http/https) are rendered as CitationLink badges * Only links that are in citationMap are rendered as CitationLink badges
* For human messages: links are rendered as plain text/links * Other links (project URLs, regular links) are rendered as plain links
*/ */
function MessageLink({ function MessageLink({
href, href,
@@ -91,27 +91,11 @@ function MessageLink({
}) { }) {
if (!href) return <span>{children}</span>; if (!href) return <span>{children}</span>;
// Human messages: render links as plain underlined text
if (isHuman) {
return (
<a
href={href}
target="_blank"
rel="noopener noreferrer"
className="text-primary underline underline-offset-2 hover:no-underline"
>
{children}
</a>
);
}
const citation = citationMap.get(href); const citation = citationMap.get(href);
// Check if it's an external link (http/https) // Only render as CitationLink badge if it's a citation (in citationMap)
const isExternalLink = href.startsWith("http://") || href.startsWith("https://"); // This ensures project URLs and regular links are not rendered as badges
if (citation && !isHuman) {
// AI messages: external links use CitationLink for consistent styling during streaming
if (isExternalLink) {
return ( return (
<CitationLink citation={citation} href={href}> <CitationLink citation={citation} href={href}>
{children} {children}
@@ -119,10 +103,12 @@ function MessageLink({
); );
} }
// Internal/anchor links use simple anchor tag // All other links (including project URLs) render as plain links
return ( return (
<a <a
href={href} href={href}
target="_blank"
rel="noopener noreferrer"
className="text-primary underline underline-offset-2 hover:no-underline" className="text-primary underline underline-offset-2 hover:no-underline"
> >
{children} {children}