Skip to content

Commit 738a964

Browse files
authored
Fix style reset on image with placeholder=blur (vercel#32680)
This PR is a follow up to PR vercel#32623 to fix the remaining blur styles. These are unlikely to be overridden by the user but this PR is necessary to make `placeholder=empty` (default behavior) and `placeholder=blur` end up with the same inline styles on the loaded image. Related to vercel#18398 (comment)
1 parent 725f6b4 commit 738a964

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

packages/next/client/image.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ function handleLoading(
266266
p.catch(() => {}).then(() => {
267267
if (placeholder === 'blur') {
268268
img.style.filter = ''
269-
img.style.backgroundSize = 'none'
270-
img.style.backgroundImage = 'none'
269+
img.style.backgroundSize = ''
270+
img.style.backgroundImage = ''
271+
img.style.backgroundPosition = ''
271272
}
272273
loadedImageURLs.add(src)
273274
if (onLoadingComplete) {

test/integration/image-component/default/pages/style-filter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const Page = () => {
99
<h1>Image Style Filter</h1>
1010

1111
<Image
12-
className={style.opacity50}
12+
className={style.overrideImg}
1313
id="img-plain"
1414
src="/test.jpg"
1515
width={400}
1616
height={400}
1717
/>
1818

1919
<Image
20-
className={style.opacity50}
20+
className={style.overrideImg}
2121
id="img-blur"
2222
placeholder="blur"
2323
src={img}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
border-radius: 139px;
1111
}
1212

13-
.opacity50 {
13+
.overrideImg {
1414
filter: opacity(0.5);
15+
background-size: 30%;
16+
background-image: url('data:image/png;base64,iVBORw0KGgo=');
17+
background-position: 1px 2px;
1518
}

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,31 @@ function runTests(mode) {
834834
await check(() => getSrc(browser, 'img-blur'), /^\/_next\/image/)
835835
await waitFor(1000)
836836

837-
const plain = await getComputedStyle(browser, 'img-plain', 'filter')
838-
expect(plain).toBe('opacity(0.5)')
837+
expect(await getComputedStyle(browser, 'img-plain', 'filter')).toBe(
838+
'opacity(0.5)'
839+
)
840+
expect(
841+
await getComputedStyle(browser, 'img-plain', 'background-size')
842+
).toBe('30%')
843+
expect(
844+
await getComputedStyle(browser, 'img-plain', 'background-image')
845+
).toMatch('iVBORw0KGgo=')
846+
expect(
847+
await getComputedStyle(browser, 'img-plain', 'background-position')
848+
).toBe('1px 2px')
839849

840-
const blur = await getComputedStyle(browser, 'img-blur', 'filter')
841-
expect(blur).toBe('opacity(0.5)')
850+
expect(await getComputedStyle(browser, 'img-blur', 'filter')).toBe(
851+
'opacity(0.5)'
852+
)
853+
expect(await getComputedStyle(browser, 'img-blur', 'background-size')).toBe(
854+
'30%'
855+
)
856+
expect(
857+
await getComputedStyle(browser, 'img-blur', 'background-image')
858+
).toMatch('iVBORw0KGgo=')
859+
expect(
860+
await getComputedStyle(browser, 'img-blur', 'background-position')
861+
).toBe('1px 2px')
842862
})
843863

844864
// Tests that use the `unsized` attribute:

0 commit comments

Comments
 (0)