Skip to content

Commit 93f19c4

Browse files
committed
fix: handle image loading errors in FeedIcon component
1 parent 5d53148 commit 93f19c4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

apps/mobile/src/components/ui/icon/feed-icon.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { FeedViewType } from "@follow/constants"
22
import type { ReactNode } from "react"
3-
import { useMemo } from "react"
3+
import { useCallback, useMemo, useState } from "react"
44

55
import type { FeedSchema } from "@/src/database/schemas/types"
66
import { getFeedIconSource } from "@/src/lib/image"
77

88
import type { ImageProps } from "../image/Image"
99
import { Image } from "../image/Image"
10+
import { FallbackIcon } from "./fallback-icon"
1011

1112
export type FeedIconRequiredFeed = Pick<
1213
FeedSchema,
@@ -39,12 +40,15 @@ export function FeedIcon({
3940
siteUrl,
4041
...props
4142
}: FeedIconProps & ImageProps) {
43+
const [isError, setIsError] = useState(false)
4244
const src = useMemo(() => {
4345
return getFeedIconSource(feed, siteUrl, fallback)
4446
}, [fallback, feed, siteUrl])
4547

46-
if (!src) {
47-
return null
48+
const handleError = useCallback(() => setIsError(true), [])
49+
50+
if (!src || isError) {
51+
return <FallbackIcon title={feed?.title ?? ""} size={size} />
4852
}
4953
return (
5054
<Image
@@ -55,6 +59,7 @@ export function FeedIcon({
5559
className="rounded"
5660
style={{ height: size, width: size }}
5761
source={{ uri: src }}
62+
onError={handleError}
5863
{...props}
5964
/>
6065
)

0 commit comments

Comments
 (0)