Unverified Commit 22676abb authored by Marco Valsecchi's avatar Marco Valsecchi Committed by GitHub

Fix next/image noscript src path with loaders (#24011)

In the `noscript` img version the correct `src` and `sizes` attributes are overwritten by not necessary inline declaration; in particular using the loaders the `src` attribute not take the right absolute path. I found this issue using a custom loader and because my site didn't indexing any images on the Google image search.

Fixes #24277
parent 2ac47d21
...@@ -569,9 +569,7 @@ export default function Image({ ...@@ -569,9 +569,7 @@ export default function Image({
sizes, sizes,
loader, loader,
})} })}
src={src}
decoding="async" decoding="async"
sizes={sizes}
style={imgStyle} style={imgStyle}
className={className} className={className}
/> />
......
import React from 'react'
import Image from 'next/image'
const myLoader = ({ src, width, quality }) => {
return `https://customresolver.com${src}?w~~${width},q~~${quality}`
}
const Page = () => {
return (
<div>
<p>noscript images</p>
<Image id="basic-image" src="/basic-image.jpg" width={640} height={360} />
<Image
loader={myLoader}
id="image-with-loader"
src="/remote-image.jpg"
width={640}
height={360}
/>
</div>
)
}
export default Page
/* eslint-env jest */
import { join } from 'path'
import cheerio from 'cheerio'
import {
killApp,
findPort,
nextStart,
nextBuild,
renderViaHTTP,
} from 'next-test-utils'
jest.setTimeout(1000 * 30)
const appDir = join(__dirname, '../')
let appPort
let app
describe('Noscript Tests', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
describe('Noscript page source tests', () => {
it('should use local API for noscript img#basic-image src attribute', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect($('noscript > img#basic-image').attr('src')).toMatch(
/^\/_next\/image/
)
})
it('should use loader url for noscript img#image-with-loader src attribute', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect($('noscript > img#image-with-loader').attr('src')).toMatch(
/^https:\/\/customresolver.com/
)
})
})
})
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