Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaPlaceholder component errors when allowedTypes is not set. #11692

Closed
kadamwhite opened this issue Nov 9, 2018 · 0 comments · Fixed by #11694
Closed

MediaPlaceholder component errors when allowedTypes is not set. #11692

kadamwhite opened this issue Nov 9, 2018 · 0 comments · Fixed by #11694
Assignees
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Bug An existing feature does not function as intended
Milestone

Comments

@kadamwhite
Copy link
Contributor

Describe the bug

When the MediaPlaceholder component is used and no allowedTypes property is provided, the component throws an error because it tries to access .length on an undefined value.

To Reproduce

  1. Create a custom block with the edit() method
  2. Attempt to insert your custom block into the editor
  3. Observe "The block has encountered an error and cannot be previewed" message.
  4. Observe a TypeError: Cannot read property 'length' of undefined in the console.

Expected behavior
The MediaUpload component specifies that allowedTypes an optional property; I would therefore expect MediaPlaceholder to behave the same, especially given that there is already code to check whether allowedTypes is unset elsewhere in MediaPlaceholder.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Ubuntu 18.04 / Chrome 70

Additional context

  • Gutenberg version: master
kadamwhite added a commit that referenced this issue Nov 9, 2018
… prop exists

Fixes #11692

Adds basic unit test to demonstrate the bug described in #11692.
@ocean90 ocean90 added [Type] Bug An existing feature does not function as intended [Feature] Media Anything that impacts the experience of managing media labels Nov 10, 2018
@ocean90 ocean90 added this to the 4.4 milestone Nov 10, 2018
youknowriad pushed a commit that referenced this issue Nov 13, 2018
…11694)

* Only check MediaPlaceholder allowedTypes array length if allowedTypes prop exists

Fixes #11692

Adds basic unit test to demonstrate the bug described in #11692.

* Initialize allowedTypes to [] instead of modifying conditional

* Reinstate array length check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants