-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Editor: Fix link color CSS cascade conflict for duplicate blocks with identical markup #12126
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
3d7c9d2
e508d12
b243a62
f457038
51313d8
64124d0
78388e7
4e0f35c
f944d13
1cc2938
bcfe0eb
24971a3
e40c491
939ca1b
012f1f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,62 @@ public function test_elements_block_support_styles( $color_settings, $elements_s | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that identical blocks with different elements styles | ||
| * generate distinct class names to avoid CSS cascade conflicts. | ||
| * | ||
| * @ticket 65435 | ||
| * | ||
| * @covers ::wp_get_elements_class_name | ||
| */ | ||
| public function test_elements_block_support_styles_with_duplicate_blocks(): void { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this test? Is it not the same as in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is almost the same, but they test different outputs. the so something like |
||
| $this->test_block_name = 'test/element-block-supports'; | ||
|
|
||
| register_block_type( | ||
| $this->test_block_name, | ||
| array( | ||
| 'api_version' => 3, | ||
| 'attributes' => array( | ||
| 'style' => array( | ||
| 'type' => 'object', | ||
| ), | ||
| ), | ||
| 'supports' => array( | ||
| 'color' => array( | ||
| 'link' => true, | ||
| ), | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $block = array( | ||
| 'blockName' => $this->test_block_name, | ||
| 'attrs' => array( | ||
| 'style' => array( | ||
| 'elements' => array( | ||
| 'link' => array( | ||
| 'color' => array( | ||
| 'text' => 'blue', | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| // Process two identical blocks with the same elements styles. | ||
| $count = 2; | ||
| for ( $i = 0; $i < $count; $i++ ) { | ||
| wp_render_elements_support_styles( $block ); | ||
| } | ||
| $actual_stylesheet = wp_style_engine_get_stylesheet_from_context( 'block-supports', array( 'prettify' => false ) ); | ||
|
|
||
| // Count the number of distinct class names to confirm uniqueness. | ||
| $this->assertSame( $count, preg_match_all( '/\.wp-elements-([a-f0-9]{32}[0-9]+)/', $actual_stylesheet, $matches ) ); | ||
| $unique_classes = array_unique( $matches[1] ); | ||
| $this->assertCount( $count, $unique_classes, 'Both blocks should produce distinct class names' ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
|
|
@@ -127,7 +183,7 @@ public function data_elements_block_support_styles() { | |
| 'elements_styles' => array( | ||
| 'button' => array( 'color' => $color_styles ), | ||
| ), | ||
| 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} .wp-element-button, .wp-elements-[a-f0-9]{32} .wp-block-button__link' . $color_css_rules . '$/', | ||
| 'expected_styles' => '/^.wp-elements-[a-f0-9]{32}[0-9]+ .wp-element-button, .wp-elements-[a-f0-9]{32}[0-9]+ .wp-block-button__link' . $color_css_rules . '$/', | ||
| ), | ||
| 'link element styles are applied' => array( | ||
| 'color_settings' => array( 'link' => true ), | ||
|
|
@@ -139,15 +195,15 @@ public function data_elements_block_support_styles() { | |
| ), | ||
| ), | ||
| ), | ||
| 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} a:where\(:not\(.wp-element-button\)\)' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32} a:where\(:not\(.wp-element-button\)\):hover' . $color_css_rules . '$/', | ||
| 'expected_styles' => '/^.wp-elements-[a-f0-9]{32}[0-9]+ a:where\(:not\(.wp-element-button\)\)' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32}[0-9]+ a:where\(:not\(.wp-element-button\)\):hover' . $color_css_rules . '$/', | ||
| ), | ||
| 'generic heading element styles are applied' => array( | ||
| 'color_settings' => array( 'heading' => true ), | ||
| 'elements_styles' => array( | ||
| 'heading' => array( 'color' => $color_styles ), | ||
| ), | ||
| 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} h1, .wp-elements-[a-f0-9]{32} h2, .wp-elements-[a-f0-9]{32} h3, .wp-elements-[a-f0-9]{32} h4, .wp-elements-[a-f0-9]{32} h5, .wp-elements-[a-f0-9]{32} h6' . $color_css_rules . '$/', | ||
| 'expected_styles' => '/^.wp-elements-[a-f0-9]{32}[0-9]+ h1, .wp-elements-[a-f0-9]{32}[0-9]+ h2, .wp-elements-[a-f0-9]{32}[0-9]+ h3, .wp-elements-[a-f0-9]{32}[0-9]+ h4, .wp-elements-[a-f0-9]{32}[0-9]+ h5, .wp-elements-[a-f0-9]{32}[0-9]+ h6' . $color_css_rules . '$/', | ||
| ), | ||
| 'individual heading element styles are applied' => array( | ||
| 'color_settings' => array( 'heading' => true ), | ||
|
|
@@ -159,12 +215,12 @@ public function data_elements_block_support_styles() { | |
| 'h5' => array( 'color' => $color_styles ), | ||
| 'h6' => array( 'color' => $color_styles ), | ||
| ), | ||
| 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} h1' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32} h2' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32} h3' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32} h4' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32} h5' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32} h6' . $color_css_rules . '$/', | ||
| 'expected_styles' => '/^.wp-elements-[a-f0-9]{32}[0-9]+ h1' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32}[0-9]+ h2' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32}[0-9]+ h3' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32}[0-9]+ h4' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32}[0-9]+ h5' . $color_css_rules . | ||
| '.wp-elements-[a-f0-9]{32}[0-9]+ h6' . $color_css_rules . '$/', | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition handles a possible case where the parsed block doesn't exist in the registry.