Skip to content

Commit

Permalink
Fix next/future/image incorrectly warning for fill + blur (#39986)
Browse files Browse the repository at this point in the history
This warning was incorrectly printed when `fill` and `placeholder="blur"` were used together:

> Image with src "/test.jpg" is smaller than 40x40. Consider removing the "placeholder='blur'" property to improve performance.
  • Loading branch information
styfle committed Aug 26, 2022
1 parent c6dafda commit 6a65dc5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/client/future/image.tsx
Expand Up @@ -697,7 +697,7 @@ export default function Image({
}

if (placeholder === 'blur') {
if ((widthInt || 0) * (heightInt || 0) < 1600) {
if (widthInt && heightInt && widthInt * heightInt < 1600) {
warnOnce(
`Image with src "${src}" is smaller than 40x40. Consider removing the "placeholder='blur'" property to improve performance.`
)
Expand Down
19 changes: 19 additions & 0 deletions test/integration/image-future/default/pages/fill.js
@@ -1,6 +1,8 @@
import React from 'react'
import Image from 'next/future/image'

import test from '../public/test.jpg'

const Page = () => {
return (
<div>
Expand All @@ -16,6 +18,23 @@ const Page = () => {
>
<Image id="fill-image-1" src="/wide.png" sizes="300px" fill />
</div>
<div
id="image-container-blur"
style={{
height: '300px',
width: '300px',
position: 'relative',
overflow: 'hidden',
}}
>
<Image
id="fill-image-blur"
src={test}
sizes="300px"
placeholder="blur"
fill
/>
</div>
</div>
)
}
Expand Down
3 changes: 3 additions & 0 deletions test/integration/image-future/default/test/index.test.ts
Expand Up @@ -1032,6 +1032,9 @@ function runTests(mode) {
.map((log) => log.message)
.join('\n')
expect(warnings).not.toMatch(/Image with src (.*) has "fill"/gm)
expect(warnings).not.toMatch(
/Image with src (.*) is smaller than 40x40. Consider removing(.*)/gm
)
})
it('should log warnings when using fill mode incorrectly', async () => {
browser = await webdriver(appPort, '/fill-warnings')
Expand Down

0 comments on commit 6a65dc5

Please sign in to comment.