Skip to content

Gallery Block: Fix equal column gallery image sizes#2534

Open
mukeshpanchal27 wants to merge 43 commits into
feature/2449-gallery-blockfrom
fix/2449-equal-column
Open

Gallery Block: Fix equal column gallery image sizes#2534
mukeshpanchal27 wants to merge 43 commits into
feature/2449-gallery-blockfrom
fix/2449-equal-column

Conversation

@mukeshpanchal27

@mukeshpanchal27 mukeshpanchal27 commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

Part of #2449

Relevant Technical Choices

Ensure that the number of images added matches the Gallery block's configured column count.

How to Test

  1. Add a Gallery block.
  2. Insert 3 images and make sure the Columns setting is set to 3.
  3. Verify that the image sizes.
  4. Repeat the test with 6 images while keeping the Columns setting at 3.
  5. Verify that the image sizes.

Before

Screenshot 2026-06-12 at 10 30 24 AM

After

Screenshot 2026-06-12 at 10 29 45 AM

In follow-up PR will fix the sizes for other column settings.

  • Add unit tests

Use of AI Tools

N/A

@mukeshpanchal27 mukeshpanchal27 self-assigned this Jun 12, 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 Jun 12, 2026
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.50%. Comparing base (726398d) to head (a4f79e2).
⚠️ Report is 1 commits behind head on feature/2449-gallery-block.

Additional details and impacted files
@@                      Coverage Diff                       @@
##           feature/2449-gallery-block    #2534      +/-   ##
==============================================================
+ Coverage                       70.38%   70.50%   +0.12%     
==============================================================
  Files                              91       91              
  Lines                            7850     7882      +32     
==============================================================
+ Hits                             5525     5557      +32     
  Misses                           2325     2325              
Flag Coverage Δ
multisite 70.50% <100.00%> (+0.12%) ⬆️
single 35.85% <100.00%> (+0.26%) ⬆️

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.

@mukeshpanchal27

Copy link
Copy Markdown
Member Author

@westonruter I'd appreciate any initial feedback you can provide on the PR when you have a chance to take a look.

@adamsilverstein

Copy link
Copy Markdown
Member

pr makes sense to me, it would be good to add some tests that demonstrate what it achieves.

@westonruter

Copy link
Copy Markdown
Member

@mukeshpanchal27 How does this handle the responsive layout? If I add a Gallery with three columns I have this on desktop:

image

But on mobile it becomes 2 columns, and the third image is twice as wide as the first two:

image

There would seem to need to be some logic add this breakpoint in sizes, where if there is an odd number of images, the last one would get a 100vw width.

@mukeshpanchal27

Copy link
Copy Markdown
Member Author

@westonruter In 46bfea1 i set two column layout for mobile explicitly.

In follow-up PR will fix issue for different columns.

}

if ( 'core/gallery' === $block['blockName'] ) {
if ( wp_is_mobile() ) {

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.

We can't rely on wp_is_mobile(), unfortunately. Page caching may not vary responses by device form factor. We'll need a solution that serves the same markup to all devices (the promise of responsive design).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can we tackle that in a follow-up PR?

On mobile/responsive layouts with screen widths below 600px, it currently becomes a two-column layout. Since that appears to be a separate issue, I think it would be better to address it in a dedicated follow-up PR.

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.

I don't think we can tackle in a follow-up, because this is a fundamental design decision or how this feature works. If we can't implement it using responsive design tools, then it won't be viable to ship.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. Currently, I'm pushing all PRs to the feature/2449-gallery-block feature branch, where all related changes are being gathered.

Once all issues are resolved, we'll open a final PR to merge into trunk. So the release will not be published until all identified issues have been addressed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It will be tackle in #2551

@mukeshpanchal27
mukeshpanchal27 marked this pull request as ready for review June 26, 2026 04:52
@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>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>

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

@github-actions github-actions Bot removed the props-bot Manually runs the Props Bot to update the contributor list. label Jul 3, 2026

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 4 comments.

Comment thread plugins/auto-sizes/includes/improve-calculate-sizes.php Outdated
Comment thread plugins/auto-sizes/includes/improve-calculate-sizes.php Outdated
Comment thread plugins/auto-sizes/includes/improve-calculate-sizes.php Outdated
Comment thread plugins/auto-sizes/tests/test-improve-calculate-sizes.php Outdated

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 1 comment.

Comment thread plugins/auto-sizes/includes/improve-calculate-sizes.php Outdated
Comment thread plugins/auto-sizes/includes/improve-calculate-sizes.php Outdated
@westonruter

Copy link
Copy Markdown
Member

Ensure that the number of images added matches the Gallery block's configured column count.

Is there a plan to deal with this? If I add 3 images to a gallery that has 2 columns:

image

All of the images have sizes="(max-width: 322px) 100vw, 322px". In reality, the last image should have sizes="(max-width: 645px) 100vw, 645px".

Comment thread plugins/auto-sizes/includes/improve-calculate-sizes.php Outdated

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.

Review of tests from Claude Opus 4.8:

The test name and data-provider name are misleading, and the primary feature is untested.

  • test_gallery_block_with_explicitly_columns_set / data_gallery_block_with_explicitly_columns_set claim to test explicit columns, but get_gallery_block_markup() never sets a columns attribute — it only sets linkTo and align. So every case exercises the fallback branch (line 370–371, inner-block count capped at 3), and the explicit-columns branch (lines 361–362) — the actual headline feature — has zero coverage.
  • A regression there would go unnoticed. The most valuable missing case: a gallery with columns set to a value that differs from the image count, e.g. columns=2 with 6 images should yield 310px, and columns=4 should exercise a value above the fallback cap of 3. Please add explicit-columns cases (and rename the test to match what it actually asserts, or split into two tests).
  • The $ancestor_block_alignment / $image_block_alignment parameters are threaded through but only ever ''. Either drop them or add wide/full alignment cases (galleries can be aligned, and alignment interacts with container_relative_width).

Recommendation: Approve after addressing the test gap — add explicit-columns cases (including a value above the fallback cap and one differing from image count) and rename the misleading test. The redundant guards and style nit are optional cleanups.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I updated the test and data-provider name.

The $ancestor_block_alignment / $image_block_alignment parameters are threaded through but only ever ''. Either drop them or add wide/full alignment cases (galleries can be aligned, and alignment interacts with container_relative_width).

I will add tests in follow-up PR. As it needs some adjustments.

@westonruter

Copy link
Copy Markdown
Member

Is there a plan to deal with this? If I add 3 images to a gallery that has 2 columns:

Oh, this is what #2543 is for?

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.

4 participants