Skip to content

Commit 8f5f89e

Browse files
committed
Rename iconSizes to imageSizes
1 parent a9984e4 commit 8f5f89e

File tree

9 files changed

+28
-29
lines changed

9 files changed

+28
-29
lines changed

docs/basic-features/image-optimization.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ module.exports = {
6262
}
6363
```
6464

65-
### Icon Sizes
65+
### Image Sizes
6666

67-
You can specify a list of icon image widths using the `iconSizes` property. These widths should be smaller than the smallest value in `deviceSizes`. The purpose is for images that don't scale with the browser window, such as icons or badges. If `iconSizes` is not defined, then `deviceSizes` will be used.
67+
You can specify a list of exact image widths using the `imageSizes` property. These widths should be different than the widths defined in `deviceSizes`. The purpose is for images that don't scale with the browser window, such as icons, badges, or profile images. If the `width` property of a [`next/image`](/docs/api-reference/next/image.md) component matches a value in `imageSizes`, the image will be rendered at that exact width.
6868

6969
```js
7070
module.exports = {
7171
images: {
72-
iconSizes: [16, 32, 64],
72+
imageSizes: [16, 32, 64],
7373
},
7474
}
7575
```

packages/next/build/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ export default async function build(
11111111
}
11121112

11131113
const images = { ...config.images }
1114-
const { deviceSizes, iconSizes } = images
1115-
images.sizes = [...deviceSizes, ...iconSizes]
1114+
const { deviceSizes, imageSizes } = images
1115+
images.sizes = [...deviceSizes, ...imageSizes]
11161116

11171117
await promises.writeFile(
11181118
path.join(distDir, IMAGES_MANIFEST),

packages/next/build/webpack-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ export default async function getBaseWebpackConfig(
992992
),
993993
'process.env.__NEXT_IMAGE_OPTS': JSON.stringify({
994994
deviceSizes: config.images.deviceSizes,
995-
iconSizes: config.images.iconSizes,
995+
imageSizes: config.images.imageSizes,
996996
path: config.images.path,
997997
loader: config.images.loader,
998998
...(dev

packages/next/client/image.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type LoaderKey = 'imgix' | 'cloudinary' | 'akamai' | 'default'
1515

1616
type ImageData = {
1717
deviceSizes: number[]
18-
iconSizes: number[]
18+
imageSizes: number[]
1919
loader: LoaderKey
2020
path: string
2121
domains?: string[]
@@ -38,14 +38,14 @@ type ImageProps = Omit<
3838
const imageData: ImageData = process.env.__NEXT_IMAGE_OPTS as any
3939
const {
4040
deviceSizes: configDeviceSizes,
41-
iconSizes: configIconSizes,
41+
imageSizes: configImageSizes,
4242
loader: configLoader,
4343
path: configPath,
4444
domains: configDomains,
4545
} = imageData
4646
// sort smallest to largest
4747
configDeviceSizes.sort((a, b) => a - b)
48-
configIconSizes.sort((a, b) => a - b)
48+
configImageSizes.sort((a, b) => a - b)
4949

5050
let cachedObserver: IntersectionObserver
5151
const IntersectionObserver =
@@ -87,8 +87,7 @@ function getDeviceSizes(width: number | undefined): number[] {
8787
if (typeof width !== 'number') {
8888
return configDeviceSizes
8989
}
90-
const smallest = configDeviceSizes[0]
91-
if (width < smallest && configIconSizes.includes(width)) {
90+
if (configImageSizes.includes(width)) {
9291
return [width]
9392
}
9493
const widths: number[] = []

packages/next/next-server/server/config.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const defaultConfig: { [key: string]: any } = {
2626
analyticsId: process.env.VERCEL_ANALYTICS_ID || '',
2727
images: {
2828
deviceSizes: [320, 420, 768, 1024, 1200],
29-
iconSizes: [],
29+
imageSizes: [],
3030
domains: [],
3131
path: '/_next/image',
3232
loader: 'default',
@@ -280,27 +280,27 @@ function assignDefaults(userConfig: { [key: string]: any }) {
280280
)
281281
}
282282
}
283-
if (images.iconSizes) {
284-
const { iconSizes } = images
285-
if (!Array.isArray(iconSizes)) {
283+
if (images.imageSizes) {
284+
const { imageSizes } = images
285+
if (!Array.isArray(imageSizes)) {
286286
throw new Error(
287-
`Specified images.iconSizes should be an Array received ${typeof iconSizes}`
287+
`Specified images.imageSizes should be an Array received ${typeof imageSizes}`
288288
)
289289
}
290290

291-
if (iconSizes.length > 25) {
291+
if (imageSizes.length > 25) {
292292
throw new Error(
293-
`Specified images.iconSizes exceeds length of 25, received length (${iconSizes.length}), please reduce the length of the array to continue`
293+
`Specified images.imageSizes exceeds length of 25, received length (${imageSizes.length}), please reduce the length of the array to continue`
294294
)
295295
}
296296

297-
const invalid = iconSizes.filter((d: unknown) => {
297+
const invalid = imageSizes.filter((d: unknown) => {
298298
return typeof d !== 'number' || d < 1 || d > 10000
299299
})
300300

301301
if (invalid.length > 0) {
302302
throw new Error(
303-
`Specified images.iconSizes should be an Array of numbers that are between 1 and 10000, received invalid values (${invalid.join(
303+
`Specified images.imageSizes should be an Array of numbers that are between 1 and 10000, received invalid values (${invalid.join(
304304
', '
305305
)})`
306306
)

packages/next/next-server/server/image-optimizer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const VECTOR_TYPES = [SVG]
2525

2626
type ImageData = {
2727
deviceSizes: number[]
28-
iconSizes: number[]
28+
imageSizes: number[]
2929
loader: string
3030
path: string
3131
domains?: string[]
@@ -39,8 +39,8 @@ export async function imageOptimizer(
3939
) {
4040
const { nextConfig, distDir } = server
4141
const imageData: ImageData = nextConfig.images
42-
const { deviceSizes = [], iconSizes = [], domains = [], loader } = imageData
43-
const sizes = [...deviceSizes, ...iconSizes]
42+
const { deviceSizes = [], imageSizes = [], domains = [], loader } = imageData
43+
const sizes = [...deviceSizes, ...imageSizes]
4444

4545
if (loader !== 'default') {
4646
await server.render404(req, res, parsedUrl)

test/integration/image-component/basic/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
images: {
33
deviceSizes: [480, 1024, 1600, 2000],
4-
iconSizes: [16, 64],
4+
imageSizes: [16, 64],
55
path: 'https://example.com/myaccount/',
66
loader: 'imgix',
77
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function runTests() {
5151
await browser.elementById('preceding-slash-image').getAttribute('srcset')
5252
).toBe('https://example.com/myaccount/fooslash.jpg?auto=format&w=480 480w')
5353
})
54-
it('should use iconSizes when width matches, not deviceSizes from next.config.js', async () => {
54+
it('should use imageSizes when width matches, not deviceSizes from next.config.js', async () => {
5555
expect(await browser.elementById('icon-image-16').getAttribute('src')).toBe(
5656
'https://example.com/myaccount/icon.png?auto=format&w=16'
5757
)

test/integration/image-optimizer/test/index.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,12 @@ describe('Image Optimizer', () => {
398398
)
399399
})
400400

401-
it('should error when iconSizes contains invalid widths', async () => {
401+
it('should error when imageSizes contains invalid widths', async () => {
402402
await nextConfig.replace(
403403
'{ /* replaceme */ }',
404404
JSON.stringify({
405405
images: {
406-
iconSizes: [0, 16, 64, 12000],
406+
imageSizes: [0, 16, 64, 12000],
407407
},
408408
})
409409
)
@@ -419,7 +419,7 @@ describe('Image Optimizer', () => {
419419
await nextConfig.restore()
420420

421421
expect(stderr).toContain(
422-
'Specified images.iconSizes should be an Array of numbers that are between 1 and 10000, received invalid values (0, 12000)'
422+
'Specified images.imageSizes should be an Array of numbers that are between 1 and 10000, received invalid values (0, 12000)'
423423
)
424424
})
425425
})
@@ -447,7 +447,7 @@ describe('Image Optimizer', () => {
447447
const json = JSON.stringify({
448448
images: {
449449
deviceSizes: [largeSize],
450-
iconSizes: [size],
450+
imageSizes: [size],
451451
domains,
452452
},
453453
})

0 commit comments

Comments
 (0)