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
409772ec
Unverified
Commit
409772ec
authored
Aug 25, 2026
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Aug 25, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[15.5.x] [next/image]: disable avif image optimization
https://github.com/vercel/next-js-mirror/pull/165
parent
9c44b882
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
152 additions
and
16 deletions
+152
-16
blur.ts
.../next/src/build/webpack/loaders/next-image-loader/blur.ts
+1
-1
image.tsx
packages/next/src/client/legacy/image.tsx
+9
-1
image-optimizer.ts
packages/next/src/server/image-optimizer.ts
+12
-1
get-img-props.ts
packages/next/src/shared/lib/get-img-props.ts
+9
-1
test.avif
test/e2e/image-optimizer/app/public/test.avif
+0
-0
sharp.test.ts
test/e2e/image-optimizer/sharp.test.ts
+18
-0
util.ts
test/integration/image-optimizer/test/util.ts
+21
-12
next-image-get-img-props.test.ts
test/unit/next-image-get-img-props.test.ts
+30
-0
next-image-legacy.test.ts
test/unit/next-image-legacy.test.ts
+34
-0
get-blur-image.test.ts
test/unit/next-image-loader/get-blur-image.test.ts
+18
-0
No files found.
packages/next/src/build/webpack/loaders/next-image-loader/blur.ts
View file @
409772ec
...
...
@@ -3,7 +3,7 @@ import { optimizeImage } from '../../../../server/image-optimizer'
const
BLUR_IMG_SIZE
=
8
const
BLUR_QUALITY
=
70
const
VALID_BLUR_EXT
=
[
'jpeg'
,
'png'
,
'webp'
,
'avif'
]
// should match other usages
const
VALID_BLUR_EXT
=
[
'jpeg'
,
'png'
,
'webp'
]
// should match other usages
export
async
function
getBlurImage
(
content
:
Buffer
,
...
...
packages/next/src/client/legacy/image.tsx
View file @
409772ec
...
...
@@ -683,6 +683,7 @@ export default function Image({
}
let
staticSrc
=
''
let
isStaticAvif
=
false
if
(
isStaticImport
(
src
))
{
const
staticImageData
=
isStaticRequire
(
src
)
?
src
.
default
:
src
...
...
@@ -695,6 +696,7 @@ export default function Image({
}
blurDataURL
=
blurDataURL
||
staticImageData
.
blurDataURL
staticSrc
=
staticImageData
.
src
isStaticAvif
=
/
\.
avif
(?:\?
|$
)
/i
.
test
(
staticSrc
)
if
(
!
layout
||
layout
!==
'fill'
)
{
height
=
height
||
staticImageData
.
height
width
=
width
||
staticImageData
.
width
...
...
@@ -709,6 +711,12 @@ export default function Image({
}
src
=
typeof
src
===
'string'
?
src
:
staticSrc
// Generating a blurDataURL requires decoding the source image, so static AVIF
// imports do not receive one while AVIF input optimization is disabled.
if
(
isStaticAvif
&&
placeholder
===
'blur'
&&
!
blurDataURL
)
{
placeholder
=
'empty'
}
let
isLazy
=
!
priority
&&
(
loading
===
'lazy'
||
typeof
loading
===
'undefined'
)
if
(
src
.
startsWith
(
'data:'
)
||
src
.
startsWith
(
'blob:'
))
{
...
...
@@ -839,7 +847,7 @@ export default function Image({
)
}
if
(
!
blurDataURL
)
{
const
VALID_BLUR_EXT
=
[
'jpeg'
,
'png'
,
'webp'
,
'avif'
]
// should match next-image-loader
const
VALID_BLUR_EXT
=
[
'jpeg'
,
'png'
,
'webp'
]
// should match next-image-loader
throw
new
Error
(
`Image with src "
${
src
}
" has "placeholder='blur'" property but is missing the "blurDataURL" property.
...
...
packages/next/src/server/image-optimizer.ts
View file @
409772ec
...
...
@@ -50,7 +50,7 @@ const BMP = 'image/bmp'
const
PDF
=
'application/pdf'
const
CACHE_VERSION
=
4
const
ANIMATABLE_TYPES
=
[
WEBP
,
PNG
,
GIF
]
const
BYPASS_TYPES
=
[
SVG
,
ICO
,
ICNS
,
BMP
,
JXL
,
HEIC
]
const
BYPASS_TYPES
=
[
SVG
,
ICO
,
ICNS
,
BMP
,
JXL
,
HEIC
,
AVIF
]
const
BLUR_IMG_SIZE
=
8
// should match `next-image-loader`
const
BLUR_QUALITY
=
70
// should match `next-image-loader`
...
...
@@ -92,6 +92,17 @@ export function getSharp(concurrency: number | null | undefined) {
try
{
// eslint-disable-next-line @next/internal/typechecked-require -- sharp 0.34 and 0.35 type the module differently, see SharpModule
_sharp
=
require
(
'sharp'
)
as
SharpModule
_sharp
.
block
({
operation
:
[
'VipsForeignLoad'
]
})
_sharp
.
unblock
({
operation
:
[
'VipsForeignLoadJpeg'
,
'VipsForeignLoadNsgif'
,
'VipsForeignLoadPng'
,
'VipsForeignLoadSvg'
,
'VipsForeignLoadTiff'
,
'VipsForeignLoadWebp'
,
],
})
if
(
_sharp
&&
_sharp
.
concurrency
()
>
1
)
{
// Reducing concurrency should reduce the memory usage too.
// We more aggressively reduce in dev but also reduce in prod.
...
...
packages/next/src/shared/lib/get-img-props.ts
View file @
409772ec
...
...
@@ -369,6 +369,7 @@ export function getImgProps(
let
heightInt
=
getInt
(
height
)
let
blurWidth
:
number
|
undefined
let
blurHeight
:
number
|
undefined
let
isStaticAvif
=
false
if
(
isStaticImport
(
src
))
{
const
staticImageData
=
isStaticRequire
(
src
)
?
src
.
default
:
src
...
...
@@ -391,6 +392,7 @@ export function getImgProps(
blurHeight
=
staticImageData
.
blurHeight
blurDataURL
=
blurDataURL
||
staticImageData
.
blurDataURL
staticSrc
=
staticImageData
.
src
isStaticAvif
=
/
\.
avif
(?:\?
|$
)
/i
.
test
(
staticSrc
)
if
(
!
fill
)
{
if
(
!
widthInt
&&
!
heightInt
)
{
...
...
@@ -407,6 +409,12 @@ export function getImgProps(
}
src
=
typeof
src
===
'string'
?
src
:
staticSrc
// Generating a blurDataURL requires decoding the source image, so static AVIF
// imports do not receive one while AVIF input optimization is disabled.
if
(
isStaticAvif
&&
placeholder
===
'blur'
&&
!
blurDataURL
)
{
placeholder
=
'empty'
}
let
isLazy
=
!
priority
&&
(
loading
===
'lazy'
||
typeof
loading
===
'undefined'
)
if
(
!
src
||
src
.
startsWith
(
'data:'
)
||
src
.
startsWith
(
'blob:'
))
{
...
...
@@ -551,7 +559,7 @@ export function getImgProps(
)
}
if
(
placeholder
===
'blur'
&&
!
blurDataURL
)
{
const
VALID_BLUR_EXT
=
[
'jpeg'
,
'png'
,
'webp'
,
'avif'
]
// should match next-image-loader
const
VALID_BLUR_EXT
=
[
'jpeg'
,
'png'
,
'webp'
]
// should match next-image-loader
throw
new
Error
(
`Image with src "
${
src
}
" has "placeholder='blur'" property but is missing the "blurDataURL" property.
...
...
test/e2e/image-optimizer/app/public/test.avif
0 → 100644
View file @
409772ec
File added
test/e2e/image-optimizer/sharp.test.ts
0 → 100644
View file @
409772ec
import
fs
from
'fs-extra'
import
{
join
}
from
'path'
import
{
optimizeImage
}
from
'next/dist/server/image-optimizer'
describe
(
'with latest sharp'
,
()
=>
{
it
(
'should block avif decoding below the optimizer bypass'
,
async
()
=>
{
const
buffer
=
await
fs
.
readFile
(
join
(
__dirname
,
'app/public/test.avif'
))
await
expect
(
optimizeImage
({
buffer
,
contentType
:
'image/webp'
,
quality
:
75
,
width
:
100
,
})
).
rejects
.
toThrow
()
})
})
test/integration/image-optimizer/test/util.ts
View file @
409772ec
...
...
@@ -100,6 +100,15 @@ export async function expectWidth(res, w, { expectAnimated = false } = {}) {
expect
(
isAnimated
(
buffer
)).
toBe
(
expectAnimated
)
}
async
function
expectUnoptimizedImage
(
res
,
filename
:
string
)
{
const
buffer
=
Buffer
.
from
(
await
res
.
arrayBuffer
())
const
source
=
await
fs
.
readFile
(
join
(
__dirname
,
'../app/public'
,
filename
))
expect
(
buffer
).
toEqual
(
source
)
expect
(
res
.
headers
.
get
(
'Content-Length'
)).
toBe
(
Buffer
.
byteLength
(
source
).
toString
()
)
}
export
const
cleanImagesDir
=
async
(
ctx
:
{
imagesDir
:
string
})
=>
{
console
.
warn
(
'Cleaning'
,
ctx
.
imagesDir
)
await
fs
.
remove
(
ctx
.
imagesDir
)
...
...
@@ -523,23 +532,23 @@ export function runTests(ctx: RunTestsCtx) {
await
expectWidth
(
res
,
ctx
.
w
)
})
it
(
'should
downlevel avif format to jpeg
for old Safari'
,
async
()
=>
{
it
(
'should
bypass avif input
for old Safari'
,
async
()
=>
{
const
accept
=
'image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5'
const
query
=
{
w
:
ctx
.
w
,
q
:
74
,
url
:
'/test.avif'
}
const
opts
=
{
headers
:
{
accept
}
}
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
'/_next/image'
,
query
,
opts
)
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toContain
(
'image/
jpeg
'
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toContain
(
'image/
avif
'
)
expect
(
res
.
headers
.
get
(
'Cache-Control'
)).
toBe
(
`public, max-age=
${
isDev
?
0
:
minimumCacheTTL
}
, must-revalidate`
)
expect
(
res
.
headers
.
get
(
'Vary'
)).
toBe
(
'Accept'
)
expect
(
res
.
headers
.
get
(
'etag'
)).
toBeTruthy
()
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`
${
contentDispositionType
}
; filename="test.
jpeg
"`
`
${
contentDispositionType
}
; filename="test.
avif
"`
)
await
expect
Width
(
res
,
ctx
.
w
)
await
expect
UnoptimizedImage
(
res
,
'test.avif'
)
})
it
(
'should fail when url is missing'
,
async
()
=>
{
...
...
@@ -805,21 +814,21 @@ export function runTests(ctx: RunTestsCtx) {
await
expectWidth
(
res
,
ctx
.
w
)
})
it
(
'should
resize avif
'
,
async
()
=>
{
const
query
=
{
url
:
'/test.avif'
,
w
:
ctx
.
w
,
q
:
75
}
it
(
'should
bypass optimization for avif input
'
,
async
()
=>
{
const
query
=
{
url
:
'/test.avif'
,
w
:
ctx
.
w
,
q
:
ctx
.
q
}
const
opts
=
{
headers
:
{
accept
:
'image/webp'
}
}
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
'/_next/image'
,
query
,
opts
)
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toBe
(
'image/
webp
'
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toBe
(
'image/
avif
'
)
expect
(
res
.
headers
.
get
(
'Cache-Control'
)).
toBe
(
`public, max-age=
${
isDev
?
0
:
minimumCacheTTL
}
, must-revalidate`
)
expect
(
res
.
headers
.
get
(
'Vary'
)).
toBe
(
'Accept'
)
expect
(
res
.
headers
.
get
(
'etag'
)).
toBeTruthy
()
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`
${
contentDispositionType
}
; filename="test.
webp
"`
`
${
contentDispositionType
}
; filename="test.
avif
"`
)
await
expect
Width
(
res
,
ctx
.
w
)
await
expect
UnoptimizedImage
(
res
,
'test.avif'
)
})
it
(
'should resize relative url and old Chrome accept header as webp'
,
async
()
=>
{
...
...
@@ -863,8 +872,8 @@ export function runTests(ctx: RunTestsCtx) {
await
expectWidth
(
res
,
ctx
.
w
)
})
it
(
'should
resize avif and maintain format
'
,
async
()
=>
{
const
query
=
{
url
:
'/test.avif'
,
w
:
ctx
.
w
,
q
:
75
}
it
(
'should
bypass avif input when avif output is enabled
'
,
async
()
=>
{
const
query
=
{
url
:
'/test.avif'
,
w
:
ctx
.
w
,
q
:
ctx
.
q
}
const
opts
=
{
headers
:
{
accept
:
'image/avif'
}
}
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
'/_next/image'
,
query
,
opts
)
expect
(
res
.
status
).
toBe
(
200
)
...
...
@@ -877,7 +886,7 @@ export function runTests(ctx: RunTestsCtx) {
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`
${
contentDispositionType
}
; filename="test.avif"`
)
await
expect
Width
(
res
,
ctx
.
w
)
await
expect
UnoptimizedImage
(
res
,
'test.avif'
)
})
it
(
'should compress avif smaller than webp at q=100'
,
async
()
=>
{
...
...
test/unit/next-image-get-img-props.test.ts
View file @
409772ec
...
...
@@ -61,6 +61,36 @@ describe('getImageProps()', () => {
expect
(
props
.
srcSet
).
toBeString
()
})
it
(
'should disable an automatic blur placeholder for a static avif'
,
()
=>
{
const
{
props
}
=
getImageProps
({
alt
:
'a nice desc'
,
src
:
{
src
:
'/_next/static/media/test.abc123.avif'
,
width
:
100
,
height
:
200
,
},
placeholder
:
'blur'
,
})
expect
(
props
.
style
).
toStrictEqual
({
color
:
'transparent'
})
})
it
(
'should preserve a custom blur placeholder for a static avif'
,
()
=>
{
const
blurDataURL
=
'data:image/png;base64,custom'
const
{
props
}
=
getImageProps
({
alt
:
'a nice desc'
,
src
:
{
src
:
'/_next/static/media/test.abc123.avif'
,
width
:
100
,
height
:
200
,
},
placeholder
:
'blur'
,
blurDataURL
,
})
expect
(
props
.
style
?.
backgroundImage
).
toContain
(
blurDataURL
)
})
it
(
'should handle priority'
,
async
()
=>
{
const
{
props
}
=
getImageProps
({
alt
:
'a nice desc'
,
...
...
test/unit/next-image-legacy.test.ts
View file @
409772ec
...
...
@@ -80,6 +80,40 @@ describe('Image Legacy Rendering', () => {
expect
(
$3
(
'noscript'
).
length
).
toBe
(
1
)
})
it
(
'should disable an automatic blur placeholder for a static avif'
,
()
=>
{
const
element
=
React
.
createElement
(
Image
,
{
src
:
{
src
:
'/_next/static/media/test.abc123.avif'
,
width
:
100
,
height
:
200
,
},
placeholder
:
'blur'
,
loading
:
'eager'
,
})
const
$
=
cheerio
.
load
(
ReactDOM
.
renderToString
(
element
))
expect
(
$
(
'noscript'
).
length
).
toBe
(
0
)
expect
(
$
.
html
()).
not
.
toContain
(
'background-image'
)
})
it
(
'should preserve a custom blur placeholder for a static avif'
,
()
=>
{
const
blurDataURL
=
'data:image/png;base64,custom'
const
element
=
React
.
createElement
(
Image
,
{
src
:
{
src
:
'/_next/static/media/test.abc123.avif'
,
width
:
100
,
height
:
200
,
},
placeholder
:
'blur'
,
blurDataURL
,
loading
:
'eager'
,
})
const
$
=
cheerio
.
load
(
ReactDOM
.
renderToString
(
element
))
expect
(
$
(
'noscript'
).
length
).
toBe
(
1
)
expect
(
$
.
html
()).
toContain
(
blurDataURL
)
})
it
(
'should render the correct sizes passed when a noscript element is rendered'
,
async
()
=>
{
const
element
=
React
.
createElement
(
Image
,
{
src
:
'/test.png'
,
...
...
test/unit/next-image-loader/get-blur-image.test.ts
View file @
409772ec
...
...
@@ -35,4 +35,22 @@ describe('getBlurImage', () => {
expect
(
result
).
toBeObject
()
expect
(
result
.
dataURL
).
toBeUndefined
()
})
it
(
'should not generate a blur placeholder for avif'
,
async
()
=>
{
const
buffer
=
await
getImage
(
'../image-optimizer/images/test.avif'
)
const
result
=
await
getBlurImage
(
buffer
,
'avif'
,
{
width
:
400
,
height
:
400
},
{
...
context
,
outputPath
:
'/_next/static/media/test.avif'
,
}
)
expect
(
result
).
toBeObject
()
expect
(
result
).
toStrictEqual
({
dataURL
:
undefined
,
width
:
0
,
height
:
0
,
})
})
})
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