Giter Site home page Giter Site logo

Comments (5)

korn806 avatar korn806 commented on September 2, 2024

Yes, this bug is still there. A quick fix is to comment out the initiation of the blocks setup in line 170 of safe-svg.php.

From
Blocks\setup();
to
//Blocks\setup();

But you will have to do that after every plugin update.

A more robust workaround would be an action to allow the deactivation of the blocks setup in the functions.php when not needed. Something like this:

Change the code in safe-svg.php from

public function setup_blocks() {
    Blocks\setup();
}

to

public function setup_blocks() {
	add_action('safe_svg_blocks', function () {
		if (isset($this->disabled)) {
			return;
		}
               else  {
			Blocks\setup();
               }
	});
	do_action('safe_svg_blocks', $this);
}

public function safe_svg_blocks_disable() {
	$this->disabled = true;
}

Now you can disable the blogs setup with the following action in functions.php:

add_action('safe_svg_blocks', function (SafeSvg\safe_svg $safe_svg_blocks) {
        $safe_svg_blocks->safe_svg_blocks_disable();
    });

from safe-svg.

dkotter avatar dkotter commented on September 2, 2024

Curious if there are additional reproduction steps that could be provided here? I've tried reproducing this myself but the only time I see that CSS being loaded is if I'm on a post or page that uses the Safe SVG block. All other posts, pages, home page, etc don't load that CSS.

I've tried testing both on content created with the Block Editor and content created with the Classic Editor, both posts and pages but I never see that CSS load unless the block is being used.

from safe-svg.

korn806 avatar korn806 commented on September 2, 2024

As thomasbachem described: An old-style custom WordPress theme without blocks and upgraded to recent WP + Safe SVG versions.

from safe-svg.

kirtangajjar avatar kirtangajjar commented on September 2, 2024

@dkotter I was able to reproduce this issue in a classic theme(twentyfourteen). So this issue is actually a WP core behaviour and not a safe-svg plugin specific issue. On non-block themes, WordPress renders styles of all blocks regardless of if they're rendered or not. This happens in wp_enqueue_registered_block_scripts_and_styles function which is hooked on enqueue_block_assets action.

So all WP would render styles of all the blocks registered by all the plugins. To disable this behaviour and render a style only when the block is loaded, add this filter in the code and it should be sorted:

add_filter( 'should_load_separate_core_block_assets', '__return_true' );

Since this is a WP core behaviour, I don't think we need to create a workaround for it in our code.

from safe-svg.

korn806 avatar korn806 commented on September 2, 2024

kirtangajjar the propblem of this solution is that you now get the "global-styles-inline-css"-style injected in the html, which kinda defeats the purpose.

from safe-svg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.