Site editor: Add allowedMimeTypes to site editor settings to fix media upload behaviour and error state#30436
Merged
gziolo merged 1 commit intoApr 2, 2021
Conversation
gziolo
approved these changes
Apr 1, 2021
Member
There was a problem hiding this comment.
Looks good. I'm working on the solution that will expose the same setting to all versions of the editor, see WordPress/wordpress-develop#1118.
Contributor
Author
|
Excellent, thanks for approving @gziolo (the new API endpoint for editor settings sounds like a great idea, too)! Do you mind merging this one in for me? I don’t have access to do that yet 🙂 |
Contributor
Author
|
Thanks so much! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
In the
mediaUploadfunction (for example, used by the upload buttons in the Cover block), there is a check for the current allowed mime types (from the WordPress end), which is then fed into theuploadMediafunction which will trigger an error before attempting to upload the file (e.g. here is the error for mime type not allowed for user).However, currently in the new Site Editor, we're not loading the allowed mime types as part of the server rendered initial state, which means that the list allowed mime types passed in to uploadMedia is empty (
wpAllowedMimeTypes), resulting in the editor attempting to upload the file and then failing at the server end.This one-line change adds in
allowedMimeTypesto the server rendered initial state, using the same approach as is used for the post and page editors (from this line in core).The result after this change is that if a user uploads a file that isn't allowed (testing with an
svgfile is a convenient way to do it), then we report the error back to the user immediately (along with the filename), instead of displaying a flicker of the file attempting to be uploaded.How has this been tested?
Manually in the site editor. Add a cover block and attempt to upload an SVG image as the background image.
For testing, I used this image: https://upload.wikimedia.org/wikipedia/commons/2/20/WordPress_logo.svg
Screenshots
Types of changes
Bug fix
Checklist:
My code follows the accessibility standards.N/AI've tested my changes with keyboard and screen readers.N/AMy code has proper inline documentation.N/AI've included developer documentation if appropriate.N/AI've updated all React Native files affected by any refactorings/renamings in this PR (please manually search allN/A*.native.jsfiles for terms that need renaming or removal).