fix(avatars) refactor preloading

Use fetch(), which gives us better control over headers.
This commit is contained in:
Saúl Ibarra Corretgé 2020-10-14 21:58:28 +02:00
parent 65a9de346f
commit a3fb996ff0
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) => { return new Promise((resolve, reject) => {
const image = document.createElement('img'); fetch(src, { referrer: '' })
.then(response => {
image.onload = () => resolve(src); if (response.ok) {
image.onerror = reject; resolve(src);
image.src = src; } else {
reject();
}
})
.catch(e => {
reject(e);
});
}); });
} }