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

Flex layout classes added incorrectly in deprecated gallery blocks. #48606

Closed
peterwilsoncc opened this issue Mar 1, 2023 · 1 comment · Fixed by #48611
Closed

Flex layout classes added incorrectly in deprecated gallery blocks. #48606

peterwilsoncc opened this issue Mar 1, 2023 · 1 comment · Fixed by #48611
Assignees
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Feature] Layout Layout block support, its UI controls, and style output. [Type] Bug An existing feature does not function as intended

Comments

@peterwilsoncc
Copy link
Contributor

Description

The layout parser is incorrectly adding the is-layout-flex classes to the deprecated gallery block formats.

I have not tested other blocks (current or deprecated) but I suspect it's happening elsewhere.

A post generated from the file /test/integration/fixtures/blocks/core__gallery__deprecated-2.html generates markup placing the is-layout-flex on the final image:

<ul class="wp-block-gallery columns-2 is-cropped alignwide wp-block-gallery-6">
	<li class="blocks-gallery-item">
		<figure>
			<img decoding="async" src="<!--snip-->" data-id="1" alt="title" class="wp-image-1" />
		</figure>
	</li>
	<li class="blocks-gallery-item">
		<figure>
			<img decoding="async" src="<!--snip-->" data-id="2" alt="title" class="wp-image-2 is-layout-flex" />
		</figure>
	</li>
</ul>

A similar issue occurs for posts containing deprecated versions 4 and 5 of the gallery block. As above, the class is added to the final image.

As the block editor will migrate deprecated versions of the HTML when you open it, you'll need to use WP-CLI to create any posts. See the reproduction steps.

I discovered this working on adding tests for the deprecated gallery formats in WP#55571. See the PR WordPress/wordpress-develop#4140

cc @tellthemachines as discussed.

Step-by-step reproduction instructions

  1. Create a post using WP-CLI from the root directory of this repo: wp post create ./test/integration/fixtures/blocks/core__gallery__deprecated-2.html --post_title="Deprecated Gallery Format: V2" --post_status=publish
  2. Do not open this post in the block editor.
  3. Visit the the post in your browser
  4. View source
  5. Observe the markup above with the incorrect class on the image.

Screenshots, screen recording, code snippet

Deprecated Gallery V4

Source: ./test/integration/fixtures/blocks/core__gallery__deprecated-4.html
Result:

<figure class="wp-block-gallery columns-3 is-cropped alignwide wp-block-gallery-6">
	<ul class="blocks-gallery-grid">
		<li class="blocks-gallery-item">
			<figure>
				<img decoding="async" src="https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190" alt="" data-id="1421" class="wp-image-1421"/>
			</figure>
		</li>
		<li class="blocks-gallery-item">
			<figure>
				<img decoding="async" src="https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580" alt="" data-id="1440" class="wp-image-1440"/>
			</figure>
		</li>
		<li class="blocks-gallery-item">
			<figure>
				<img decoding="async" src="https://sergioestevaofolio.files.wordpress.com/2017/05/cropped-l1005945-2-2.jpg?w=580" alt="" data-id="1362" class="wp-image-1362 is-layout-flex"/>
			</figure>
		</li>
	</ul>
</figure>

Deprecated Gallery V5

Source: ./test/integration/fixtures/blocks/core__gallery__deprecated-5.html
Result:

