Skip to content

File: Keep the block's file when a Replace upload fails - #87094

Draft
SainathPoojary wants to merge 2 commits into
WordPress:trunkfrom
SainathPoojary:fix/file-block-failed-replace-upload
Draft

SainathPoojary wants to merge 2 commits into
WordPress:trunkfrom
SainathPoojary:fix/file-block-failed-replace-upload

Conversation

@SainathPoojary

Copy link
Copy Markdown
Member

What?

Closes #87093

When a Replace upload fails, the File block now keeps its current file. Reset still removes it.

Why?

Failed Replace upload removes the file and the block goes back to the empty placeholder. Image, Audio and Video already keep their media after a failed upload (#86290), File block has similar issue.

How?

  • On a failed upload, the block now clears only the blob attribute and the temporary URL. It used to clear href (rejected file) or every file attribute (server error).
  • Reset used the same handler as the server-error case, so it now has its own onResetFile(). It clears the file as before.
  • Adds e2e tests for a server error and a rejected file type.

Testing Instructions

  1. Add a File block to a post and upload any small file.
  2. Select the block, then choose Replace → Upload and pick a file the site does not allow, such as a .exe. An error notice appears and the file stays.
  3. Make the media upload fail with a server error. In the browser dev tools, open the Network tab and block the request URL /wp/v2/media, or use a local override that returns a 500. Then choose Replace → Upload and pick a normal file. An error notice appears and the file stays.
  4. Choose Replace → Reset. The block returns to the placeholder.
  5. Choose Replace → Upload with an allowed file. The file is replaced.
  6. In a new File block placeholder, drop a .exe file on it. The placeholder stays and the spinner stops.

Screenshots or screencast

Before

2026-11-19.18-00-06.mp4

After:

2026-11-19.17-53-15.mp4

Use of AI Tools

Claude Code (Claude Opus 5.5) helped with the code changes. Review and testing the changes was done by me

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

This branch has not been deployed

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

Labels

[Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File: A failed Replace upload removes the block's existing file

1 participant