Skip to content

defaultGradients doesn't work properly #41356

Closed

Description

@wpsoul

Description

I want to disable default gradients and register custom.

I tried defaultGradients option set to false in theme.json and add_theme_support( 'editor-gradient-presets', array() );

Problem is that both ways remove default gradient selectors, but still keep loading all gradients styles in wp-block-library-inline-css and global-styles-inline-css styles which are loaded on all pages of site and generates unused css.

Step-by-step reproduction instructions

  1. Add add_theme_support( 'editor-gradient-presets', array() ) to theme functions
  2. Check source code of page. All styles related to default gradient panel is still loading
  3. https://monosnap.com/file/ZhuAMs5CleBAODQFxZVWwgDQw3oY5T

Screenshots, screen recording, code snippet

No response

Environment info

No response

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

Activity

  1. added
    [Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi
    on May 26, 2022
  2. justintadlock commented on May 26, 2022

    @justintadlock
    Contributor

    From what I understand, this is the correct behavior. Disabling the default gradients is meant to remove them from the UI. However, it is not necessarily unused CSS. WordPress still delivers the CSS for compatibility so that users do not lose preexisting gradient selections.

    If you really wanted to remove core's CSS, it's best to dequeue the wp-block-library styles and roll out custom styles.

  3. wpsoul commented on May 26, 2022

    @wpsoul
    Author

    I don’t think so. If I want to remove default gradients and added such code, then I want really remove them and not just hide. Otherwise, we need another filter to remove them totally.

    from my point of view, Wordpress team are concentrated on block logic and conditional assets. For example, if I don’t use group block, then styles of this block is not loading. So, what is the reason to load such big amount of styles if I deactivated them?

  4. justintadlock commented on May 26, 2022

    @justintadlock
    Contributor

    Related: #40183

    So, what is the reason to load such big amount of styles if I deactivated them?

    Right now, the end user needs the styles to be loaded regardless of whether a theme supports the core gradients. For example, let's say the user had Twenty Twenty-Two installed for a while and used those gradients for their blocks. Then, they install a different theme that doesn't support the core gradients. The user might still want their old gradients to appear correctly. Otherwise, their site looks broken. So, the styles are still needed in those cases.

    The method in which this is handled needs some work. Ideally, Gutenberg/WP would only load those disabled gradient styles if they were in use on a particular page instead of loading them globally when not supported by the theme. Basically, conditional loading.

  5. wpsoul commented on May 26, 2022

    @wpsoul
    Author

    Ok. This has a sense. To be truth, it’s not clear what is the reason to load all gradients at once if it’s possible to load gradient which is used for block. Like we have for all other settings: margins, paddings, etc

  6. skorasaurus commented on May 29, 2022

    @skorasaurus
    Member

    I agree that the Core contributors haven't clearly or prominently communicated to developers based on the number of issues that I've seen about this.

    The ability to only load a certain gradient when it is used on a specific page or block as @justintadlock described is not possible yet; although I'd personally argue that should have been done when gradients were introduced.

    They do eventually plan to conditionally load the gradients so they only load when they are being used (I cannot find the issue about this at the moment) where you could track the progress of this.

    Some of the rationale about this is at and at #38299 (comment) and #38681 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions