Skip to content

Gallery block: Add full align gallery support and unit tests#2587

Open
mukeshpanchal27 wants to merge 3 commits into
fix/2449-equal-columnfrom
add/full-align-unit-tests
Open

Gallery block: Add full align gallery support and unit tests#2587
mukeshpanchal27 wants to merge 3 commits into
fix/2449-equal-columnfrom
add/full-align-unit-tests

Conversation

@mukeshpanchal27

Copy link
Copy Markdown
Member

Summary

Part of #2449

Treat child Image blocks of a full aligned Gallery as aligned, alongside the existing wide alignment handling. A full aligned gallery only spans the viewport when it has a single column, so multi-column galleries fall back to the default sizes.

Add unit tests covering full aligned galleries with equal and unequal column counts, the 'is_parent_aligned' render block context, and the Image block context declarations.

Use of AI Tools

N/A

@mukeshpanchal27 mukeshpanchal27 self-assigned this Jul 20, 2026
@mukeshpanchal27 mukeshpanchal27 added [Type] Enhancement A suggestion for improvement of an existing feature 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 Jul 20, 2026
@mukeshpanchal27
mukeshpanchal27 requested a review from Copilot July 20, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the Auto Sizes plugin’s Gallery handling so that child core/image blocks inside a full-aligned Gallery inherit alignment behavior (similar to existing wide-alignment support), and it adds unit tests to cover the new behavior and context plumbing.

Changes:

  • Treat core/gallery blocks with align: "full" as “parent aligned” so child core/image blocks can inherit alignment when they don’t explicitly set their own.
  • Add logic to fall back to default sizes for inherited full alignment when the gallery image is not effectively full-width (based on container_relative_width).
  • Add/extend unit tests for full-aligned galleries, is_parent_aligned render-block context, and core/image context usage declarations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
plugins/auto-sizes/includes/improve-calculate-sizes.php Adds full-aligned Gallery inheritance for child Images and a fallback to default sizes when full alignment shouldn’t apply.
plugins/auto-sizes/tests/test-improve-calculate-sizes.php Adds unit tests for full-aligned gallery scenarios and validates new/required render-block context behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/auto-sizes/includes/improve-calculate-sizes.php
Comment thread plugins/auto-sizes/tests/test-improve-calculate-sizes.php
Comment on lines +2163 to +2176
'Full gallery alignment, Default image alignment, 3 images (1 column)' => array(
'full',
'',
3,
1,
'sizes="100vw" ',
),
'Full gallery alignment, Default image alignment, 4 images (2 columns)' => array(
'full',
'',
4,
2,
'sizes="(max-width: 1024px) 100vw, 1024px" ',
),
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.50%. Comparing base (a4f79e2) to head (714535c).

Additional details and impacted files
@@                  Coverage Diff                   @@
##           fix/2449-equal-column    #2587   +/-   ##
======================================================
  Coverage                  70.50%   70.50%           
======================================================
  Files                         91       91           
  Lines                       7882     7884    +2     
======================================================
+ Hits                        5557     5559    +2     
  Misses                      2325     2325           
Flag Coverage Δ
multisite 70.50% <100.00%> (+<0.01%) ⬆️
single 35.87% <100.00%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

plugins/auto-sizes/tests/test-improve-calculate-sizes.php:2177

  • In the full-aligned, multi-column gallery case with an incomplete last row (remainder=1), the expected sizes for the last image is sizes="100vw", which contradicts the intent stated just above (that multi-column full galleries fall back to default sizes, including incomplete rows) and the PR description.

If multi-column full galleries should always use default sizes, the last image here should also use the default sizes string instead of 100vw.

				3,
				2,
				'sizes="(max-width: 1024px) 100vw, 1024px" ',
				'sizes="100vw" ',
			),

plugins/auto-sizes/includes/improve-calculate-sizes.php:141

  • The new early-return for inherited full alignment only checks container_relative_width !== 1.0. However, for a multi-column gallery’s incomplete last row where remainder=1, auto_sizes_filter_render_block_context() sets container_relative_width to 1.0 for that last image (it uses 1.0 / $remainder). This means the last image can still be treated as full and end up with sizes="100vw", even though the PR description says multi-column full-aligned galleries should fall back to default sizes.

If the intended behavior is “any gallery with column_count > 1 uses default sizes for all images”, consider passing the gallery column count (or a boolean like is_parent_multi_column) through block context to the child Image blocks and using that instead of relying solely on container_relative_width.

			$is_parent_gallery_aligned = (bool) ( $block->context['is_parent_aligned'] ?? false );
			if ( $is_parent_gallery_aligned && '' === $alignment ) {
				$alignment = $max_alignment;

				/*
				 * A full alignment normally spans the whole viewport, but inside a narrower
				 * container (e.g. a column) the gallery is constrained to that container instead.
				 * The resulting width cannot be expressed reliably here, so keep the default sizes.
				 */
				if ( 1.0 !== (float) $container_relative_width && 'full' === $alignment ) {
					return $sizes;

@mukeshpanchal27
mukeshpanchal27 marked this pull request as ready for review July 22, 2026 03:27
@github-actions

Copy link
Copy Markdown

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>

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants