Skip to content

Commit

Permalink
DataViews: Correctly display featured image that don't have image siz…
Browse files Browse the repository at this point in the history
…es (#59111)

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
  • Loading branch information
6 people authored and getdave committed Feb 20, 2024
1 parent 7b589f9 commit a2f73e6
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/edit-site/src/components/media/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ function Media( { id, size = [ 'large', 'medium', 'thumbnail' ], ...props } ) {
const currentSize = size.find(
( s ) => !! media?.media_details?.sizes[ s ]
);
const mediaDetails = media?.media_details?.sizes[ currentSize ];
if ( ! mediaDetails ) {

const mediaUrl =
media?.media_details?.sizes[ currentSize ]?.source_url ||
media?.source_url;

if ( ! mediaUrl ) {
return null;
}

return (
<img
{ ...props }
src={ mediaDetails.source_url }
alt={ media.alt_text }
/>
);
return <img { ...props } src={ mediaUrl } alt={ media.alt_text } />;
}

export default Media;

0 comments on commit a2f73e6

Please sign in to comment.