Ignore stale downloads

If src or sizePx changes while we're downloading,
discard the now-stale fetch result so we don't
override the fresh one.
This commit is contained in:
JephDiel
2026-03-12 22:20:19 -05:00
parent 8ecb1b3dbf
commit b198721969

View File

@@ -110,16 +110,24 @@ export const Avatar: FC<Props> = ({
}
let objectUrl: string | undefined;
let stale = false;
blob
.then((blob) => {
if (stale) {
return;
}
objectUrl = URL.createObjectURL(blob);
setAvatarUrl(objectUrl);
})
.catch((ex) => {
if (stale) {
return;
}
setAvatarUrl(undefined);
});
return (): void => {
stale = true;
if (objectUrl) {
URL.revokeObjectURL(objectUrl);
}