Skip to content

Commit

Permalink
Fix Firefox image decode error (#26011)
Browse files Browse the repository at this point in the history
* Fix Firefox image decode error

* Add next/image test to production suite

* update page count test
  • Loading branch information
ijjk committed Jun 11, 2021
1 parent 0a92063 commit 6eb6e30
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/client/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function removePlaceholder(
const handleLoad = () => {
if (!img.src.startsWith('data:')) {
const p = 'decode' in img ? img.decode() : Promise.resolve()
p.then(() => {
p.catch(() => {}).then(() => {
img.style.filter = 'none'
img.style.backgroundSize = 'none'
img.style.backgroundImage = 'none'
Expand Down
9 changes: 9 additions & 0 deletions test/integration/production/pages/static-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Image from 'next/image'
import logo from '../public/vercel.png'

export default () => (
<div>
<p>Static Image</p>
<Image src={logo} placeholder="blur" id="static-image" />
</div>
)
Binary file added test/integration/production/public/vercel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 51 additions & 2 deletions test/integration/production/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('Production Usage', () => {
afterAll(() => stopApp(server))

it('should contain generated page count in output', async () => {
expect(output).toContain('Generating static pages (0/37)')
expect(output).toContain('Generating static pages (37/37)')
expect(output).toContain('Generating static pages (0/38)')
expect(output).toContain('Generating static pages (38/38)')
// we should only have 4 segments and the initial message logged out
expect(output.match(/Generating static pages/g).length).toBe(5)
})
Expand Down Expand Up @@ -917,6 +917,55 @@ describe('Production Usage', () => {
expect(await browser.eval('window.location.pathname')).toBe('/non-existent')
})

it('should remove placeholder for next/image correctly', async () => {
const browser = await webdriver(context.appPort, '/')

await browser.eval(`(function() {
window.beforeNav = 1
window.next.router.push('/static-image')
})()`)
await browser.waitForElementByCss('#static-image')

expect(await browser.eval('window.beforeNav')).toBe(1)

await check(
() => browser.elementByCss('img').getComputedCss('background-image'),
'none'
)

await browser.eval(`(function() {
window.beforeNav = 1
window.next.router.push('/')
})()`)
await browser.waitForElementByCss('.index-page')
await waitFor(1000)

await browser.eval(`(function() {
window.beforeNav = 1
window.next.router.push('/static-image')
})()`)
await browser.waitForElementByCss('#static-image')

expect(await browser.eval('window.beforeNav')).toBe(1)

await check(
() =>
browser
.elementByCss('#static-image')
.getComputedCss('background-image'),
'none'
)

for (let i = 0; i < 5; i++) {
expect(
await browser
.elementByCss('#static-image')
.getComputedCss('background-image')
).toBe('none')
await waitFor(500)
}
})

dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))

processEnv(context)
Expand Down

0 comments on commit 6eb6e30

Please sign in to comment.