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

Gutenberg Bug - Nested WP Element Styles Broken #52646

Closed
TimDix opened this issue Jul 14, 2023 · 5 comments · Fixed by #53085
Closed

Gutenberg Bug - Nested WP Element Styles Broken #52646

TimDix opened this issue Jul 14, 2023 · 5 comments · Fixed by #53085
Assignees
Labels
[Package] Style Engine /packages/style-engine [Status] In Progress Tracking issues with work in progress [Type] Regression Related to a regression in the latest release

Comments

@TimDix
Copy link

TimDix commented Jul 14, 2023

Description

I'm noticing some very weird behavior in the latest version of Gutenberg. It appears that the logic for inline styles is broken. Here's a video showing, 6.2.2, and an unmodified twenty twenty three theme:

https://www.youtube.com/watch?v=YRpz5xJfHZw

It seems to me that WordPress is unable to output the styles in the correct order, causing the wrong styles to override. WordPress is combining multiple styles when the color is the same, which causes specific styles on descendant elements to be hoisted to a higher level.

Step-by-step reproduction instructions

  • Set one color on the parent
  • Set a different color on a child
  • Set the same color as the parent on another child
  • Second color overrides the first

Multiple related bugs and steps to reproduce demonstrated in the video.

Screenshots, screen recording, code snippet

https://www.youtube.com/watch?v=YRpz5xJfHZw

Environment info

WordPress 6.2.2, unmodified Twenty twenty three theme, Chrome

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

@TimDix TimDix changed the title Gutenberg Bug Nested WP Element Styles Broken Gutenberg Bug - Nested WP Element Styles Broken Jul 14, 2023
@costdev
Copy link
Contributor

costdev commented Jul 14, 2023

Trac ticket for the bugfix merge when it's ready: https://core.trac.wordpress.org/ticket/58811

@johannecourtright
Copy link

I have done some testing, it seems that disabling this solves it
if ( true === $options['optimize'] ) { $this->combine_rules_selectors(); }
wp-includes/style-engine/class-wp-style-engine-processor.php

@TimDix
Copy link
Author

TimDix commented Jul 14, 2023

Also, optimize does not default to false, it defaults to true?

wp-includes/style-engine/class-wp-style-engine-processor.php

@type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is false.

$defaults = array( 'optimize' => true, 'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG, );

@johannecourtright
Copy link

johannecourtright commented Jul 14, 2023

until this gets resolved, this is a temporary work around, put this in your theme. Enforce the option to be passed into the function, remove the action hook first and re-add
`
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_stored_styles' );
remove_action( 'wp_footer', 'wp_enqueue_stored_styles', 1 );

add_action( 'wp_enqueue_scripts', 'fix_enqueue_stored_styles' );
add_action( 'wp_footer', 'fix_enqueue_stored_styles', 1 );

function fix_enqueue_stored_styles() {
$options = array('optimize' => false);
wp_enqueue_stored_styles($options);
}
`

@ramonjd
Copy link
Member

ramonjd commented Jul 28, 2023

Also, optimize does not default to false, it defaults to true?

Thanks for filing this issue and noticing the discrepancy. I've flipped the default to false here:

#53085

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Style Engine /packages/style-engine [Status] In Progress Tracking issues with work in progress [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants