Skip to content

Commit

Permalink
Another optimisation - only return a new imageData reference if all i…
Browse files Browse the repository at this point in the history
…mages have data resolved
  • Loading branch information
Glen Davies committed Apr 11, 2021
1 parent dbda7e9 commit 342695e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/**
* External dependencies
*/
import { isEqual, isEmpty, find, concat, differenceBy, some } from 'lodash';
import {
isEqual,
isEmpty,
find,
concat,
differenceBy,
some,
every,
} from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -144,12 +152,18 @@ function GalleryEdit( props ) {
}

const getMedia = select( 'core' ).getMedia;
return innerBlockImages.map( ( imageBlock ) => {
const newImageData = innerBlockImages.map( ( imageBlock ) => {
return {
id: imageBlock.attributes.id,
data: getMedia( imageBlock.attributes.id ),
};
} );

if ( every( newImageData, ( img ) => img.data ) ) {
return newImageData;
}

return imageData;
},
[ innerBlockImages ]
);
Expand Down

0 comments on commit 342695e

Please sign in to comment.