Skip to content

Commit

Permalink
fix: Gravatar over-fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Nov 23, 2023
1 parent 6e51b92 commit 3d51002
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions frontend/src/lib/lemon-ui/ProfilePicture/ProfilePicture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ export function ProfilePicture({
if (emailOrNameWithEmail) {
const emailHash = md5(emailOrNameWithEmail.trim().toLowerCase())
const tentativeUrl = `https://www.gravatar.com/avatar/${emailHash}?s=96&d=404`
// The image will be cached, so it's best to do GET request check before trying to render it
void fetch(tentativeUrl).then((response) => {
if (response.status === 200) {
setGravatarUrl(tentativeUrl)
}
})
setGravatarUrl(tentativeUrl)
}
}, [email])

Expand All @@ -64,6 +59,7 @@ export function ProfilePicture({
src={gravatarUrl}
title={title || `This is the Gravatar for ${combinedNameAndEmail}`}
alt=""
onError={() => setGravatarUrl(null)}
/>
)
} else {
Expand Down

0 comments on commit 3d51002

Please sign in to comment.