Skip to content

Commit

Permalink
Fix issue where gallery block requests all attachments when empty (#2…
Browse files Browse the repository at this point in the history
…8621)

* Return early from building attachments for galleries

* Improve code clarity
  • Loading branch information
talldan authored and tellthemachines committed Feb 17, 2021
1 parent d73b258 commit 08ff019
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/media-utils/src/components/media-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,17 @@ class MediaUpload extends Component {

onOpen() {
this.updateCollection();
if ( ! this.props.value ) {

// Handle both this.props.value being either (number[]) multiple ids
// (for galleries) or a (number) singular id (e.g. image block).
const hasMedia = Array.isArray( this.props.value )
? !! this.props.value?.length
: !! this.props.value;

if ( ! hasMedia ) {
return;
}

if ( ! this.props.gallery ) {
const selection = this.frame.state().get( 'selection' );
castArray( this.props.value ).forEach( ( id ) => {
Expand Down

0 comments on commit 08ff019

Please sign in to comment.