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 incorrectly warning for position: absolute parent #34551

Merged
merged 4 commits into from Feb 18, 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
3 changes: 2 additions & 1 deletion packages/next/client/image.tsx
Expand Up @@ -280,7 +280,8 @@ function handleLoading(
} else if (
layout === 'fill' &&
parent.position !== 'relative' &&
parent.position !== 'fixed'
parent.position !== 'fixed' &&
parent.position !== 'absolute'
) {
console.warn(
`Image with src "${src}" may not render properly with a parent using position:"${parent.position}". Consider changing the parent style to position:"relative" with a width and height.`
Expand Down
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import Image from 'next/image'
import jpg from '../public/test.jpg'
import png from '../public/test.png'
import avif from '../public/test.avif'
import webp from '../public/test.webp'

const Page = () => {
Expand All @@ -14,6 +15,9 @@ const Page = () => {
<div style={{ position: 'fixed', width: '200px', height: '200px' }}>
<Image id="fixed" layout="fill" priority src={png} />
</div>
<div style={{ position: 'absolute', width: '200px', height: '200px' }}>
<Image id="absolute" layout="fill" priority src={avif} />
</div>
<div style={{ position: 'relative', width: '200px', height: '200px' }}>
<Image id="relative" layout="fill" priority src={webp} />
</div>
Expand Down
3 changes: 3 additions & 0 deletions test/integration/image-component/default/test/index.test.js
Expand Up @@ -669,6 +669,9 @@ function runTests(mode) {
expect(warnings).not.toMatch(
/Image with src (.*)png(.*) may not render properly/gm
)
expect(warnings).not.toMatch(
/Image with src (.*)avif(.*) may not render properly/gm
)
expect(warnings).not.toMatch(
/Image with src (.*)webp(.*) may not render properly/gm
)
Expand Down