Skip to content

Site editor: Add allowedMimeTypes to site editor settings to fix media upload behaviour and error state#30436

Merged
gziolo merged 1 commit into
WordPress:trunkfrom
andrewserong:update/allowed-mime-types-check-in-site-editor
Apr 2, 2021
Merged

Site editor: Add allowedMimeTypes to site editor settings to fix media upload behaviour and error state#30436
gziolo merged 1 commit into
WordPress:trunkfrom
andrewserong:update/allowed-mime-types-check-in-site-editor

Conversation

@andrewserong
Copy link
Copy Markdown
Contributor

Description

In the mediaUpload function (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 the uploadMedia function 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 allowedMimeTypes to 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 svg file 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

Before After
media-upload-mime-types-before-sml media-upload-mime-types-after-sml

Types of changes

Bug fix

Checklist:

  • My code is tested. (Manually tested)
  • My code follows the WordPress code style.
  • My code follows the accessibility standards. N/A
  • I've tested my changes with keyboard and screen readers. N/A
  • My code has proper inline documentation. N/A
  • I've included developer documentation if appropriate. N/A
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal). N/A

Copy link
Copy Markdown
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

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.

@gziolo gziolo added [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Bug An existing feature does not function as intended labels Apr 1, 2021
@andrewserong
Copy link
Copy Markdown
Contributor Author

andrewserong commented Apr 1, 2021

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 🙂

@gziolo gziolo merged commit ed00137 into WordPress:trunk Apr 2, 2021
@github-actions github-actions Bot added this to the Gutenberg 10.4 milestone Apr 2, 2021
@andrewserong andrewserong deleted the update/allowed-mime-types-check-in-site-editor branch April 2, 2021 06:19
@andrewserong
Copy link
Copy Markdown
Contributor Author

Thanks so much!

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

Labels

[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants