Skip to content

Commit

Permalink
Merge branch 'canary' into x-modern-legacy-doc-2
Browse files Browse the repository at this point in the history
  • Loading branch information
devknoll committed Aug 26, 2021
2 parents 435ea3b + d8093ec commit bb29b3c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
20 changes: 11 additions & 9 deletions packages/next/client/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,17 @@ function handleLoading(
onLoadingComplete({ naturalWidth, naturalHeight })
}
if (process.env.NODE_ENV !== 'production') {
const parent = img.parentElement?.parentElement?.style
if (layout === 'responsive' && parent?.display === 'flex') {
console.warn(
`Image with src "${src}" may not render properly as a child of a flex container. Consider wrapping the image with a div to configure the width.`
)
} else if (layout === 'fill' && parent?.position !== 'relative') {
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.`
)
if (img.parentElement?.parentElement) {
const parent = getComputedStyle(img.parentElement.parentElement)
if (layout === 'responsive' && parent.display === 'flex') {
console.warn(
`Image with src "${src}" may not render properly as a child of a flex container. Consider wrapping the image with a div to configure the width.`
)
} else if (layout === 'fill' && parent.position !== 'relative') {
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import Image from 'next/image'
import img from '../public/test.jpg'
import style from '../style.module.css'

const Page = () => {
return (
<div style={{ display: 'flex' }}>
<div className={style.displayFlex}>
<Image id="img" layout="responsive" src={img} />
</div>
)
Expand Down
3 changes: 3 additions & 0 deletions test/integration/image-component/default/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.displayFlex {
display: flex;
}

0 comments on commit bb29b3c

Please sign in to comment.