Skip to content

Commit 1ead8de

Browse files
authored
Merge pull request #602 from Stackla/fix/add-onerror-event-for-avatar
feat: Enhance avatar image loading with lazy loading and error handling
2 parents b43f9ef + 05ea6fe commit 1ead8de

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

widgets/libs/vertical-expanded-tiles/tile-content.template.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,21 @@ function UserInfoTemplate(props: UserInfoTemplateProps) {
108108
const tileAvatar = (
109109
<span class="avatar-wrapper">
110110
<a class="avatar-link" href={"javascript:void(0)"}>
111-
<img loading="lazy" src={avatar} />
111+
<img
112+
loading="lazy"
113+
src={avatar}
114+
style={{ display: "none" }}
115+
onLoad={e => {
116+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
117+
const currentTarget: HTMLImageElement | null = e.currentTarget as HTMLImageElement
118+
currentTarget.style.display = ""
119+
}}
120+
onError={e => {
121+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
122+
const currentTarget: HTMLImageElement | null = e.currentTarget as HTMLImageElement
123+
currentTarget.style.display = "none"
124+
}}
125+
/>
112126
</a>
113127
</span>
114128
)

0 commit comments

Comments
 (0)