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

Latest Posts block breaks when there are no intermediate image sizes #21582

Closed
WPprodigy opened this issue Apr 14, 2020 · 2 comments
Closed

Latest Posts block breaks when there are no intermediate image sizes #21582

WPprodigy opened this issue Apr 14, 2020 · 2 comments
Labels
[Type] Bug An existing feature does not function as intended

Comments

@WPprodigy
Copy link
Contributor

WPprodigy commented Apr 14, 2020

Description

The "Latest Post" block is not usable if a site has disabled all intermediate image sizes.

To reproduce

Steps to reproduce the behavior:

  1. Add add_filter( 'intermediate_image_sizes', '__return_empty_array' ); to your theme's functions.php
  2. Create a new post & add the "Latest Posts" block.
  3. Note the broken block: "This block has encountered an error and cannot be previewed."

What's happening

Error: An error occurred while running 'mapSelect': Cannot read property 'width' of undefined
The error may be correlated with this previous error:
TypeError: Cannot read property 'width' of undefined
    at https://vip.test/wp-includes/js/dist/block-library.min.js?ver=f710d3cc99e7a55a0d6a5418f3cfe33c:9:209846

The noted error happens here:

defaultImageWidth: imageDimensions[ featuredImageSizeSlug ].width,

Can replicate pretty easily with just this in the console:

const { getSettings } = wp.data.select( 'core/block-editor' );
const { imageSizes, imageDimensions } = getSettings();

// Is empty
imageDimensions

Editor version

  • WordPress version: 5.4
  • Core WP version of GB, not the extra plugin.
@jasmussen jasmussen added the [Type] Bug An existing feature does not function as intended label Apr 16, 2020
@Chrico
Copy link
Contributor

Chrico commented Apr 17, 2020

I want to extend this issue with some more information.


imageDimensions
The imageDimensions are set via localized script data here:

if ( ! isset( $settings['imageDimensions'] ) && ! empty( $settings['imageSizes'] ) ) {

--> Which means: They can actually be empty / contain no value at all.


defaults
The SETTINGS_DEFAULTS are not containing imageDimensions as well https://github.com/WordPress/gutenberg/blob/2a5146f6a078ae4ebfb9b0b806daac17674e7a95/packages/block-editor/src/store/defaults.js

--> No fallback forimageDimensions in JavaScript.


For me it looks like a Bug in Gutenberg itself to rely on data which is not ensured via a default in JavaScript and is not localized when set.

The latest-posts-Block should be updated in a way, which does only use images when at least 1 imageDimension is set. Otherwhise the "image"-option shouldn't be visible at all.

@WPprodigy
Copy link
Contributor Author

Oh, I missed #21070. This can be closed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants