From ef874dd347ffc57c42f519f6788c30f2543c5e1f Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sun, 19 Mar 2023 13:38:40 +0800 Subject: [PATCH] More caching for alpha-detecting avatars --- src/components/avatar.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/avatar.jsx b/src/components/avatar.jsx index a9c2d9c4..c2aed8ab 100644 --- a/src/components/avatar.jsx +++ b/src/components/avatar.jsx @@ -43,6 +43,7 @@ function Avatar({ url, size, alt = '', ...props }) { }} onLoad={(e) => { if (avatarRef.current) avatarRef.current.dataset.loaded = true; + if (alphaCache[url] !== undefined) return; try { // Check if image has alpha channel const canvas = document.createElement('canvas'); @@ -65,8 +66,8 @@ function Avatar({ url, size, alt = '', ...props }) { if (hasAlpha) { // console.log('hasAlpha', hasAlpha, allPixels.data); avatarRef.current.classList.add('has-alpha'); - alphaCache[url] = true; } + alphaCache[url] = hasAlpha; } catch (e) { // Ignore }