-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Image Block: Correctly set image size slug #32364
Conversation
Size Change: +92 B (0%) Total Size: 1.03 MB
ℹ️ View Unchanged
|
Thank you George for fixing this bug! Before: Applying a GB special build of the plugin. PR works as mentioned. |
As this is a bug fix. I assume it can be backported to WP 5.8. I went ahead and added the Backport label. |
@gwwar Kerry can you take a look at this PR? |
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.
🤔 Is there anything else I need to do to make the named image size options appear? I don't see the drop down using 2021 or Armando theme.
Provided that "full" is a good fallback and supported by all themes, I think the code here looks reasonable.
One non-blocking note is that optional chaining could make sense here. This might look like:
const fallbackSize = 'full';
const imageUrl = image?.sizes?.defaultSize?.url;
const sourceUrl = image?.media_details?.sizes?.defaultSize?.source_url;
const sizeSlug = ( imageUrl || sourceUrl ) ?? fallbackSize;
Thanks for testing, @gwwar Are image sizes available in block editor? wp.data.select('core/block-editor').getSettings().imageSizes; I've also seen this happen if there're no image sizes generated for media. Usually, when the image is smaller than a thumbnail. See: gutenberg/packages/block-library/src/image/image.js Lines 162 to 167 in c9950a3
|
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.
Description
When default image size isn't available for uploaded media, the Image block uses a full-size image. But
sizeSlug
is still set for default. This causes incorrect image size selection inImageSizeControl
component.PR adds logic to fallback to 'full' size when default image size isn't available.
Fixes #27198.
How has this been tested?
Settings -> Media
. 1024x1024px by default.Types of changes
Bugfix
Checklist:
*.native.js
files for terms that need renaming or removal).