Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Firefox image decode error #26011

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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