mirror of
https://github.com/WordPress/WordPress.git
synced 2026-06-19 07:37:07 +00:00
Editor: Fix wp-elements-* CSS class name collisions for identical blocks.
The `wp_get_elements_class_name()` function previously generated CSS class names by hashing the serialized block data via `md5()`. Identical blocks received the same `wp-elements-*` class name and the Style Engine deduplicated their CSS rules into one, causing a parent block's element style (e.g. link color) to cascade down and override a child block's identical style due to CSS source order. The function is updated to use `wp_unique_prefixed_id()` instead, generating sequential unique class names (`wp-elements-1`, `wp-elements-2`, etc.) that match the block editor's JavaScript implementation. The now-unused `$parsed_block` parameter is removed from the function signature. PHPStan rule level 10 errors are also resolved in the related code. See #64898. Developed in https://github.com/WordPress/wordpress-develop/pull/12126. Follow-up to r53260, r58074. Props tusharbharti, westonruter, wildworks. Fixes #65435. Built from https://develop.svn.wordpress.org/trunk@62520 git-svn-id: http://core.svn.wordpress.org/trunk@61801 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -12,11 +12,10 @@
|
||||
* @since 6.0.0
|
||||
* @access private
|
||||
*
|
||||
* @param array $block Block object.
|
||||
* @return string The unique class name.
|
||||
*/
|
||||
function wp_get_elements_class_name( $block ) {
|
||||
return 'wp-elements-' . md5( serialize( $block ) );
|
||||
function wp_get_elements_class_name(): string {
|
||||
return wp_unique_prefixed_id( 'wp-elements-' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,6 +108,29 @@ function wp_should_add_elements_class_name( $block, $options ) {
|
||||
*
|
||||
* @param array $parsed_block The parsed block.
|
||||
* @return array The same parsed block with elements classname added if appropriate.
|
||||
*
|
||||
* @phpstan-param array{
|
||||
* blockName: string,
|
||||
* attrs: array{
|
||||
* className?: string,
|
||||
* style?: array{
|
||||
* elements?: array<string, array{
|
||||
* ":hover"?: array<string, string>,
|
||||
* ...
|
||||
* }>,
|
||||
* },
|
||||
* ...
|
||||
* },
|
||||
* ...
|
||||
* } $parsed_block
|
||||
* @phpstan-return array{
|
||||
* blockName: string,
|
||||
* attrs: array{
|
||||
* className?: string,
|
||||
* ...
|
||||
* },
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
function wp_render_elements_support_styles( $parsed_block ) {
|
||||
/*
|
||||
@@ -129,9 +151,12 @@ function wp_render_elements_support_styles( $parsed_block ) {
|
||||
);
|
||||
}
|
||||
|
||||
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] );
|
||||
$element_block_styles = $parsed_block['attrs']['style']['elements'] ?? null;
|
||||
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] );
|
||||
if ( ! $block_type ) {
|
||||
return $parsed_block;
|
||||
}
|
||||
|
||||
$element_block_styles = $parsed_block['attrs']['style']['elements'] ?? null;
|
||||
if ( ! $element_block_styles ) {
|
||||
return $parsed_block;
|
||||
}
|
||||
@@ -157,7 +182,7 @@ function wp_render_elements_support_styles( $parsed_block ) {
|
||||
return $parsed_block;
|
||||
}
|
||||
|
||||
$class_name = wp_get_elements_class_name( $parsed_block );
|
||||
$class_name = wp_get_elements_class_name();
|
||||
$updated_class_name = isset( $parsed_block['attrs']['className'] ) ? $parsed_block['attrs']['className'] . " $class_name" : $class_name;
|
||||
|
||||
_wp_array_set( $parsed_block, array( 'attrs', 'className' ), $updated_class_name );
|
||||
@@ -197,7 +222,7 @@ function wp_render_elements_support_styles( $parsed_block ) {
|
||||
)
|
||||
);
|
||||
|
||||
if ( isset( $element_style_object[':hover'] ) ) {
|
||||
if ( isset( $element_style_object[':hover'], $element_config['hover_selector'] ) ) {
|
||||
wp_style_engine_get_styles(
|
||||
$element_style_object[':hover'],
|
||||
array(
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '7.1-alpha-62519';
|
||||
$wp_version = '7.1-alpha-62520';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user