Fix: Preserve aspectRatio and scale when switching to wide/full align…#76914
Conversation
…ment in Image block
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @adithya-naik! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
|
Hi @ajitbohra and @fabiankaegy 👋 Following up on this PR. The fix ensures that aspectRatio and scale are preserved when switching alignment, without affecting existing behavior. All checks are passing. Happy to make any updates if needed—would love your review when you have time. Thanks! |
|
Hi @mikachan, This is just a follow up remainder on this PR |
mikachan
left a comment
There was a problem hiding this comment.
Thanks @adithya-naik! This fixes the issue for me, and the testing instructions work as described 🙌

What?
Fixes a bug where the
aspectRatioandscaleattributes of the Image Blockare reset to
undefinedwhen switching alignment to Wide Width or Full Width.Fixes #76697
Why?
A
useEffectinedit.jswas introduced in #55954 to clearwidthandheightpixel dimensions when switching towideorfullalignment —which is correct, since explicit pixel dimensions conflict with the 100%
container width those alignments apply.
However, the same effect was also clearing
aspectRatioandscale. Theseare CSS-based attributes (
aspect-ratioandobject-fit) that are fullycompatible with wide/full alignment and should not be affected by the
alignment change.
How?
Removed
aspectRatio: undefinedandscale: undefinedfrom thesetAttributescall inside the
useEffectthat fires onwide/fullalignment changes.Only
widthandheight(inline pixel dimensions) are now cleared,preserving the CSS-based aspect ratio and object-fit scale behavior.
Before:
After:
Testing Instructions
Screenshots or screencast
As videos are larger than 10MB, uploaded into drive and gave public access
https://drive.google.com/drive/folders/1R6Stkc4lsDSjUBT6Mj2IQ7Zg2cuFOmfO?usp=sharing