WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#29689 closed defect (bug) (fixed)

Drag-and-drop media upload fails if the Media Library has already been opened and closed manually

Reported by: cfinke Owned by: wonderboymusic
Milestone: 4.1 Priority: normal
Severity: normal Version: 4.1
Component: Media Keywords: needs-patch
Focuses: javascript Cc:

Description

What I Did

  1. Created a new post by visiting wp-admin/post-new.php
  2. Clicked the "Add Media" button.
  3. Closed the Media Library by clicking on the "X" in the top right corner.
  4. Dragged and dropped an image file from my desktop into the editor.

What I Expected

That the image file would upload and appear in the Media Library.

What Happened

The Media Library overlay opened, but no upload occurred.

Notes

This bug only affects the first attempt during any given pageload to upload via drag-and-drop into the editor after the Media Library has been opened. Subsequent drag-and-drop uploads completed without issue.

Dragging and dropping into the Media Library is not affected, just into the editor.

Browsers: Firefox 32 and 33 on Mac OS X 10.9.4

Reproduced in WordPress 4.0 and today's nightly build with no plugins active.

Change History (4)

#1 @lucasartoni
3 years ago

I reproduced it on 4.0 and trunk.

#2 @wonderboymusic
3 years ago

  • Focuses javascript added
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.1

Reproduced.

#3 @danielpataki
3 years ago

I've figured out where the issue is but I am less of a Javascript ninja than I should be so if someone would lend a hand that would be great!

In wp-includes/js/media-views.js, in the drop function in media.view.EditorUploader if there is no workflow set the workflow is created. Once created the image is added like this:

this.workflow.on( 'uploader:ready', this.addFiles, this );

If this is replaced by the following it works just fine:

this.addFiles.apply( this );

Since I am not too familiar with these parts of WordPress I am worried that the listener is there for a reason. Some debugging suggests that there is no need for this listener but I am definitely not sure.

In addition, I don't know if the other workflow methods need to be used. If yes, the whole section could be simplified like so:

if ( ! this.workflow ) {
	this.workflow = wp.media.editor.open( 'content', {
		frame:    'post',
		state:    'insert',
		title:    wp.media.view.l10n.addMedia,
		multiple: true
	});
this.workflow.state().reset();
this.addFiles.apply( this );
this.workflow.open();

I am not submitting a patch at the moment since I'm not sure which route is correct. Perhaps somewhere the ready event isn't being triggered even though it should?

#4 @wonderboymusic
3 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 29917:

In wp.Uploader, when uploader:ready is triggered, set ready to true on the instance. This allows media workflows to check for an existing uploaded instance when opening.

Without this check, workflows might wait for uploader:ready, which could already have been fired. This would result in an unresponsive editor dropzone.

Fixes #29689.

Note: See TracTickets for help on using tickets.