Skip to content

Enhanced Responsive Images: Account for Gallery and grid layouts in sizes calculation#2453

Open
meravi wants to merge 1 commit into
WordPress:trunkfrom
meravi:meravi-2449-enhanced-responsive-images-gallery
Open

Enhanced Responsive Images: Account for Gallery and grid layouts in sizes calculation#2453
meravi wants to merge 1 commit into
WordPress:trunkfrom
meravi:meravi-2449-enhanced-responsive-images-gallery

Conversation

@meravi
Copy link
Copy Markdown
Contributor

@meravi meravi commented Apr 21, 2026

Summary

Addresses #2449

Updates Enhanced Responsive Images so Gallery blocks and grid-style Group layouts propagate equal-width container constraints to child images for more accurate sizes attributes.

Technical Notes

  • added layout column-count/context propagation for Gallery and grid-style Group layouts
  • reused the existing container-relative sizing calculation for direct child image-like blocks
  • added PHPUnit coverage for Gallery and Group grid layouts
  • updated the Gallery test helper to serialize empty attributes like core block markup

Props: ravikhadka

@meravi meravi requested a review from mukeshpanchal27 as a code owner April 21, 2026 18:39
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

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: meravi <ravikhadka@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.44%. Comparing base (518db24) to head (d9353eb).
⚠️ Report is 2 commits behind head on trunk.

Files with missing lines Patch % Lines
...ns/auto-sizes/includes/improve-calculate-sizes.php 96.96% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2453      +/-   ##
==========================================
+ Coverage   69.33%   69.44%   +0.10%     
==========================================
  Files          90       90              
  Lines        7749     7779      +30     
==========================================
+ Hits         5373     5402      +29     
- Misses       2376     2377       +1     
Flag Coverage Δ
multisite 69.44% <96.96%> (+0.10%) ⬆️
single 35.96% <96.96%> (+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.
Copy link
Copy Markdown
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Just a couple quick drive-by suggestions. I haven't reviewed this otherwise, and I'm not really very familiar with how it works.

* @return array<string, mixed> Modified block context.
*/
function auto_sizes_inherit_parent_layout_width( array $context, WP_Block $parent_block ): array {
$column_count = isset( $parent_block->context['column_count'] ) ? (int) $parent_block->context['column_count'] : 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
$column_count = isset( $parent_block->context['column_count'] ) ? (int) $parent_block->context['column_count'] : 0;
$column_count = (int) ( $parent_block->context['column_count'] ?? 0 );
isset( $block['attrs']['layout']['type'] ) &&
'grid' === $block['attrs']['layout']['type']
) {
$column_count = isset( $block['attrs']['layout']['columnCount'] ) ? (int) $block['attrs']['layout']['columnCount'] : 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
$column_count = isset( $block['attrs']['layout']['columnCount'] ) ? (int) $block['attrs']['layout']['columnCount'] : 0;
$column_count = (int) ( $block['attrs']['layout']['columnCount'] ?? 0 );
}

if ( 'core/gallery' === $block['blockName'] ) {
$column_count = isset( $block['attrs']['columns'] ) ? (int) $block['attrs']['columns'] : 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
$column_count = isset( $block['attrs']['columns'] ) ? (int) $block['attrs']['columns'] : 0;
$column_count = (int) ( $block['attrs']['columns'] ?? 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants