Skip to content

Commit 079c4be

Browse files
authored
Fix style.filter on image with placeholder=blur (vercel#32623)
Fixes vercel#18398 (comment)
1 parent f244593 commit 079c4be

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

packages/next/client/image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function handleLoading(
265265
const p = 'decode' in img ? img.decode() : Promise.resolve()
266266
p.catch(() => {}).then(() => {
267267
if (placeholder === 'blur') {
268-
img.style.filter = 'none'
268+
img.style.filter = ''
269269
img.style.backgroundSize = 'none'
270270
img.style.backgroundImage = 'none'
271271
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react'
2+
import Image from 'next/image'
3+
import style from '../style.module.css'
4+
import img from '../public/test.jpg'
5+
6+
const Page = () => {
7+
return (
8+
<div>
9+
<h1>Image Style Filter</h1>
10+
11+
<Image
12+
className={style.opacity50}
13+
id="img-plain"
14+
src="/test.jpg"
15+
width={400}
16+
height={400}
17+
/>
18+
19+
<Image
20+
className={style.opacity50}
21+
id="img-blur"
22+
placeholder="blur"
23+
src={img}
24+
/>
25+
26+
<footer>Footer</footer>
27+
</div>
28+
)
29+
}
30+
31+
export default Page

test/integration/image-component/default/style.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
.mainContainer img {
1010
border-radius: 139px;
1111
}
12+
13+
.opacity50 {
14+
filter: opacity(0.5);
15+
}

test/integration/image-component/default/test/index.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,19 @@ function runTests(mode) {
828828
}
829829
})
830830

831+
it('should apply filter style after image loads', async () => {
832+
const browser = await webdriver(appPort, '/style-filter')
833+
await check(() => getSrc(browser, 'img-plain'), /^\/_next\/image/)
834+
await check(() => getSrc(browser, 'img-blur'), /^\/_next\/image/)
835+
await waitFor(1000)
836+
837+
const plain = await getComputedStyle(browser, 'img-plain', 'filter')
838+
expect(plain).toBe('opacity(0.5)')
839+
840+
const blur = await getComputedStyle(browser, 'img-blur', 'filter')
841+
expect(blur).toBe('opacity(0.5)')
842+
})
843+
831844
// Tests that use the `unsized` attribute:
832845
if (mode !== 'dev') {
833846
it('should correctly rotate image', async () => {

0 commit comments

Comments
 (0)