Skip to content

Commit b1f907c

Browse files
committed
Add image onerror handling for avatars
1 parent 1edd5d1 commit b1f907c

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/common/imageOnError.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @param e
3+
* @param className string[]
4+
*/
5+
export default function imageOnError(e, className = []) {
6+
e.target.onError = null;
7+
e.target.classList.add('text-transparent', ...className);
8+
}

src/entries/contentScript/components/ReactionsHistoryNotice.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { hasSubscriptionFeature } from '~/entries/contentScript/hooks/useSubscri
1212
import { subscriptionIds, subscriptionFeatures } from '~/enums';
1313
import PremiumCtaLabel from '~/entries/contentScript/components/PremiumCtaLabel';
1414
import { buildReactionFromUrl } from '~/common/pretty';
15+
import imageOnError from '~/common/imageOnError';
1516

1617
function ReactionPreview({ reaction }) {
1718
const { t } = useTranslation();
@@ -34,6 +35,7 @@ function ReactionPreview({ reaction }) {
3435
<img
3536
src={reaction.from_info.avatar_url}
3637
className="inline size-7 overflow-hidden rounded-full"
38+
onError={(e) => imageOnError(e, ['bg-primary-gradient-hc-from/40'])}
3739
alt={reaction.from_info.name}
3840
/>
3941
</a>

0 commit comments

Comments
 (0)