-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix the latest-posts block when imageDimensions
is empty
#21070
Fix the latest-posts block when imageDimensions
is empty
#21070
Conversation
imageDimensions
is empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great change! I think the test failures are affecting all Gutenberg PRs at the moment.
At any rate, it's important for folks to remember that since image dimensions are filterable on the server, it's possible for any of them to be filtered out.
I don't think any of the bugs you noted in the PR are related to these changes since the block has been working in the "normal" case. This doesn't change any of that behavior.
@roo2 could you rebase to try to fix tests? (I can merge once everything passes) |
3148796
to
f7a751a
Compare
f7a751a
to
9217a2c
Compare
hey thanks for reminding me, yep the tests are passing now! :) |
Congratulations on your first merged pull request! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
Co-authored-by: roo2 <roo2@protonmail.com>
Co-authored-by: roo2 <roo2@protonmail.com>
Description
We found a bug when testing the Latest Posts block on WordPress.com that caused the block to fail to load: Automattic/wp-calypso#40127
There was a javascript crash caused by
imageDimensions
array having missing values for certain sizes that we try to access without a null check viaimageDimensions[featuredImageSizeSlug].height
This PR adds a null check and defaults the image size to 0 if not values are found in the
imageDimensions
array.How has this been tested?
I tested this by modifying
imageDimensions
to be empty. The Latest Posts block was then able to load, save, preview, etc.After applying this fix, I did notice that if you select the named percentage sizes: "25%, 50%, 75%, 100%" then the image's max-width is set to 0px. I'm not sure if that is related but it could be fixed in addition to this null check.
I also noticed that the Width and Height values that the user enters set
max-width
andmax-height
css properties. This means that only the lowest value of Width and Height is used, If this is deliberate, I think it should be communicated better to the user :)