tomusborne / generateblocks

GenerateBlocks is a small collection of lightweight WordPress blocks that can accomplish nearly anything.
https://generateblocks.com
188 stars 18 forks source link

GB 1.9 "interupts" editor styles in certain themes. NOT BUG #1232

Closed diggeddy closed 1 month ago

diggeddy commented 2 months ago

Description

Using Bricks theme, block editors styles do not load when using GB 1.9. If fallback to GB 1.8 then the styles do load. But is not that GB is loading any styles over the top - Bricks is just not outputting the necessary .editor-styles-wrapper CSS.

Here is GB 1.8, where .editor-styles-wrapper exist

Screenshot 2024-04-26 at 13 55 22

Here is GB 1.9 where they do not

Screenshot 2024-04-26 at 13 56 33

So did we do anything in GB 1.9, possibly related to WP 6.5s changes to editor style loading that could be interfering?

For support topic reference: https://generate.support/topic/post-editor-styling-changed-after-updating-to-gb-1-9-and-gb-pro-1-7/page/2/#post-105042

tomusborne commented 2 months ago

Looks to me like it's being caused by this function: https://github.com/tomusborne/generateblocks/blob/1.9.0/includes/general.php#L461

However, this is the correct usage of the filter, and a valid way of adding styles to the editor.

I guess we would need to know exactly how Bricks is adding this CSS to the editor in the first place.

diggeddy commented 2 months ago

Bricks reply: https://forum.bricksbuilder.io/t/no-bug-gutenberg-editor-styles-disappear-after-generateblocks-plugin-activation/22250/2

OP reckons issue can be replicated in Kadence and Hello, but i could not. However the issue seems to be more than just the use of generateblocks_do_block_css_reset

Any use of the block_editor_settings_all filter whilst GB 1.9 is active will break the styles

To test:

  1. Activate GB 1.9
  2. Remove generateblocks_do_block_css_reset: remove_filter( 'block_editor_settings_all', 'generateblocks_do_block_css_reset', 15 ); `
  3. Add a custom function in either functions.php or a plugin:
add_filter( 'block_editor_settings_all', 'custom_editor_styles', 15 );

// Function to apply CSS reset
function custom_editor_styles( $editor_settings ) {
    $css = 'p {margin-bottom: 100px}';

    // Add CSS to editor settings
    $editor_settings['styles'][] = array(
        'css' => $css,
    );

    return $editor_settings;
}

This will break the editor stylets too.

  1. Disable GB 1.9 and the editor styles now load correctly.
diggeddy commented 2 months ago

And another theme reported: https://generate.support/topic/possible-conflict-with-buddyboss-theme-editor-styles-lost/#post-106330

tomusborne commented 2 months ago

When I add the function above to an empty site using Bricks and no plugins, I see the issue happen as well.

Deactivating GB (or not having it at all) doesn't prevent the issue from happening for me if I'm using the block_editor_settings_all filter anywhere else.

diggeddy commented 2 months ago

May have some relevance: https://forum.bricksbuilder.io/t/solved-how-to-load-editor-styles-in-gutenberg/12346/2

diggeddy commented 1 month ago

So the bottom line here is:

WP has editors styles reset.css and default.css that get loaded. Themes that DO NOT load editor styles return the default.css

If however you use the block_editor_settings_all to load styles, such as we are in GB 1.9, WP changes the loading order of th styles resulting in the reset overriding the default. So the users sees a change.

The fix for themes not loading editor styles is to uncheck Use theme styles in the editor: Editor > Top Bar > 3 dot menu -> Appearance –> Uncheck the Use theme styles