Skip to content

Commit a6389c6

Browse files
Merge remote-tracking branch 'fork/add/media-library-client-side-uploads' into add/media-modal-client-side-uploads
2 parents 3fa59e3 + e133bd5 commit a6389c6

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

‎src/js/_enqueues/admin/media-frame-upload.js‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,29 @@
6969
* @param {PipelineAttachment} attachment The finalized attachment from the pipeline.
7070
*/
7171
function handleSuccess( wpUploader, model, attachment ) {
72-
model.set( { id: attachment.id }, { silent: true } );
72+
// Not silent: Attachments re-keys a model from its cid to its id when
73+
// it sees the change event. Without that the collection cannot find the
74+
// attachment by id, and refreshing the library duplicates its tile.
75+
model.set( { id: attachment.id } );
7376

7477
// Register the model in Attachments.all (parity with wp-plupload.js).
7578
wp.media.model.Attachment.get( attachment.id, model );
7679

80+
// Clear the uploading state before the refetch lands, not after. The
81+
// attachment details view re-renders on the refetch's changes, so it has
82+
// to see `uploading: false` by then or it keeps showing a progress bar.
83+
// wp-plupload.js sets both in one call for the same reason.
84+
[ 'file', 'loaded', 'size', 'percent' ].forEach( function ( key ) {
85+
model.unset( key, { silent: true } );
86+
} );
87+
model.set( { uploading: false }, { silent: true } );
88+
7789
model
7890
.fetch()
79-
.done( function () {
80-
[ 'file', 'loaded', 'size', 'percent' ].forEach( function (
81-
key
82-
) {
83-
model.unset( key, { silent: true } );
84-
} );
85-
model.set( { uploading: false } );
86-
} )
8791
.fail( function () {
88-
// Fetch failed, but the upload succeeded: clear the uploading
89-
// state with what the pipeline gave us so no tile is stuck.
90-
[ 'file', 'loaded', 'size', 'percent' ].forEach( function (
91-
key
92-
) {
93-
model.unset( key, { silent: true } );
94-
} );
92+
// Fetch failed, but the upload succeeded: fill the tile with what
93+
// the pipeline gave us so it is not left empty.
9594
model.set( attachment );
96-
model.set( { uploading: false } );
9795
} )
9896
.always( function () {
9997
maybeResetQueue();

0 commit comments

Comments
 (0)