Skip to content

Commit 6eb6e30

Browse files
authored
Fix Firefox image decode error (#26011)
* Fix Firefox image decode error * Add next/image test to production suite * update page count test
1 parent 0a92063 commit 6eb6e30

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

packages/next/client/image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function removePlaceholder(
269269
const handleLoad = () => {
270270
if (!img.src.startsWith('data:')) {
271271
const p = 'decode' in img ? img.decode() : Promise.resolve()
272-
p.then(() => {
272+
p.catch(() => {}).then(() => {
273273
img.style.filter = 'none'
274274
img.style.backgroundSize = 'none'
275275
img.style.backgroundImage = 'none'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Image from 'next/image'
2+
import logo from '../public/vercel.png'
3+
4+
export default () => (
5+
<div>
6+
<p>Static Image</p>
7+
<Image src={logo} placeholder="blur" id="static-image" />
8+
</div>
9+
)
29.4 KB
Loading

test/integration/production/test/index.test.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ describe('Production Usage', () => {
6363
afterAll(() => stopApp(server))
6464

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

920+
it('should remove placeholder for next/image correctly', async () => {
921+
const browser = await webdriver(context.appPort, '/')
922+
923+
await browser.eval(`(function() {
924+
window.beforeNav = 1
925+
window.next.router.push('/static-image')
926+
})()`)
927+
await browser.waitForElementByCss('#static-image')
928+
929+
expect(await browser.eval('window.beforeNav')).toBe(1)
930+
931+
await check(
932+
() => browser.elementByCss('img').getComputedCss('background-image'),
933+
'none'
934+
)
935+
936+
await browser.eval(`(function() {
937+
window.beforeNav = 1
938+
window.next.router.push('/')
939+
})()`)
940+
await browser.waitForElementByCss('.index-page')
941+
await waitFor(1000)
942+
943+
await browser.eval(`(function() {
944+
window.beforeNav = 1
945+
window.next.router.push('/static-image')
946+
})()`)
947+
await browser.waitForElementByCss('#static-image')
948+
949+
expect(await browser.eval('window.beforeNav')).toBe(1)
950+
951+
await check(
952+
() =>
953+
browser
954+
.elementByCss('#static-image')
955+
.getComputedCss('background-image'),
956+
'none'
957+
)
958+
959+
for (let i = 0; i < 5; i++) {
960+
expect(
961+
await browser
962+
.elementByCss('#static-image')
963+
.getComputedCss('background-image')
964+
).toBe('none')
965+
await waitFor(500)
966+
}
967+
})
968+
920969
dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))
921970

922971
processEnv(context)

0 commit comments

Comments
 (0)