Merge pull request #7904 from saghul/preload-avatars-refer

fix(avatars) refactor preloading
This commit is contained in:
Aaron van Meerten 2020-10-14 15:22:17 -05:00 committed by GitHub
commit 5e6c4d67ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 5 deletions

View File

@ -15,10 +15,16 @@ export function preloadImage(src: string | Object): Promise<string> {
}
return new Promise((resolve, reject) => {
const image = document.createElement('img');
image.onload = () => resolve(src);
image.onerror = reject;
image.src = src;
fetch(src, { referrer: '' })
.then(response => {
if (response.ok) {
resolve(src);
} else {
reject();
}
})
.catch(e => {
reject(e);
});
});
}