diff --git a/commafeed-client/src/components/content/FeedFavicon.tsx b/commafeed-client/src/components/content/FeedFavicon.tsx index cbf10464..b84c0546 100644 --- a/commafeed-client/src/components/content/FeedFavicon.tsx +++ b/commafeed-client/src/components/content/FeedFavicon.tsx @@ -10,11 +10,18 @@ export interface FeedFaviconProps { export function FeedFavicon({ url, size = 18 }: Readonly) { // the backend always returns a favicon except when the feed has never been fetched // this can happen when the user subscribes to a feed, the feed is added to the tree but the feed has not been fetched yet - // in this case we just retry every second until the feed is fetched and the favicon is available + // in this case we retry every second up to 3 times until the feed is fetched and the favicon is available const [timestamp, setTimestamp] = useState(0) + const [retryCount, setRetryCount] = useState(0) const { start: retry } = useTimeout(() => setTimestamp(Date.now()), 1000) const urlWithTimestamp = url + (timestamp === 0 ? "" : `?t=${timestamp}`) + const handleError = () => { + if (retryCount < 3) { + setRetryCount(c => c + 1) + retry() + } + } return ( ) { placeholderHeight={size} placeholderBackgroundColor="inherit" placeholderIconSize={size} - onError={retry} + onError={handleError} /> ) } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java b/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java index 73306b00..b28a1fa6 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java @@ -30,9 +30,10 @@ public class RootFaviconFetcher implements FaviconFetcher { url = feed.getUrl(); } - URI uri = URI.create(url); - String faviconUrl = "%s://%s/favicon.ico".formatted(uri.getScheme(), uri.getHost()); try { + URI uri = URI.create(url.trim()); + String faviconUrl = "%s://%s/favicon.ico".formatted(uri.getScheme(), uri.getHost()); + log.debug("getting root icon at {}", faviconUrl); HttpResult result = getter.get(faviconUrl); return new Favicon(result.content(), result.contentType());