Skip to content

Fix: Playlist: A failed Replace upload clears the track's title, artist, album, image and length - #86018

Merged
hbhalodia merged 5 commits into
WordPress:trunkfrom
hbhalodia:fix/issue-85951
Oct 30, 2026
Merged

hbhalodia merged 5 commits into
WordPress:trunkfrom
hbhalodia:fix/issue-85951

Conversation

@hbhalodia

Copy link
Copy Markdown
Contributor

What?

Closes #85951

When a Replace upload fails, the Playlist track now keeps its title, artist, album, image and length.

Why?

On a failed server-side upload, MediaReplaceFlow calls onSelect( undefined ), and onSelectTrack cleared every track attribute except src. The track lost its details in the editor, and because its id was cleared, it was also left out on the front end (#83857).

How?

  • When an upload fails, onSelectTrack now clears only blob and the temporary URL, and leaves the track's other attributes as they were.
  • The existing "replacement upload fails" unit test now checks that the update contains only blob. It uses toStrictEqual, because toEqual ignores keys set to undefined and would pass on the old code.

The change is needed because, when a client side media upload fails, it does not update anything and uses the previous attributes only, so the same should happen when server side uploads processing is available.

Testing Instructions

  1. Use server-side uploads. In the editor console, window.__clientSideMediaProcessing should be undefined. If it's true, add add_filter( 'wp_client_side_media_processing_enabled', '__return_false' ); to a mu-plugin.
  2. Insert a Playlist block and add a track from the Media Library that has a title, artist, album and image.
  3. In the editor console, run the snippet below. Media uploads then fail until you reload the page.
  4. Select the track, then choose Replace → Upload in the toolbar and pick any MP3.
  5. An upload error notice appears, and the track keeps its title, artist, album, image and length. On trunk, these are cleared.
  6. Save the post and view it. The track appears with its details. On trunk, it's missing.
  7. Run npm run test:unit -- packages/block-library/src/playlist-track/test/edit.jsdom.test.jsx.
wp.apiFetch.use( ( options, next ) => {
	if ( options.method === 'POST' && /^\/wp\/v2\/media(\?|$)/.test( options.path ?? '' ) ) {
		return Promise.reject( { code: 'simulated_failure', message: 'Simulated upload failure.' } );
	}
	return next( options );
} );

Testing Instructions for Keyboard

None

Screenshots or screencast

Screen.Recording.2026-10-29.at.8.11.38.PM.mov

Use of AI Tools

Used Claude Code (Claude Opus 5.5) to trace the cause and draft the fix, the test change, and this description. I reviewed and tested the changes myself.

@hbhalodia hbhalodia self-assigned this Oct 30, 2026
@hbhalodia hbhalodia added [Type] Bug An existing feature does not function as intended [Package] Block library /packages/block-library [Block] Playlist labels Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: hbhalodia <hbhalodia@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@hbhalodia
hbhalodia marked this pull request as ready for review October 30, 2026 05:19
@hbhalodia
hbhalodia requested a review from t-hamano October 30, 2026 05:20
@hbhalodia

hbhalodia commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @t-hamano, Apologies for a ping here. Could you please check or not sure who's the right person here, if that change was intentional or a miss?

IMO, the changes should not get removed if the media upload fails, just like how client side media processing does that, but server side media processing if failed, it clears all past attributes.

Just wanted to know your thoughts 🙇.

Ref: #85951 (comment)

@ramonjd

ramonjd commented Oct 30, 2026

Copy link
Copy Markdown
Member

Could you please check or not sure who's the right person here, if that change was intentional or a miss?

Maybe @carolinan or @scruffian would know? (I only looked at git blame)

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping.

Reading this comment, the agreement seems to be that the existing track should be kept when an upload fails. Given that, the approach in this PR makes sense to me.

// In this case there was an error and we should continue in the editing state
// previous attributes should be removed because they may be temporary blob urls.

This code comment is indeed confusing, but I think it was copied from the Audio block, which still has the same comment from its older implementation:

if ( ! media || ! media.url ) {
// In this case there was an error and we should continue in the editing state
// previous attributes should be removed because they may be temporary blob urls.
setAttributes( {
src: undefined,
id: undefined,
caption: undefined,
blob: undefined,
} );
setTemporaryURL();
return;
}

For reference, the Image, Audio and Video blocks reset their media-related attributes and go back to the placeholder state when an upload fails:

I think this is a leftover from when there was no local blob attribute, and the temporary blob URL was written directly into the src attribute during upload. These three blocks now handle blob URLs through the local blob attribute and temporaryURL, so if the only goal is to clean up blob URLs, resetting the blob attribute, as this PR does, should be enough. Whether to change the behavior of those three blocks is a separate discussion, though, and I think it's out of scope for this PR.

@hbhalodia

Copy link
Copy Markdown
Contributor Author

Thanks @t-hamano, For clearing the confusion here.

I agree other blocks is a separate discussion, I can create a followup ticket and we can continue on that.

Meanwhile the PR and Issue's scope is limited to the playlist block, and if PR is in good shape then we can plan to move forward with this, while creating a followup for three blocks as shared.

@hbhalodia
hbhalodia enabled auto-merge (squash) October 30, 2026 11:55
@hbhalodia
hbhalodia merged commit 6f46660 into WordPress:trunk Oct 30, 2026
80 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 30, 2026
@hbhalodia

Copy link
Copy Markdown
Contributor Author

For reference, the Image, Audio and Video blocks reset their media-related attributes and go back to the placeholder state when an upload fails:
Image block
Audio block
Video block
I think this is a leftover from when there was no local blob attribute, and the temporary blob URL was written directly into the src attribute during upload. These three blocks now handle blob URLs through the local blob attribute and temporaryURL, so if the only goal is to clean up blob URLs, resetting the blob attribute, as this PR does, should be enough. Whether to change the behavior of those three blocks is a separate discussion, though, and I think it's out of scope for this PR.

Created a followup ticket to fix the same here - #86289

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Playlist [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playlist: A failed Replace upload clears the track's title, artist, album, image and length

3 participants