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 layout="raw" image element sizes prop #35809

Merged
merged 3 commits into from Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions packages/next/client/image.tsx
Expand Up @@ -843,7 +843,6 @@ const ImageElement = ({
imgRef,
placeholder,
loading,
sizes,
srcString,
config,
unoptimized,
Expand All @@ -855,7 +854,7 @@ const ImageElement = ({
<img
{...rest}
{...imgAttributes}
{...(layout === 'raw' && !sizes
{...(layout === 'raw' && !imgAttributes.sizes
? { height: heightInt, width: widthInt }
: {})}
decoding="async"
Expand All @@ -875,10 +874,10 @@ const ImageElement = ({
layout,
width: widthInt,
quality: qualityInt,
sizes,
sizes: imgAttributes.sizes,
loader,
})}
{...(layout === 'raw' && !sizes
{...(layout === 'raw' && !imgAttributes.sizes
? { height: heightInt, width: widthInt }
: {})}
decoding="async"
Expand Down
10 changes: 10 additions & 0 deletions test/integration/image-component/default/test/index.test.js
Expand Up @@ -610,13 +610,23 @@ function runTests(mode) {
expect(await browser.elementById('raw1').getAttribute('style')).toBe(
`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(
`/_next/image?url=%2Fwide.png&w=1200&q=75 1x, /_next/image?url=%2Fwide.png&w=3840&q=75 2x`
)

expect(await browser.elementById('raw2').getAttribute('style')).toBe(
'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(
`/_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`
)
Expand Down