diff --git a/ts/components/StoryLinkPreview.tsx b/ts/components/StoryLinkPreview.tsx index 35a6184640..6a4a7b1f05 100644 --- a/ts/components/StoryLinkPreview.tsx +++ b/ts/components/StoryLinkPreview.tsx @@ -9,7 +9,7 @@ import type { LinkPreviewType } from '../types/message/LinkPreviews'; import type { LocalizerType } from '../types/Util'; import { CurveType, Image } from './conversation/Image'; import { isImageAttachment } from '../types/Attachment'; -import { getDomain } from '../types/LinkPreview'; +import { getSafeDomain } from '../types/LinkPreview'; export type Props = LinkPreviewType & { forceCompactMode?: boolean; @@ -26,7 +26,7 @@ export function StoryLinkPreview({ url, }: Props): JSX.Element { const isImage = isImageAttachment(image); - const location = domain || getDomain(String(url)); + const location = domain || getSafeDomain(String(url)); const isCompact = forceCompactMode || !image; let content: JSX.Element | undefined; @@ -74,7 +74,7 @@ export function StoryLinkPreview({
{i18n('icu:stagedPreviewThumbnail',( )} { ); } +export function getSafeDomain(href: string): string | undefined { + try { + return getDomain(href); + } catch { + return undefined; + } +} + export function getDomain(href: string): string { const url = maybeParseUrl(href); if (!url || !url.hostname) {