digitoimistodude / air-light

💨 WordPress starter theme - designed to be minimal, ultra-lightweight (< 20 kB) and easy for all kinds of WordPress projects. 7+years/1000+hours of development and still updating daily! We prefer the original WordPress way of doing things so no strange templating languages or frameworks here.
https://airwptheme.com
MIT License
945 stars 142 forks source link

WordPress/Gutenberg core styles leaking to editor #148

Closed ronilaukkarinen closed 2 years ago

ronilaukkarinen commented 2 years ago

It seems our hook for removing the default styles and resets no longer works. Opening an issue to here as well to keep the situation up to date. Referring to my issue comment in Gutenberg repo:

Is it just me, or does every attempt to override or extend Gutenberg's default behavior feel like a fragile hack?

It is not just you.

We recently noticed the fix unset($editor_settings['styles'][0]['css']); is not effective. Default WordPress styles and Gutenberg styles are still applied in the editor as before we got rid of them.

Is there any bulletproof way to deregister or dequeue admin head styles related to Gutenberg blocks nowadays? I can't find any. > We'd like to build our own core block styles, now default styles are in the way.

This issue should really be reopened @youknowriad as add_editor_style doesn't really solve this at all by itself (for the record, we're using it this way.

Let's see what we can do about this.

ronilaukkarinen commented 2 years ago

This hasn't bothered us in the newest WordPress version so closing this for now. Let's open issue again if the problem reoccurs.

ronilaukkarinen commented 2 years ago

Just noticed Autoptimize has "Remove WordPress block CSS" which seems to work well.

Hook-wise it works like this:

    public function disable_global_styles()
    {
        remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
        remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
        remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );

        if ( true === apply_filters( 'autoptimize_filter_extra_global_styles_and_block_css', true ) ) {
            add_action(
                'wp_enqueue_scripts',
                function() {
                    wp_dequeue_style( 'wp-block-library' );
                    wp_dequeue_style( 'wp-block-library-theme' );
                }
            );
        }
    }

Opening for consideration whether we add this functionality to air-helper or to this theme and build those blocks ourselves or trust Gutenberg with their CSS. The gallery block etc. have been quite good lately so it might be best to live with the extra block theme CSS and combine styles with Autoptimize instead.

ronilaukkarinen commented 2 years ago

We have re-valuated this and discussed that we won't be supporting our own core blocks and will have Gutenberg as dependency instead. This way we make sure that blocks retain good quality. It's extra HTTP request but the CSS file is not that large so it doesn't bother us that much at this time.