Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Accurate sizes: Get accurate sizes base on ancestor block context #1818

Open
wants to merge 13 commits into
base: add/ancestor-block-context
Choose a base branch
from

Conversation

mukeshpanchal27
Copy link
Member

Summary

See #1511

@mukeshpanchal27 mukeshpanchal27 added [Type] Feature A new feature within an existing module no milestone PRs that do not have a defined milestone for release [Plugin] Enhanced Responsive Images Issues for the Enhanced Responsive Images plugin (formerly Auto Sizes) labels Jan 22, 2025
@mukeshpanchal27 mukeshpanchal27 self-assigned this Jan 22, 2025
Copy link

codecov bot commented Jan 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.59%. Comparing base (7757e50) to head (454c669).

Additional details and impacted files
@@                      Coverage Diff                       @@
##           add/ancestor-block-context    #1818      +/-   ##
==============================================================
+ Coverage                       69.41%   69.59%   +0.18%     
==============================================================
  Files                              86       86              
  Lines                            7006     7018      +12     
==============================================================
+ Hits                             4863     4884      +21     
+ Misses                           2143     2134       -9     
Flag Coverage Δ
multisite 69.59% <100.00%> (+0.18%) ⬆️
single 39.66% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mukeshpanchal27
Copy link
Member Author

@joemcgill This one ready for your review.

@mukeshpanchal27
Copy link
Member Author

The PR is ready for internal review.

@mukeshpanchal27 mukeshpanchal27 marked this pull request as ready for review March 26, 2025 05:25
Copy link

github-actions bot commented Mar 26, 2025

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.

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

Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>

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

@swissspidy
Copy link
Member

What‘s with the failing tests?

@mukeshpanchal27
Copy link
Member Author

What‘s with the failing tests?

In 3a51aed it will skip failed tests for WordPress versions lower than 6.8

*
* @return array<string, array<int, string>> The ancestor and image alignments.
*/
public function data_image_block_with_parent_columns_and_its_parent_group_block(): array {
Copy link
Member

Choose a reason for hiding this comment

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

Each of the tests has the exact same sizes attribute: sizes="(max-width: 413px) 100vw, 413px".

Is this expected?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is expected as it end up to the default alignment any of it's parents or image alignment as default alignment. In bba4997, I added more variations of alignment options.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@mukeshpanchal27 This looks really good, just a few questions.

// Convert to float for better precision.
$layout_width = (float) $layout_width * $container_relative_width;
$layout_width = sprintf( '%dpx', (int) $layout_width );
}
Copy link
Member

Choose a reason for hiding this comment

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

Curious: Why does the wide alignment not take into consideration the image's own width, but left, right, center, and default do?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because when we set the wide alignment option for the image block, it does not allow setting the Width and Height options for the image. So, we don't need to consider that option for wide alignment.

// First remove 'px' from width.
$layout_width = str_replace( 'px', '', $layout_width );
// Convert to float for better precision.
$layout_width = (float) $layout_width * $container_relative_width;
$layout_width = sprintf( '%dpx', min( (int) $layout_width, $image_width ) );
} else {
$layout_width = sprintf( 'min(%1$s, %2$spx)', $layout_width, $image_width );
Copy link
Member

Choose a reason for hiding this comment

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

Is it allowed to have relative values like % in the sizes attribute? Or what is the rationale for having this min() value here?

Copy link
Member Author

Choose a reason for hiding this comment

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

See #1737 for context why it was added.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
no milestone PRs that do not have a defined milestone for release [Plugin] Enhanced Responsive Images Issues for the Enhanced Responsive Images plugin (formerly Auto Sizes) [Type] Feature A new feature within an existing module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants