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

Gallery block markup/metadata is not updated when images are removed #55232

Open
cbirdsong opened this issue Oct 10, 2023 · 3 comments
Open

Gallery block markup/metadata is not updated when images are removed #55232

cbirdsong opened this issue Oct 10, 2023 · 3 comments
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended

Comments

@cbirdsong
Copy link

cbirdsong commented Oct 10, 2023

Description

The gallery block does not update its markup when images are removed.

Step-by-step reproduction instructions

  1. Add a gallery block with multiple images.
  2. Adjust the number of columns away from the default.
  3. Duplicate it and remove one of the images
  4. Inspect the markup in the front end or the markup and block metadata in the code view of the editor.

Screenshots, screen recording, code snippet

<!-- Original gallery with two images: -->

<!-- wp:gallery {"columns":2,"linkTo":"none"} -->
<figure class="wp-block-gallery has-nested-images columns-2 is-cropped"><!-- wp:image {"id":56,"aspectRatio":"1","scale":"cover","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="http://stock.local/wp-content/uploads/2022/01/761eb638-10a7-3784-957b-51c63c28c58c-1024x683.jpg" alt="" class="wp-image-56" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image -->

<!-- wp:image {"id":56,"aspectRatio":"1","scale":"cover","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="http://stock.local/wp-content/uploads/2022/01/761eb638-10a7-3784-957b-51c63c28c58c-1024x683.jpg" alt="" class="wp-image-56" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image --></figure>
<!-- /wp:gallery -->

<!-- Duplicated gallery with one image deleted: -->

<!-- wp:gallery {"columns":2,"linkTo":"none"} -->
<figure class="wp-block-gallery has-nested-images columns-2 is-cropped"><!-- wp:image {"id":56,"aspectRatio":"1","scale":"cover","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="http://stock.local/wp-content/uploads/2022/01/761eb638-10a7-3784-957b-51c63c28c58c-1024x683.jpg" alt="" class="wp-image-56" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image --></figure>
<!-- /wp:gallery -->

Notice the "columns":2 and columns-2 class.

Environment info

  • Latest version of Wordpress, not using the plugin

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@jordesign jordesign added [Type] Bug An existing feature does not function as intended Needs Testing Needs further testing to be confirmed. [Block] Gallery Affects the Gallery Block - used to display groups of images labels Oct 11, 2023
@cbirdsong
Copy link
Author

Additional issue I found:

When you create a gallery, it gets the class "columns-default" and has no "columns" key even if it has multiple images.

<!-- wp:gallery {"linkTo":"none"} -->
<figure class="wp-block-gallery has-nested-images columns-default is-cropped"><!-- wp:image {"id":56,"aspectRatio":"1","scale":"cover","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="http://stock.local/wp-content/uploads/2022/01/761eb638-10a7-3784-957b-51c63c28c58c-1024x683.jpg" alt="" class="wp-image-56" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image -->

<!-- wp:image {"id":56,"aspectRatio":"1","scale":"cover","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="http://stock.local/wp-content/uploads/2022/01/761eb638-10a7-3784-957b-51c63c28c58c-1024x683.jpg" alt="" class="wp-image-56" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image --></figure>
<!-- /wp:gallery -->

If I change this gallery to 1 column and then set it back to 2 then this is the resulting markup:

<!-- wp:gallery {"columns":2,"linkTo":"none"} -->
<figure class="wp-block-gallery has-nested-images columns-2 is-cropped"><!-- wp:image {"id":56,"aspectRatio":"1","scale":"cover","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="http://stock.local/wp-content/uploads/2022/01/761eb638-10a7-3784-957b-51c63c28c58c-1024x683.jpg" alt="" class="wp-image-56" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image -->

<!-- wp:image {"id":56,"aspectRatio":"1","scale":"cover","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="http://stock.local/wp-content/uploads/2022/01/761eb638-10a7-3784-957b-51c63c28c58c-1024x683.jpg" alt="" class="wp-image-56" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image --></figure>
<!-- /wp:gallery -->

This now has a columns-2 class and "columns" key even though the content and appearance in the editor is identical. This kind of inconsistency makes it really hard to style.

Copy link

Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Nov 24, 2023
@cbirdsong
Copy link
Author

I've just confirmed this is still an issue under 6.4.1.

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended
2 participants