Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
0bfa3ec1
Unverified
Commit
0bfa3ec1
authored
Sep 20, 2024
by
Steven
Committed by
GitHub
Sep 20, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(next/image): add support for `decoding` prop (#70298)
- Fixes
https://github.com/vercel/next.js/pull/49772
parent
e3688fbd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
3 deletions
+38
-3
image.mdx
docs/02-app/02-api-reference/01-components/image.mdx
+13
-2
get-img-props.ts
packages/next/src/shared/lib/get-img-props.ts
+2
-1
next-image-get-img-props.test.ts
test/unit/next-image-get-img-props.test.ts
+23
-0
No files found.
docs/02-app/02-api-reference/01-components/image.mdx
View file @
0bfa3ec1
...
@@ -467,13 +467,24 @@ For example, when upgrading an existing website from `<img>` to `<Image>`, you m
...
@@ -467,13 +467,24 @@ For example, when upgrading an existing website from `<img>` to `<Image>`, you m
/>
/>
```
```
### decoding
A hint to the browser indicating if it should wait for the image to be decoded before presenting other content updates or not. Defaults to `async`.
Possible values are the following:
- `async` - Asynchronously decode the image and allow other content to be rendered before it completes.
- `sync` - Synchronously decode the image for atomic presentation with other content.
- `auto` - No preference for the decoding mode; the browser decides what's best.
Learn more about the [`decoding` attribute](https://developer.mozilla.org/docs/Web/HTML/Element/img#loading).
### Other Props
### Other Props
Other properties on the `<Image />` component will be passed to the underlying
Other properties on the `<Image />` component will be passed to the underlying
`img` element with the exception of the following:
`img` element with the exception of the following:
- `srcSet`. Use [Device Sizes](#devicesizes) instead.
- `srcSet`. Use [Device Sizes](#devicesizes) instead.
- `decoding`. It is always `"async"`.
## Configuration Options
## Configuration Options
...
@@ -1022,7 +1033,7 @@ This `next/image` component uses browser native [lazy loading](https://caniuse.c
...
@@ -1022,7 +1033,7 @@ This `next/image` component uses browser native [lazy loading](https://caniuse.c
| Version | Changes |
| Version | Changes |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `v15.0.0` | `
contentDispositionType` configuration default changed to `attachment`.
|
| `v15.0.0` | `
decoding` prop added. `contentDispositionType` configuration default changed to `attachment`.
|
| `v14.2.0` | `overrideSrc` prop added. |
| `v14.2.0` | `overrideSrc` prop added. |
| `v14.1.0` | `getImageProps()` is stable. |
| `v14.1.0` | `getImageProps()` is stable. |
| `v14.0.0` | `onLoadingComplete` prop and `domains` config deprecated. |
| `v14.0.0` | `onLoadingComplete` prop and `domains` config deprecated. |
...
...
packages/next/src/shared/lib/get-img-props.ts
View file @
0bfa3ec1
...
@@ -254,6 +254,7 @@ export function getImgProps(
...
@@ -254,6 +254,7 @@ export function getImgProps(
placeholder
=
'empty'
,
placeholder
=
'empty'
,
blurDataURL
,
blurDataURL
,
fetchPriority
,
fetchPriority
,
decoding
=
'async'
,
layout
,
layout
,
objectFit
,
objectFit
,
objectPosition
,
objectPosition
,
...
@@ -684,7 +685,7 @@ export function getImgProps(
...
@@ -684,7 +685,7 @@ export function getImgProps(
fetchPriority
,
fetchPriority
,
width
:
widthInt
,
width
:
widthInt
,
height
:
heightInt
,
height
:
heightInt
,
decoding
:
'async'
,
decoding
,
className
,
className
,
style
:
{
...
imgStyle
,
...
placeholderStyle
},
style
:
{
...
imgStyle
,
...
placeholderStyle
},
sizes
:
imgAttributes
.
sizes
,
sizes
:
imgAttributes
.
sizes
,
...
...
test/unit/next-image-get-img-props.test.ts
View file @
0bfa3ec1
...
@@ -302,4 +302,27 @@ describe('getImageProps()', () => {
...
@@ -302,4 +302,27 @@ describe('getImageProps()', () => {
[
'src'
,
'/override.png'
],
[
'src'
,
'/override.png'
],
])
])
})
})
it
(
'should handle decoding=sync'
,
async
()
=>
{
const
{
props
}
=
getImageProps
({
alt
:
'a nice desc'
,
src
:
'/test.png'
,
decoding
:
'sync'
,
width
:
100
,
height
:
200
,
})
expect
(
warningMessages
).
toStrictEqual
([])
expect
(
Object
.
entries
(
props
)).
toStrictEqual
([
[
'alt'
,
'a nice desc'
],
[
'loading'
,
'lazy'
],
[
'width'
,
100
],
[
'height'
,
200
],
[
'decoding'
,
'sync'
],
[
'style'
,
{
color
:
'transparent'
}],
[
'srcSet'
,
'/_next/image?url=%2Ftest.png&w=128&q=75 1x, /_next/image?url=%2Ftest.png&w=256&q=75 2x'
,
],
[
'src'
,
'/_next/image?url=%2Ftest.png&w=256&q=75'
],
])
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment