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 blur placeholder when JS is disabled #28269

Merged
merged 5 commits into from Aug 19, 2021
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
40 changes: 20 additions & 20 deletions packages/next/client/image.tsx
Expand Up @@ -597,26 +597,6 @@ export default function Image({
) : null}
</div>
) : null}
{!isVisible && (
<noscript>
<img
{...rest}
{...generateImgAttrs({
src,
unoptimized,
layout,
width: widthInt,
quality: qualityInt,
sizes,
loader,
})}
decoding="async"
data-nimg
style={imgStyle}
className={className}
/>
</noscript>
)}
<img
{...rest}
{...imgAttributes}
Expand All @@ -629,6 +609,26 @@ export default function Image({
}}
style={{ ...imgStyle, ...blurStyle }}
/>
<noscript>
<img
{...rest}
{...generateImgAttrs({
src,
unoptimized,
layout,
width: widthInt,
quality: qualityInt,
sizes,
loader,
})}
decoding="async"
data-nimg
style={imgStyle}
className={className}
loading={loading || 'lazy'}
/>
</noscript>

{priority ? (
// Note how we omit the `href` attribute, as it would only be relevant
// for browsers that do not support `imagesrcset`, and in those cases
Expand Down
5 changes: 5 additions & 0 deletions packages/next/types/index.d.ts
Expand Up @@ -40,6 +40,11 @@ declare module 'react' {
interface LinkHTMLAttributes<T> extends HTMLAttributes<T> {
nonce?: string
}

// <img loading="lazy"> support
interface ImgHTMLAttributes<T> extends HTMLAttributes<T> {
loading?: 'auto' | 'eager' | 'lazy'
}
}

export type Redirect =
Expand Down
2 changes: 1 addition & 1 deletion test/integration/export-image-loader/test/index.test.js
Expand Up @@ -74,7 +74,7 @@ describe('Export with custom loader next/image component', () => {
it('should contain img element with same src in html output', async () => {
const html = await fs.readFile(join(outdir, 'index.html'))
const $ = cheerio.load(html)
expect($('img[alt="icon"]').attr('src')).toBe('/custom/i.png')
expect($('img[src="/custom/o.png"]')).toBeDefined()
})

afterAll(async () => {
Expand Down
Expand Up @@ -151,7 +151,7 @@ function runTests(mode) {
const els = [].slice.apply($html('img'))
expect(els.length).toBe(2)

const [noscriptEl, el] = els
const [el, noscriptEl] = els
expect(noscriptEl.attribs.src).toBeDefined()
expect(noscriptEl.attribs.srcset).toBeDefined()

Expand Down