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 next/future/image incorrectly warning for fill + blur #39986

Merged
merged 3 commits into from Aug 26, 2022
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/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