Skip to content

Commit c9b2569

Browse files
grgarMamaduka
andauthored
Add optional chain to sizes indexing of media details in edit-site (#68995)
This optional chaining is already present in 21 other lines in Gutenberg where `sizes` (in `media_details`) is indexed, but is missing on these two lines. For some reason, `media_details` is an empty object for some of my attachments on my site, so this throws a TypeError. This change resolves this issue. Co-authored-by: grgar <grgarside@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
1 parent 24fad40 commit c9b2569

File tree

1 file changed

+2
-2
lines changed
  • packages/edit-site/src/components/media

1 file changed

+2
-2
lines changed

packages/edit-site/src/components/media/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { useEntityRecord } from '@wordpress/core-data';
66
function Media( { id, size = [ 'large', 'medium', 'thumbnail' ], ...props } ) {
77
const { record: media } = useEntityRecord( 'root', 'media', id );
88
const currentSize = size.find(
9-
( s ) => !! media?.media_details?.sizes[ s ]
9+
( s ) => !! media?.media_details?.sizes?.[ s ]
1010
);
1111

1212
const mediaUrl =
13-
media?.media_details?.sizes[ currentSize ]?.source_url ||
13+
media?.media_details?.sizes?.[ currentSize ]?.source_url ||
1414
media?.source_url;
1515

1616
if ( ! mediaUrl ) {

0 commit comments

Comments
 (0)