Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions packages/next/client/image.tsx
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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