<figure class="wp-block-gallery columns-3 is-cropped wp-block-gallery-6">
	<ul class="blocks-gallery-grid">
		<li class="blocks-gallery-item">
			<figure>
				<a href="http://wptest.local/wp-content/uploads/2020/09/test-image-edited-1-scaled.jpg" >
					<img
						src="http://wptest.local/wp-content/uploads/2020/09/test-image-edited-1-682x1024.jpg"
						alt=""
						data-id="705"
						data-full-url="http://wptest.local/wp-content/uploads/2020/09/test-image-edited-1-scaled.jpg"
						data-link="http://wptest.local/classic/test-image-3/"
						class="wp-image-705"
					/>
				</a>
			</figure>
		</li>
		<li class="blocks-gallery-item">
			<figure>
				<a href="http://wptest.local/wp-content/uploads/2020/09/test-image-edited-scaled.jpg" >
					<img
						src="http://wptest.local/wp-content/uploads/2020/09/test-image-edited-1024x682.jpg"
						alt=""
						data-id="704"
						data-full-url="http://wptest.local/wp-content/uploads/2020/09/test-image-edited-scaled.jpg"
						data-link="http://wptest.local/test-image-2/"
						class="wp-image-704"
					/>
				</a>
			</figure>
		</li>
		<li class="blocks-gallery-item">
			<figure>
				<a href="http://wptest.local/wp-content/uploads/2020/04/test-image-scaled.jpg" >
					<img
						src="http://wptest.local/wp-content/uploads/2020/04/test-image-1024x683.jpg"
						alt=""
						data-id="703"
						data-full-url="http://wptest.local/wp-content/uploads/2020/04/test-image-scaled.jpg"
						data-link="http://wptest.local/test-image/"
						class="wp-image-703 is-layout-flex"
					/>
				</a>
			</figure>
		</li>
	</ul>
</figure>

Environment info

Note: This is reproducible in WordPress Trunk both with and without the Gutenberg plugin active.

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

@tellthemachines
Copy link
Contributor

I can reproduce this with Gallery block deprecations 2, 4, 5 and 6. It happens because in these older Gallery versions, the block didn't have inner blocks. The layout logic is looking for the inner block wrapper, which should be the innermost block with a classname attached, and it finds the last img instead.

This means it's unlikely the issue will happen with other deprecations, as afaik Gallery is the only layout-using core block that didn't start out as an inner block container.

@tellthemachines tellthemachines added [Type] Bug An existing feature does not function as intended [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Feature] Layout Layout block support, its UI controls, and style output. [Block] Gallery Affects the Gallery Block - used to display groups of images labels Mar 1, 2023
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Mar 1, 2023
pento pushed a commit to WordPress/wordpress-develop that referenced this issue Mar 1, 2023
Backport of WordPress/gutenberg#48606, which fixes an issue found in adding fixtures for deprecated Gallery block versions in #55571.

See #55571.
Fixes #57831.
Props isabel_brison, Mamaduka, dasnitesh780.




git-svn-id: https://develop.svn.wordpress.org/trunk@55439 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this issue Mar 1, 2023
Backport of WordPress/gutenberg#48606, which fixes an issue found in adding fixtures for deprecated Gallery block versions in #55571.

See #55571.
Fixes #57831.
Props isabel_brison, Mamaduka, dasnitesh780.



Built from https://develop.svn.wordpress.org/trunk@55439


git-svn-id: http://core.svn.wordpress.org/trunk@54972 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this issue Mar 1, 2023
Backport of WordPress/gutenberg#48606, which fixes an issue found in adding fixtures for deprecated Gallery block versions in #55571.

See #55571.
Fixes #57831.
Props isabel_brison, Mamaduka, dasnitesh780.



Built from https://develop.svn.wordpress.org/trunk@55439


git-svn-id: https://core.svn.wordpress.org/trunk@54972 1a063a9b-81f0-0310-95a4-ce76da25c4cd
VenusPR added a commit to VenusPR/Wordpress_Richard that referenced this issue Mar 9, 2023
Backport of WordPress/gutenberg#48606, which fixes an issue found in adding fixtures for deprecated Gallery block versions in #55571.

See #55571.
Fixes #57831.
Props isabel_brison, Mamaduka, dasnitesh780.



Built from https://develop.svn.wordpress.org/trunk@55439


git-svn-id: http://core.svn.wordpress.org/trunk@54972 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label May 11, 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 [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Feature] Layout Layout block support, its UI controls, and style output. [Type] Bug An existing feature does not function as intended
3 participants