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

Fix: Refactor Featured Image Block to use aspectRatio block support #61485

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

hbhalodia
Copy link
Contributor

@hbhalodia hbhalodia commented May 8, 2024

What?

Resolves #61432

Why?

  • To improve the code quality, we have removed the aspectRatio from attributes and used the Block Supports for the core/post-featured-image, because the attributes were redundant.

How?

  • Have removed the aspectRatio from the attributes.
  • Have added the block supports, dimensions[aspectRatio] in block.json.
  • Used that value to update the block in editor and frontend as well.

Testing Instructions

  1. Open a post/page.
  2. Added the core/post-featured-image block.
  3. Check the aspect ratio dropdown. It is now using the block supports, instead of native attributes.

Testing Instructions for Keyboard

  • NIL

Screenshots or screencast

  • NIL, code quality improvement.
Copy link

github-actions bot commented May 8, 2024

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @eric-michel.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: eric-michel.

Co-authored-by: hbhalodia <hbhalodia@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Block] Post Featured Image Affects the Post Featured Image Block labels May 8, 2024
@Mamaduka Mamaduka requested review from Mamaduka, abotteram and ajlende and removed request for juanmaguitar, ajitbohra, ryanwelcher, ndiego and abotteram May 8, 2024 12:02
@Mamaduka
Copy link
Member

Mamaduka commented May 8, 2024

I've not properly tested this, but I think the Featured Image won't retain the aspect ratio after the update.

  1. Set the aspect ratio for a featured image on the trunk. Save the post.
  2. Switch to this branch.
  3. See if the aspect ratio is still set.
@hbhalodia
Copy link
Contributor Author

hbhalodia commented May 9, 2024

I've not properly tested this, but I think the Featured Image won't retain the aspect ratio after the update.

  1. Set the aspect ratio for a featured image on the trunk. Save the post.
  2. Switch to this branch.
  3. See if the aspect ratio is still set.

Hi @Mamaduka, I tried the above steps and yes, the aspectRatio which is set is no more used. We need to make sure it is backward compatible, if aspectRatio is set, it should respect that, and if changed then we can use new one.

Let me know if you have some idea how can we proceed with that? I tried some findings but did not succeed. Maybe we should retain the attribute and check if that is set, use that, and once change it from block support make it undefined. I am not sure what could be the better approach.

Thank You.

@@ -80,6 +75,9 @@ const DimensionControls = ( {
label: name,
} ) );

// Get the block Supports aspect ratio.
const aspectRatio = attributes?.style?.dimensions?.aspectRatio;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const aspectRatio = attributes?.style?.dimensions?.aspectRatio;

Above line can be changed to something like,

const blockSupportAspectRatio = attributes?.style?.dimensions?.aspectRatio || aspectRatio;

Here we should not remove the attribute from the block itself, we just keep it to get the value which was stored previously?

But it would have issue like, blockSupport aspectRatio dropdown would not show the selected aspectRatio from the atttribute.

@eric-michel
Copy link

@hbhalodia can you confirm if this implementation of aspect-ratio will create an inline style even when an aspect-ratio is not selected? This happened with the Cover block and broke a lot of our sites. If this were to happen with the Group block, it would be catastrophic for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Featured Image Affects the Post Featured Image Block [Type] Enhancement A suggestion for improvement.
3 participants