mirror of
https://github.com/vector-im/element-call.git
synced 2026-03-28 06:50:26 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user