From abe336811550a32d838a179007bb8d1c22cffbf6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 12 Nov 2025 14:34:46 -0600 Subject: [PATCH] Add error handling to favicon URL --- src/components/ExternalFavicon.tsx | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/components/ExternalFavicon.tsx b/src/components/ExternalFavicon.tsx index 1175d709..1538d2df 100644 --- a/src/components/ExternalFavicon.tsx +++ b/src/components/ExternalFavicon.tsx @@ -1,6 +1,7 @@ import { useAppContext } from '@/hooks/useAppContext'; import { faviconUrl, normalizeUrl } from '@/lib/faviconUrl'; -import { ReactNode } from 'react'; +import { cn } from '@/lib/utils'; +import { ReactNode, useMemo } from 'react'; interface ExternalFaviconProps { /** The URL to fetch the favicon for */ @@ -25,14 +26,28 @@ export function ExternalFavicon({ }: ExternalFaviconProps) { const { config } = useAppContext(); - // Normalize the URL to ensure it has a protocol - const normalizedUrl = normalizeUrl(url); - // Generate the favicon URL using the configured template - const faviconSrc = faviconUrl(config.faviconUrl, normalizedUrl); + const faviconSrc = useMemo(() => { + try { + // Normalize the URL to ensure it has a protocol + const normalizedUrl = normalizeUrl(url); + return faviconUrl(config.faviconUrl, normalizedUrl); + } catch { + return; + } + }, [url, config.faviconUrl]); + + // If faviconSrc is not available, render the fallback directly + if (!faviconSrc) { + return ( + + {fallback} + + ) + } return ( - +