gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Adding custom color palette on a block through theme.json creates warning in console

Open giannis-koulouris-bb opened this issue 2 years ago • 2 comments

Description

I'm using theme.json to set custom color palette for the core/button block, and when I do it I get this warning in the console:

global-styles-css-custom-properties-inline-css was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.

Other than that, everything works fine though, I get the correct colors showing in the sidebar and the correct styles are being generated.

The way I set the custom color palette is through theme.json like this (just pasting the block settings part for simplicity):

{ "settings": { "blocks": { "core/button": { "color": { "palette": [ { "name": "Black", "slug": "black", "color": "#000000" }, { "name": "White", "slug": "white", "color": "#FFFFFF" } ] } } } } }

I've even tested on Twenty Twenty-Four theme and happens there as well.

Step-by-step reproduction instructions

  1. Open Twenty Twenty-Four theme.json using a code editor
  2. Add custom color palette on blocks via settings.blocks
  3. Open console when inside Gutenberg editor, and you will see the warning.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • [X] Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • [X] Yes

giannis-koulouris-bb avatar Sep 16 '24 14:09 giannis-koulouris-bb

I was able to reproduce the warning by adding a custom color pallet for the core button block

Image

Upon further inspection, the warning originates from the Gutenberg editor's iframe component used to render the content inside the editor.

https://github.com/WordPress/gutenberg/blob/0e10bebe95cd0bca6a3d4590b9bbc2b5d625d9f0/packages/block-editor/src/components/iframe/index.js#L160-L176

So when styles like custom color palettes for core blocks are defined in theme.json, WordPress injects them into the head into their respective compatStyle (global-styles-css-custom-properties-inline-css in this case). As these styles aren't properly enqueued, they show the warning of incorrect use.

BugReportOnWeb avatar Jun 04 '25 11:06 BugReportOnWeb

Thanks for the report. I think this problem is the same as #76082.

I'd like to close this issue as a duplicate, as the cause is more precisely identified there.

t-hamano avatar Mar 07 '26 06:03 t-hamano