Skip to content

Commit 6cf7643

Browse files
authored
fix(FeaturedImage): prevent simultaneous width and fill props usage (#2009)
1 parent 32c8cf7 commit 6cf7643

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

examples/next/faustwp-getting-started/components/FeaturedImage/FeaturedImage.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,33 @@ export default function FeaturedImage({
1010
...props
1111
}) {
1212
const src = image?.sourceUrl;
13-
const { altText } = image || '';
1413

15-
width = width ? width : image?.mediaDetails?.width;
16-
height = height ? height : image?.mediaDetails?.height;
14+
if (!src) return null;
15+
16+
const { altText = '', mediaDetails = {} } = image ?? {};
17+
1718
layout = layout ?? 'fill';
1819

19-
return src && width && height ? (
20+
const dimensions = {
21+
width: layout === 'fill' ? undefined : width ?? mediaDetails?.width,
22+
height: layout === 'fill' ? undefined : height ?? mediaDetails?.height
23+
};
24+
25+
if (layout !== 'fill' && (!dimensions.width || !dimensions.height)) return null;
26+
27+
return (
2028
<figure className={className}>
2129
<Image
2230
src={src}
2331
alt={altText}
24-
layout={layout}
25-
width={width}
26-
height={height}
32+
fill={layout}
33+
width={dimensions.width}
34+
height={dimensions.height}
2735
priority={priority}
2836
{...props}
2937
/>
3038
</figure>
31-
) : null;
39+
);
3240
}
3341

3442
FeaturedImage.fragments = {

0 commit comments

Comments
 (0)