mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 14:16:39 +01:00
Don't do anything to "missing" avatars
This commit is contained in:
parent
ed1d475a12
commit
e1a0c4d2db
1 changed files with 7 additions and 1 deletions
|
@ -16,6 +16,7 @@ const alphaCache = {};
|
|||
function Avatar({ url, size, alt = '', ...props }) {
|
||||
size = SIZES[size] || size || SIZES.m;
|
||||
const avatarRef = useRef();
|
||||
const isMissing = /missing\.png$/.test(url);
|
||||
return (
|
||||
<span
|
||||
ref={avatarRef}
|
||||
|
@ -34,7 +35,11 @@ function Avatar({ url, size, alt = '', ...props }) {
|
|||
height={size}
|
||||
alt={alt}
|
||||
loading="lazy"
|
||||
crossOrigin={alphaCache[url] === undefined ? 'anonymous' : undefined}
|
||||
crossOrigin={
|
||||
alphaCache[url] === undefined && !isMissing
|
||||
? 'anonymous'
|
||||
: undefined
|
||||
}
|
||||
onError={(e) => {
|
||||
if (e.target.crossOrigin) {
|
||||
e.target.crossOrigin = null;
|
||||
|
@ -44,6 +49,7 @@ function Avatar({ url, size, alt = '', ...props }) {
|
|||
onLoad={(e) => {
|
||||
if (avatarRef.current) avatarRef.current.dataset.loaded = true;
|
||||
if (alphaCache[url] !== undefined) return;
|
||||
if (isMissing) return;
|
||||
try {
|
||||
// Check if image has alpha channel
|
||||
const canvas = document.createElement('canvas');
|
||||
|
|
Loading…
Reference in a new issue