Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix next/image noscript when blur and priority #34973

Merged
merged 3 commits into from Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/client/image.tsx
Expand Up @@ -722,7 +722,7 @@ export default function Image({
ref={imgRef}
style={{ ...imgStyle, ...blurStyle }}
/>
{isLazy && (
{(isLazy || placeholder === 'blur') && (
<noscript>
<img
{...rest}
Expand Down
33 changes: 33 additions & 0 deletions test/unit/image-rendering.test.ts
Expand Up @@ -46,4 +46,37 @@ describe('Image rendering', () => {
expect($2('noscript').length).toBe(0)
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)
})
})