wordpress-activitypub
                                
                                 wordpress-activitypub copied to clipboard
                                
                                    wordpress-activitypub copied to clipboard
                            
                            
                            
                        Blocks: only load inline styles when the block is active
Quick summary
After installed, ActivityPub plugin adds a ton of inline CSS on header, in a style tag with the ID activitypub-followers-style-inline-css, even on sites that don't use blocks (as in, use Classic Editor) or FSE.
Maybe there is a code to declare on functions.php to avoid this behavior? Tbh, it seems like a bug, since it shouldn't load in sites without Gutenberg or FSE in the first place.
Bug first raised on issue #14.
Steps to reproduce
- Just activate and set the plugin up.
- Open the site and check its source code. On header, there will be several lines of inline CSS added with activitypub-followers-style-inline-cssID.
What you expected to happen
That inline code didn't show up in sites that don't use Gutenberg/Blocks or FSE.
What actually happened
CSS loads anyway, no matter the site's configuration.
Impact
Some (< 50%)
Available workarounds?
No but the platform is still usable
Logs or notes
No response
thanks @rghedin !
I think that the functions.php line that you are looking for is:
function remove_wp_block_library_css(){
  wp_dequeue_style( 'activitypub-followers-style' );
  wp_dequeue_style( 'activitypub-follow-me-style' );
} 
add_action( 'wp_print_styles', 'remove_wp_block_library_css', 100 );
Worked like a charm, @writeplace. Thanks!
Shoot, I thought that the Gutenberg styles would only load like that when the block was active, it appears not. Retitled the issue to indicate what needs fixing.
Shoot, I thought that the Gutenberg styles would only load like that when the block was active, it appears not. Retitled the issue to indicate what needs fixing.
Yeah, you'd think, right?
I guess there is a residual from Gutenberg being loaded by AP, @mattwiebe:
<link rel="stylesheet" id="wp-components-css" href="https://manualdousuario.net/wp-includes/css/dist/components/style.min.css?ver=6.4.2" media="all"/>
Any thoughts on this one, @mwt @mattwiebe @writeplace?
Yeah it shouldn't be loading that either, it's a dependency of the block CSS, but if the block's CSS isn't loaded, it shouldn't be either. This is going to be "fun" to fix :D
Fingers crossed 🤞
Meanwhile, do you know any workaround/functions.php to stop it from loading?
@rghedin I got a bit stumped on this one, the styles were only printing when the block was present for me, but then I realized you are in a classic theme and I was in a block theme! So I tested with a classic theme, and yup, it appears that all block styles get printed on a non-block theme. So I dug in.
_add_default_theme_supports sets a bunch of defaults for block themes, including this line that you will want to try out in your functions.php:
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
It's not really named the best but it's controlling this Since Core behaves this way on purpose, and there's a workaround, I'm going to close this one.
Thanks, @mattwiebe! I tried the suggested line in functions.php, but the file didn't go away. This one:
https://domain.com/wp-includes/css/dist/components/style.min.css?ver=6.4.3
☹️
Is this required by the plugin? have you disabled ActivityPub to see if its gone?
Yeap, @pfefferle. Just disabled ActivityPub in my staging site and that CSS isn't being loaded anymore.
The weirdest part is that Disable Gutenberg, a plugin I use and otherwise disable everything blocks/Gutenberg-related, can't catch this one. I opened an issue over there as well.
@rghedin I've dug into this more and it seems like a simply unfortunate part of how WP Core manages block assets, not very well outside of Block Themes, it would seem.
If you wish to disable the ActivityPub blocks on your site entirely, and with it this problem, you can also add the following to your functions.php:
add_filter( 'activitypub_site_supports_blocks', '__return_false' );
Worked like a charm, @mattwiebe! Thanks :)
Ouch, false alarm, @mattwiebe. I forgot to activate ActivityPub back, and thought your filter fixed it. In fact, it didn't, as you can see here.
Sorry about that.
We'll re-open this and see what we can find out
I was poking around this issue and noticed that if I load both functions suggested by you guys, it gets rid of that pesky style.min.css:
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
add_filter( 'activitypub_site_supports_blocks', '__return_false' );