Unverified Commit d6105c95 authored by Alex Castle's avatar Alex Castle Committed by GitHub

Add delay to placeholder removal (#25916)

* Add delay to placeholder removal

* Increase jest timeout for image tests

* Use check instead of immediately expecting the result
Co-authored-by: 's avatarTim Neutkens <timneutkens@me.com>
parent f443b694
...@@ -261,6 +261,8 @@ function defaultImageLoader(loaderProps: ImageLoaderProps) { ...@@ -261,6 +261,8 @@ 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, element: HTMLImageElement | null,
placeholder: PlaceholderValue placeholder: PlaceholderValue
...@@ -270,11 +272,15 @@ function removePlaceholder( ...@@ -270,11 +272,15 @@ function removePlaceholder(
// 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.
element.style.backgroundImage = 'none' setTimeout(() => {
element.style.backgroundImage = 'none'
}, 1500)
} else { } else {
element.onload = () => { element.onload = () => {
if (!element.src.startsWith('data:')) { if (!element.src.startsWith('data:')) {
element.style.backgroundImage = 'none' setTimeout(() => {
element.style.backgroundImage = 'none'
}, 1500)
} }
} }
} }
......
...@@ -16,7 +16,7 @@ import { ...@@ -16,7 +16,7 @@ import {
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { join } from 'path' import { join } from 'path'
jest.setTimeout(1000 * 60) jest.setTimeout(1000 * 80)
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
...@@ -607,14 +607,15 @@ describe('Image Component Tests', () => { ...@@ -607,14 +607,15 @@ describe('Image Component Tests', () => {
let browser let browser
try { try {
browser = await webdriver(appPort, '/blurry-placeholder') browser = await webdriver(appPort, '/blurry-placeholder')
await check(
expect( async () =>
await getComputedStyle( await getComputedStyle(
browser, browser,
'blurry-placeholder', 'blurry-placeholder',
'background-image' 'background-image'
) ),
).toBe('none') 'none'
)
expect( expect(
await getComputedStyle( await getComputedStyle(
browser, browser,
...@@ -627,13 +628,15 @@ describe('Image Component Tests', () => { ...@@ -627,13 +628,15 @@ describe('Image Component Tests', () => {
await browser.eval('document.getElementById("spacer").remove()') await browser.eval('document.getElementById("spacer").remove()')
expect( await check(
await getComputedStyle( async () =>
browser, await getComputedStyle(
'blurry-placeholder-with-lazy', browser,
'background-image' 'blurry-placeholder-with-lazy',
) 'background-image'
).toBe('none') ),
'none'
)
} finally { } finally {
if (browser) { if (browser) {
await browser.close() await browser.close()
......
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