Skip to content

Commit

Permalink
Fix crash after we open image preview
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Jan 30, 2025
1 parent 92ec8b9 commit cc6bb9f
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,23 @@ const WpcomMediaUrlUploadForm = ( { ajaxUrl, action, nonce, isSiteEditor } ) =>
if ( success ) {
window.wp.media.model.Attachment.get( data.attachment_id ).fetch( {
success: function ( attachment ) {
const addAttachment = attachmentToAdd => {
( window.wp.media.frame.controller || window.wp.media.frame ).content
.get()
.collection.add( attachmentToAdd );
};

if ( isSiteEditor ) {
const mediaLibraryTab = window.wp.media.frame.state( 'library' );
mediaLibraryTab.trigger( 'open' );

window.wp.media.frame.controller.browserView.collection.add( attachment );
addAttachment( attachment );

const selection = mediaLibraryTab.get( 'selection' );
selection.reset();
selection.add( [ attachment ] );
} else {
window.wp.media.frame.controller.browserView.collection.add( attachment );
addAttachment( attachment );
}

setIsUploading( false );
Expand Down

0 comments on commit cc6bb9f

Please sign in to comment.