|
69 | 69 | * @param {PipelineAttachment} attachment The finalized attachment from the pipeline. |
70 | 70 | */ |
71 | 71 | 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 } ); |
73 | 76 |
|
74 | 77 | // Register the model in Attachments.all (parity with wp-plupload.js). |
75 | 78 | wp.media.model.Attachment.get( attachment.id, model ); |
76 | 79 |
|
| 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 | + |
77 | 89 | model |
78 | 90 | .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 | | - } ) |
87 | 91 | .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. |
95 | 94 | model.set( attachment ); |
96 | | - model.set( { uploading: false } ); |
97 | 95 | } ) |
98 | 96 | .always( function () { |
99 | 97 | maybeResetQueue(); |
|
0 commit comments