From c9b256927a60011bc7bce1371c673972f84835f8 Mon Sep 17 00:00:00 2001 From: George Garside <191085+grgar@users.noreply.github.com> Date: Sun, 2 Feb 2025 06:17:15 +0000 Subject: [PATCH] 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 Co-authored-by: Mamaduka --- packages/edit-site/src/components/media/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/media/index.js b/packages/edit-site/src/components/media/index.js index e103e6bcddb5b2..0e0c7abaae4644 100644 --- a/packages/edit-site/src/components/media/index.js +++ b/packages/edit-site/src/components/media/index.js @@ -6,11 +6,11 @@ import { useEntityRecord } from '@wordpress/core-data'; function Media( { id, size = [ 'large', 'medium', 'thumbnail' ], ...props } ) { const { record: media } = useEntityRecord( 'root', 'media', id ); const currentSize = size.find( - ( s ) => !! media?.media_details?.sizes[ s ] + ( s ) => !! media?.media_details?.sizes?.[ s ] ); const mediaUrl = - media?.media_details?.sizes[ currentSize ]?.source_url || + media?.media_details?.sizes?.[ currentSize ]?.source_url || media?.source_url; if ( ! mediaUrl ) {