Unverified Commit 142af812 authored by Steven's avatar Steven Committed by GitHub

Relax warning for `next/image` loader width even more (#30624)

parent 842a1302
...@@ -451,13 +451,16 @@ export default function Image({ ...@@ -451,13 +451,16 @@ export default function Image({
} }
if (!unoptimized) { if (!unoptimized) {
const rand = Math.floor(Math.random() * 1000) + 100 const urlStr = loader({
const url = loader({ src, width: rand, quality: 75 }) src,
if ( width: widthInt || 400,
!url.includes(rand.toString()) && quality: qualityInt || 75,
!url.includes('w=') && })
!url.includes('width=') let url: URL | undefined
) { try {
url = new URL(urlStr)
} catch (err) {}
if (urlStr === src || (url && url.pathname === src && !url.search)) {
console.warn( console.warn(
`Image with src "${src}" has a "loader" property that does not implement width. Please implement it or use the "unoptimized" property instead.` + `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` `\nRead more: https://nextjs.org/docs/messages/next-image-missing-loader-width`
......
...@@ -20,18 +20,27 @@ const Page = () => { ...@@ -20,18 +20,27 @@ const Page = () => {
loader={({ src, width }) => `${src}/${width}/file.jpg`} loader={({ src, width }) => `${src}/${width}/file.jpg`}
/> />
<Image <Image
id="width-querystring" id="width-querystring-w"
src="/test.webp" src="/test.webp"
width={100} width={100}
height={100} height={100}
loader={({ src, width }) => `${src}?w=${width / 2}`} loader={({ src, width }) => `${src}?w=${width / 2}`}
/> />
<Image <Image
id="width-querystring-full" id="width-querystring-width"
src="/test.gif" src="/test.gif"
width={100} width={100}
height={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> <footer>footer</footer>
</div> </div>
......
...@@ -722,6 +722,9 @@ function runTests(mode) { ...@@ -722,6 +722,9 @@ function runTests(mode) {
expect(warnings).not.toMatch( expect(warnings).not.toMatch(
/Image with src (.*)gif(.*) has a "loader" property that does not implement width/gm /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 { } else {
//server-only tests //server-only tests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment