Unverified Commit 352e60de authored by Alex Castle's avatar Alex Castle Committed by GitHub

Fix `layout="raw"` image element sizes prop (#35809)

This fixes an issue with how the sizes prop was being applied to images with the experimental raw layout. The only effects were on the raw layout, so won't effect any non-experimental functionality.
parent 0eb9f7e7
...@@ -843,7 +843,6 @@ const ImageElement = ({ ...@@ -843,7 +843,6 @@ const ImageElement = ({
imgRef, imgRef,
placeholder, placeholder,
loading, loading,
sizes,
srcString, srcString,
config, config,
unoptimized, unoptimized,
...@@ -855,7 +854,7 @@ const ImageElement = ({ ...@@ -855,7 +854,7 @@ const ImageElement = ({
<img <img
{...rest} {...rest}
{...imgAttributes} {...imgAttributes}
{...(layout === 'raw' && !sizes {...(layout === 'raw' && !imgAttributes.sizes
? { height: heightInt, width: widthInt } ? { height: heightInt, width: widthInt }
: {})} : {})}
decoding="async" decoding="async"
...@@ -875,10 +874,10 @@ const ImageElement = ({ ...@@ -875,10 +874,10 @@ const ImageElement = ({
layout, layout,
width: widthInt, width: widthInt,
quality: qualityInt, quality: qualityInt,
sizes, sizes: imgAttributes.sizes,
loader, loader,
})} })}
{...(layout === 'raw' && !sizes {...(layout === 'raw' && !imgAttributes.sizes
? { height: heightInt, width: widthInt } ? { height: heightInt, width: widthInt }
: {})} : {})}
decoding="async" decoding="async"
......
...@@ -610,6 +610,12 @@ function runTests(mode) { ...@@ -610,6 +610,12 @@ function runTests(mode) {
expect(await browser.elementById('raw1').getAttribute('style')).toBe( expect(await browser.elementById('raw1').getAttribute('style')).toBe(
`aspect-ratio:1200 / 700` `aspect-ratio:1200 / 700`
) )
expect(await browser.elementById('raw1').getAttribute('height')).toBe(
'700'
)
expect(await browser.elementById('raw1').getAttribute('width')).toBe(
'1200'
)
expect(await browser.elementById('raw1').getAttribute('srcset')).toBe( expect(await browser.elementById('raw1').getAttribute('srcset')).toBe(
`/_next/image?url=%2Fwide.png&w=1200&q=75 1x, /_next/image?url=%2Fwide.png&w=3840&q=75 2x` `/_next/image?url=%2Fwide.png&w=1200&q=75 1x, /_next/image?url=%2Fwide.png&w=3840&q=75 2x`
) )
...@@ -617,6 +623,10 @@ function runTests(mode) { ...@@ -617,6 +623,10 @@ function runTests(mode) {
expect(await browser.elementById('raw2').getAttribute('style')).toBe( expect(await browser.elementById('raw2').getAttribute('style')).toBe(
'padding-left:4rem;width:100%;object-position:30% 30%;aspect-ratio:1200 / 700' 'padding-left:4rem;width:100%;object-position:30% 30%;aspect-ratio:1200 / 700'
) )
expect(
await browser.elementById('raw2').getAttribute('height')
).toBeNull()
expect(await browser.elementById('raw2').getAttribute('width')).toBeNull()
expect(await browser.elementById('raw2').getAttribute('srcset')).toBe( expect(await browser.elementById('raw2').getAttribute('srcset')).toBe(
`/_next/image?url=%2Fwide.png&w=16&q=75 16w, /_next/image?url=%2Fwide.png&w=32&q=75 32w, /_next/image?url=%2Fwide.png&w=48&q=75 48w, /_next/image?url=%2Fwide.png&w=64&q=75 64w, /_next/image?url=%2Fwide.png&w=96&q=75 96w, /_next/image?url=%2Fwide.png&w=128&q=75 128w, /_next/image?url=%2Fwide.png&w=256&q=75 256w, /_next/image?url=%2Fwide.png&w=384&q=75 384w, /_next/image?url=%2Fwide.png&w=640&q=75 640w, /_next/image?url=%2Fwide.png&w=750&q=75 750w, /_next/image?url=%2Fwide.png&w=828&q=75 828w, /_next/image?url=%2Fwide.png&w=1080&q=75 1080w, /_next/image?url=%2Fwide.png&w=1200&q=75 1200w, /_next/image?url=%2Fwide.png&w=1920&q=75 1920w, /_next/image?url=%2Fwide.png&w=2048&q=75 2048w, /_next/image?url=%2Fwide.png&w=3840&q=75 3840w` `/_next/image?url=%2Fwide.png&w=16&q=75 16w, /_next/image?url=%2Fwide.png&w=32&q=75 32w, /_next/image?url=%2Fwide.png&w=48&q=75 48w, /_next/image?url=%2Fwide.png&w=64&q=75 64w, /_next/image?url=%2Fwide.png&w=96&q=75 96w, /_next/image?url=%2Fwide.png&w=128&q=75 128w, /_next/image?url=%2Fwide.png&w=256&q=75 256w, /_next/image?url=%2Fwide.png&w=384&q=75 384w, /_next/image?url=%2Fwide.png&w=640&q=75 640w, /_next/image?url=%2Fwide.png&w=750&q=75 750w, /_next/image?url=%2Fwide.png&w=828&q=75 828w, /_next/image?url=%2Fwide.png&w=1080&q=75 1080w, /_next/image?url=%2Fwide.png&w=1200&q=75 1200w, /_next/image?url=%2Fwide.png&w=1920&q=75 1920w, /_next/image?url=%2Fwide.png&w=2048&q=75 2048w, /_next/image?url=%2Fwide.png&w=3840&q=75 3840w`
) )
......
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