Unverified Commit e735c514 authored by Steven's avatar Steven Committed by GitHub

Remove `<noscript>` from `next/future/image` (#40075)

This PR removes `<noscript>` from `next/future/image` since it is no longer needed now that we use a svg blur placeholder (as opposed to css filter).

- Fixes  #38621 
- Closes #39736 
parent c3ceeb03
......@@ -134,7 +134,6 @@ type ImageElementProps = Omit<ImageProps, 'src' | 'loader'> & {
onLoadingCompleteRef: React.MutableRefObject<OnLoadingComplete | undefined>
setBlurComplete: (b: boolean) => void
setShowAltText: (b: boolean) => void
noscriptSizes: string | undefined
}
function getWidths(
......@@ -343,7 +342,6 @@ const ImageElement = ({
setShowAltText,
onLoad,
onError,
noscriptSizes,
...rest
}: ImageElementProps) => {
loading = isLazy ? 'lazy' : loading
......@@ -438,30 +436,6 @@ const ImageElement = ({
}
}}
/>
{placeholder === 'blur' && (
<noscript>
<img
{...rest}
{...generateImgAttrs({
config,
src: srcString,
unoptimized,
width: widthInt,
quality: qualityInt,
sizes: noscriptSizes,
loader,
})}
width={widthInt}
height={heightInt}
decoding="async"
data-nimg={`future${fill ? '-fill' : ''}`}
style={imgStyle}
className={className}
// @ts-ignore - TODO: upgrade to `@types/react@17`
loading={loading}
/>
</noscript>
)}
</>
)
}
......@@ -884,7 +858,6 @@ export default function Image({
onLoadingCompleteRef,
setBlurComplete,
setShowAltText,
noscriptSizes: sizes,
...rest,
}
return (
......
......@@ -1097,15 +1097,6 @@ function runTests(mode) {
)
})
it('should not use blurry placeholder for <noscript> image', async () => {
const html = await renderViaHTTP(appPort, '/blurry-placeholder')
const $html = cheerio.load(html)
const img = $html('noscript > img')[0]
expect(img).toBeDefined()
expect(img.attribs.id).toBe('blurry-placeholder-raw')
expect(img.attribs.style).toBe('color:transparent')
})
it('should remove blurry placeholder after image loads', async () => {
const browser = await webdriver(appPort, '/blurry-placeholder')
await check(
......
module.exports = {
experimental: {
images: {
allowFutureImage: true,
},
},
}
import React from 'react'
import Image from 'next/future/image'
const myLoader = ({ src, width, quality }) => {
return `https://example.vercel.sh${src}?w~~${width},q~~${quality}`
}
const Page = () => {
return (
<div>
<p>noscript images</p>
<Image id="basic-image" src="/basic.jpg" width={640} height={360} />
<Image
loader={myLoader}
id="image-with-loader"
src="/remote-image.jpg"
width={640}
height={360}
/>
<Image
id="image-with-blur"
src="/blur.jpg"
width={640}
height={360}
placeholder="blur"
blurDataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mMU/M9QDwADygGR4qH9qQAAAABJRU5ErkJggg=="
/>
</div>
)
}
export default Page
/* eslint-env jest */
import { join } from 'path'
import cheerio from 'cheerio'
import {
findPort,
killApp,
launchApp,
nextStart,
nextBuild,
renderViaHTTP,
} from 'next-test-utils'
const appDir = join(__dirname, '../')
let appPort
let app
function runTests() {
it('should include noscript for placeholder=blur but not others', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect($('noscript > img#basic-image').attr('src')).toBeUndefined()
expect($('noscript > img#image-with-loader').attr('src')).toBeUndefined()
expect($('noscript > img#image-with-blur').attr('src')).toMatch('blur.jpg')
})
}
describe('Future Image Component Noscript Tests', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests()
})
describe('server mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests()
})
})
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