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
142af812
Unverified
Commit
142af812
authored
Oct 29, 2021
by
Steven
Committed by
GitHub
Oct 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Relax warning for `next/image` loader width even more (#30624)
parent
842a1302
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
10 deletions
+25
-10
image.tsx
packages/next/client/image.tsx
+10
-7
invalid-loader.js
...tegration/image-component/default/pages/invalid-loader.js
+12
-3
index.test.js
test/integration/image-component/default/test/index.test.js
+3
-0
No files found.
packages/next/client/image.tsx
View file @
142af812
...
...
@@ -451,13 +451,16 @@ export default function Image({
}
if
(
!
unoptimized
)
{
const
rand
=
Math
.
floor
(
Math
.
random
()
*
1000
)
+
100
const
url
=
loader
({
src
,
width
:
rand
,
quality
:
75
})
if
(
!
url
.
includes
(
rand
.
toString
())
&&
!
url
.
includes
(
'w='
)
&&
!
url
.
includes
(
'width='
)
)
{
const
urlStr
=
loader
({
src
,
width
:
widthInt
||
400
,
quality
:
qualityInt
||
75
,
})
let
url
:
URL
|
undefined
try
{
url
=
new
URL
(
urlStr
)
}
catch
(
err
)
{}
if
(
urlStr
===
src
||
(
url
&&
url
.
pathname
===
src
&&
!
url
.
search
))
{
console
.
warn
(
`Image with src "
${
src
}
" has a "loader" property that does not implement width. Please implement it or use the "unoptimized" property instead.`
+
`\nRead more: https://nextjs.org/docs/messages/next-image-missing-loader-width`
...
...
test/integration/image-component/default/pages/invalid-loader.js
View file @
142af812
...
...
@@ -20,18 +20,27 @@ const Page = () => {
loader
=
{({
src
,
width
})
=>
`
${
src
}
/
${
width
}
/file.jpg`
}
/
>
<
Image
id
=
"width-querystring"
id
=
"width-querystring
-w
"
src
=
"/test.webp"
width
=
{
100
}
height
=
{
100
}
loader
=
{({
src
,
width
})
=>
`
${
src
}
?w=
${
width
/
2
}
`
}
/
>
<
Image
id
=
"width-querystring-
full
"
id
=
"width-querystring-
width
"
src
=
"/test.gif"
width
=
{
100
}
height
=
{
100
}
loader
=
{({
src
,
width
})
=>
`
${
src
}
?width=
${
width
*
2
}
`
}
loader
=
{({
src
,
width
})
=>
`https://example.com
${
src
}
?width=
${
width
*
2
}
`
}
/
>
<
Image
id
=
"width-querystring-size"
src
=
"/test.tiff"
width
=
{
100
}
height
=
{
100
}
loader
=
{({
src
})
=>
`https://example.com
${
src
}
?size=medium`
}
/
>
<
footer
>
footer
<
/footer
>
<
/div
>
...
...
test/integration/image-component/default/test/index.test.js
View file @
142af812
...
...
@@ -722,6 +722,9 @@ function runTests(mode) {
expect
(
warnings
).
not
.
toMatch
(
/Image with src
(
.*
)
gif
(
.*
)
has a "loader" property that does not implement width/gm
)
expect
(
warnings
).
not
.
toMatch
(
/Image with src
(
.*
)
tiff
(
.*
)
has a "loader" property that does not implement width/gm
)
})
}
else
{
//server-only tests
...
...
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