Set error state when there is an upload error in during file upload #24017
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #23579
The app was hanging in an infinite loading state when file upload resulted in an error because of an unsupported file type. The problem was that in here
gutenberg/packages/media-utils/src/utils/upload-media.js
Lines 171 to 176 in 0a22d69
the uploaded file is not recognized but is considered to be a valid one. Next when
onFileChange
is called it runsgutenberg/packages/block-library/src/file/edit.js
Lines 90 to 100 in 0a22d69
which sets hasError state to false. At this point the server has not yet responded with an error, so the front-end shows a loader screen. Next the API call is made and
createMediaFromFile
throws.gutenberg/packages/media-utils/src/utils/upload-media.js
Lines 181 to 212 in 0a22d69
onError
runs but the state is never updated ingutenberg/packages/block-library/src/file/edit.js
Lines 102 to 106 in 0a22d69
How has this been tested?
Manually tested with a file with
.unsupported
extension.Screenshots
Types of changes
Bug fix (non-breaking change)
Checklist: