Unverified Commit 65e704da authored by Steven's avatar Steven Committed by GitHub

Fix `next/image` noscript when blur and priority (#34973)

Fixes a bug where browsers with scripts disabled did not work with `<Image placeholder="blur" priority />`.

- Introduced in #32918 
parent a5180362
...@@ -722,7 +722,7 @@ export default function Image({ ...@@ -722,7 +722,7 @@ export default function Image({
ref={imgRef} ref={imgRef}
style={{ ...imgStyle, ...blurStyle }} style={{ ...imgStyle, ...blurStyle }}
/> />
{isLazy && ( {(isLazy || placeholder === 'blur') && (
<noscript> <noscript>
<img <img
{...rest} {...rest}
......
...@@ -46,4 +46,37 @@ describe('Image rendering', () => { ...@@ -46,4 +46,37 @@ describe('Image rendering', () => {
expect($2('noscript').length).toBe(0) expect($2('noscript').length).toBe(0)
expect($lazy('noscript').length).toBe(1) expect($lazy('noscript').length).toBe(1)
}) })
it('should render noscript element when placeholder=blur', async () => {
const element1 = React.createElement(Image, {
src: '/test.png',
width: 100,
height: 100,
loading: 'eager',
placeholder: 'blur',
blurDataURL: 'data:image/png;base64',
})
const element2 = React.createElement(Image, {
src: '/test.png',
width: 100,
height: 100,
placeholder: 'blur',
blurDataURL: 'data:image/png;base64',
loading: 'eager',
})
const element3 = React.createElement(Image, {
src: '/test.png',
width: 100,
height: 100,
placeholder: 'blur',
blurDataURL: 'data:image/png;base64',
priority: true,
})
const $1 = cheerio.load(ReactDOM.renderToString(element1))
const $2 = cheerio.load(ReactDOM.renderToString(element2))
const $3 = cheerio.load(ReactDOM.renderToString(element3))
expect($1('noscript').length).toBe(1)
expect($2('noscript').length).toBe(1)
expect($3('noscript').length).toBe(1)
})
}) })
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