Unverified Commit dca59bb3 authored by Steven's avatar Steven Committed by GitHub

Fix delay between blur image and high res image (#25994)

Previously, we had an arbitrary delay of 1500ms but instead we can wait until decoding is complete.
Co-authored-by: 's avatarKristóf Poduszló <kripod@protonmail.com>
parent d8b59f3e
...@@ -261,32 +261,28 @@ function defaultImageLoader(loaderProps: ImageLoaderProps) { ...@@ -261,32 +261,28 @@ function defaultImageLoader(loaderProps: ImageLoaderProps) {
// See https://stackoverflow.com/q/39777833/266535 for why we use this ref // See https://stackoverflow.com/q/39777833/266535 for why we use this ref
// handler instead of the img's onLoad attribute. // handler instead of the img's onLoad attribute.
// 1500ms delay in removing placeholder is to prevent flash of white between
// image load and image render.
function removePlaceholder( function removePlaceholder(
element: HTMLImageElement | null, img: HTMLImageElement | null,
placeholder: PlaceholderValue placeholder: PlaceholderValue
) { ) {
if (placeholder === 'blur' && element) { if (placeholder === 'blur' && img) {
if (element.complete && !element.src.startsWith('data:')) { const handleLoad = () => {
if (!img.src.startsWith('data:')) {
const p = 'decode' in img ? img.decode() : Promise.resolve()
p.then(() => {
img.style.filter = 'none'
img.style.backgroundSize = 'none'
img.style.backgroundImage = 'none'
})
}
}
if (img.complete) {
// If the real image fails to load, this will still remove the placeholder. // If the real image fails to load, this will still remove the placeholder.
// This is the desired behavior for now, and will be revisited when error // This is the desired behavior for now, and will be revisited when error
// handling is worked on for the image component itself. // handling is worked on for the image component itself.
setTimeout(() => { handleLoad()
element.style.filter = 'none'
element.style.backgroundSize = 'none'
element.style.backgroundImage = 'none'
}, 1500)
} else { } else {
element.onload = () => { img.onload = handleLoad
if (!element.src.startsWith('data:')) {
setTimeout(() => {
element.style.filter = 'none'
element.style.backgroundSize = 'none'
element.style.backgroundImage = 'none'
}, 1500)
}
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment