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 Show error when user put wrong values in width or height #26166

Merged
merged 23 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
56fa669
Fix Show error when user put wrong values in width or height
jthcast Jun 16, 2021
3446c9b
Add test
jthcast Jun 16, 2021
45f75c5
Merge branch 'canary' into canary
jthcast Jun 17, 2021
b9e2b7d
Fix handle another case
jthcast Jun 17, 2021
ae6c75b
Merge branch 'canary' of https://github.com/jthcast/next.js into canary
jthcast Jun 17, 2021
9b4e17b
Merge branch 'canary' into canary
jthcast Jun 17, 2021
e9c55d6
Update test/integration/image-component/default/pages/invalid-weight-…
jthcast Jun 17, 2021
5189265
Update packages/next/client/image.tsx
jthcast Jun 17, 2021
3d85b69
Update test/integration/image-component/default/test/index.test.js
jthcast Jun 17, 2021
d344a0d
Fix rename weight to width
jthcast Jun 17, 2021
eba3c73
Merge branch 'canary' into canary
jthcast Jun 17, 2021
cb65f29
Merge branch 'canary' into canary
jthcast Jun 17, 2021
9fe959f
Fix type error
ijjk Jun 17, 2021
0ea1336
Merge branch 'canary' into canary
jthcast Jun 17, 2021
51f4ba8
Fix intrinsic need width and height value
jthcast Jun 17, 2021
9c84023
Merge branch 'canary' of https://github.com/jthcast/next.js into canary
jthcast Jun 17, 2021
6ce4b62
Merge branch 'canary' into canary
jthcast Jun 17, 2021
559e8da
Fix static image doesn't need width and height
jthcast Jun 17, 2021
3cad23c
Merge branch 'canary' of https://github.com/jthcast/next.js into canary
jthcast Jun 17, 2021
168597d
Merge branch 'canary' into canary
styfle Jun 17, 2021
0427b1d
Fix lint
jthcast Jun 17, 2021
eda2c84
Merge branch 'canary' of https://github.com/jthcast/next.js into canary
jthcast Jun 17, 2021
10f7060
Fix comparison
styfle Jun 17, 2021
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
10 changes: 9 additions & 1 deletion packages/next/client/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ export default function Image({
).join(',')}.`
)
}
if (
layout !== 'fill' &&
(isNaN(widthInt) || isNaN(heightInt))
) {
throw new Error(
`Image with src "${src}" has invalid "width" or "height" property. These should be numeric values.`
)
}
if (!VALID_LOADING_VALUES.includes(loading)) {
throw new Error(
`Image with src "${src}" has invalid "loading" property. Provided "${loading}" should be one of ${VALID_LOADING_VALUES.map(
Expand All @@ -373,7 +381,7 @@ export default function Image({
)
}
if (placeholder === 'blur') {
if ((widthInt || 0) * (heightInt || 0) < 1600) {
if (layout !== 'fill' && (widthInt || 0) * (heightInt || 0) < 1600) {
console.warn(
`Image with src "${src}" is smaller than 40x40. Consider removing the "placeholder='blur'" property to improve performance.`
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
jthcast marked this conversation as resolved.
Show resolved Hide resolved
import Image from 'next/image'

export default function Page() {
return (
<div>
<p>Invalid width or height</p>

<Image
src="/test.jpg"
width="fill"
height="fill"
layout="responsive"
placeholder="blur"
blurDataURL="/test.jpg"
/>
</div>
)
}
9 changes: 9 additions & 0 deletions test/integration/image-component/default/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,15 @@ function runTests(mode) {
)
})

it('should show error when not numeric string width or height', async () => {
const browser = await webdriver(appPort, '/invalid-weight-or-height')
jthcast marked this conversation as resolved.
Show resolved Hide resolved

expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(
`Image with src "/test.jpg" has invalid "width" or "height" property. These should be numeric values.`
)
})

it('should show error when static import and placeholder=blur and blurDataUrl is missing', async () => {
const browser = await webdriver(
appPort,
Expand Down