-
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
Fix a bug that caused the display ratio of images to be corrupted starting from 6.3.( fix #53555 ) #53598
base: trunk
Are you sure you want to change the base?
Conversation
Warning: Type of PR label error To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. |
@scruffian Since you reviewed the similar #53274, could we get your eyes on this one, too? |
@MaggieCabrera Is this what we observed with our testing earlier this week when that one image didn't show the controls? |
It could be happening that after we use "Replace" on an existing image (this is the code for the original image in TT4) the dimensions are added to the block and that makes aspect ratio fail |
// Note that only width may be "auto". | ||
if ( ! aspectRatio && height && width && 'auto' !== width ) { |
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.
height
can be set to auto
in the editor with a fixed width
, so we can't make this assumption here. We want to support layouts where that is required.
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.
If migrate
needs to be added to all these deprecations, that seems to me like a bug in applyBlockDeprecatedVersions
, not the image block deprecations. The documentation for block deprecations doesn't mention this, and it seems rather awkward and error-prone to have to add them everywhere.
const w = parseInt( width ); | ||
const h = parseInt( height ); |
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.
The idea for the image block moving forward is to support units other than px
, so we don't want to parseInt
without confirming that they are pixel values first.
if ( ! aspectRatio && height && width && 'auto' !== width ) { | ||
const w = parseInt( width ); | ||
const h = parseInt( height ); | ||
if ( ! isNaN( w ) && ! isNaN( h ) ) { | ||
imgStyle.aspectRatio = `${ w }/${ h }`; | ||
} | ||
} else { | ||
if ( 'string' === typeof width ) imgStyle.width = width; | ||
if ( 'string' === typeof height ) imgStyle.height = height; | ||
} |
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.
The logic here should be moved to edit.js
to allow for more flexibility of styling.
What?
Since 6.3, there is a bug that the display ratio is broken when the size is specified in the image block. (#53555)
This PR fixes the above problem.
How?
If both
width
andheight
have size specifications, they are converted toaspect-ratio
rather than being output as they are in thestyle
attribute.Testing Instructions
As an example, I share one image block code I installed in 6.2.
Note
There was already a PR for 53274 that fixes another problem, which was already different from the 6.3 situation.
The 53274 changed the
width
,height
to astring
type, but blocks placed before 6.2 were not migrated correctly to astring
type, so we are fixing those as well.(In
deprecated.js
,migrate
process was also added tov6
~v4
)