Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: Improved fallback solution for avatar image loading failure (#1172)

leo562a571281de
diff --git a/web/app/components/base/avatar/index.tsx b/web/app/components/base/avatar/index.tsx
index e6ebf308bdf..c3410d0bc80 100644
--- a/web/app/components/base/avatar/index.tsx
+++ b/web/app/components/base/avatar/index.tsx
@@ -1,5 +1,6 @@
'use client'
import cn from 'classnames'
+import { useState } from 'react'
type AvatarProps = {
name: string
@@ -17,14 +18,20 @@ const Avatar = ({
}: AvatarProps) => {
const avatarClassName = 'shrink-0 flex items-center rounded-full bg-primary-600'
const style = { width: `${size}px`, height: `${size}px`, fontSize: `${size}px`, lineHeight: `${size}px` }
+ const [imgError, setImgError] = useState(false)
- if (avatar) {
+ const handleError = () => {
+ setImgError(true)
+ }
+
+ if (avatar && !imgError) {
return (
<img
className={cn(avatarClassName, className)}
style={style}
alt={name}
src={avatar}
+ onError={handleError}
/>
)
}