diff --git a/packages/elements/__tests__/inline-citation.test.tsx b/packages/elements/__tests__/inline-citation.test.tsx index 601d47ae..3ff59966 100644 --- a/packages/elements/__tests__/inline-citation.test.tsx +++ b/packages/elements/__tests__/inline-citation.test.tsx @@ -92,6 +92,39 @@ describe("inlineCitationCardTrigger", () => { ); expect(screen.getByText("unknown")).toBeInTheDocument(); }); + + it("renders raw source for a bare domain without a scheme", () => { + expect(() => + render( + + + + ) + ).not.toThrow(); + expect(screen.getByText("example.com/nlp")).toBeInTheDocument(); + }); + + it("renders raw source for a relative path", () => { + expect(() => + render( + + + + ) + ).not.toThrow(); + expect(screen.getByText("/nlp-advances")).toBeInTheDocument(); + }); + + it("renders raw source for a non-URL string", () => { + expect(() => + render( + + + + ) + ).not.toThrow(); + expect(screen.getByText("not a url")).toBeInTheDocument(); + }); }); describe("inlineCitationCardBody", () => { diff --git a/packages/elements/src/inline-citation.tsx b/packages/elements/src/inline-citation.tsx index 171c81cf..3789ac15 100644 --- a/packages/elements/src/inline-citation.tsx +++ b/packages/elements/src/inline-citation.tsx @@ -1,7 +1,9 @@ "use client"; -import { Badge } from "@repo/shadcn-ui/components/ui/badge"; import type { CarouselApi } from "@repo/shadcn-ui/components/ui/carousel"; +import type { ComponentProps } from "react"; + +import { Badge } from "@repo/shadcn-ui/components/ui/badge"; import { Carousel, CarouselContent, @@ -14,7 +16,6 @@ import { } from "@repo/shadcn-ui/components/ui/hover-card"; import { cn } from "@repo/shadcn-ui/lib/utils"; import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react"; -import type { ComponentProps } from "react"; import { createContext, useCallback, @@ -70,7 +71,7 @@ export const InlineCitationCardTrigger = ({ > {sources[0] ? ( <> - {new URL(sources[0]).hostname}{" "} + {URL.canParse(sources[0]) ? new URL(sources[0]).hostname : sources[0]}{" "} {sources.length > 1 && `+${sources.length - 1}`} ) : (