Skip to content

Invalid real time generated CSS for ref value when changing font sizes presets in the Global Styles panel (Site Editor) #59585

@daviedR

Description

@daviedR

Description

I tried to add a new block style to my core/heading block. The new style is called title.
The idea is to replicate the h1 element style into the title custom block style.
After discussion in #59163, I tried to use the ref value and block style variations in the theme.json to bind the h1 values into my new title block style.

This works well on the front website and block editor.
But when I use the Global Styles panel (Site Editor) to change the H1 style (Global Styles > Typography > Headings > H1 tab), there is an issue when using the fontSize presets control.

The real time CSS generated is still in raw value var:preset|font-size|large instead of var(--wp--preset--font-size--large).

Screen Shot 2024-03-05 at 16 34 17

But after we clicked the Save button (top right side), the generated CSS is flushed again and shows the correct value.

Screen Shot 2024-03-05 at 16 39 03

Step-by-step reproduction instructions

  1. Add the Snippet 1 (below) to the theme.json file. This will add block style variation for title block style on core/heading block.
  2. Go to Site Editor and add a core/heading block into the template content.
  3. Choose the Title block style. The heading block should replicate the H1 style even though the heading block level is not set to h1.
  4. Go to the Global Styles panel and browse to Typography > Headings > H1 tab.
  5. Change the font size value using the S M L XL XXL presets.
  6. The font size is not applied to the heading block with Title style, because Site Editor JS generate invalid CSS value (see screenshot above).

Screenshots, screen recording, code snippet

Snippet 1 (theme.json):

{
	...
	"styles": {
		"blocks": {
			"core/heading": {
				"variations": {
					"title": {
						"typography": {
							"fontFamily": { "ref": "styles.elements.h1.typography.fontFamily" },
							"fontSize": { "ref": "styles.elements.h1.typography.fontSize" },
							"fontStyle": { "ref": "styles.elements.h1.typography.fontStyle" },
							"fontWeight": { "ref": "styles.elements.h1.typography.fontWeight" },
							"letterSpacing": { "ref": "styles.elements.h1.typography.letterSpacing" },
							"lineHeight": { "ref": "styles.elements.h1.typography.lineHeight" },
							"textDecoration": { "ref": "styles.elements.h1.typography.textDecoration" },
							"textTransform": { "ref": "styles.elements.h1.typography.textTransform" }
						}
					}
				}
			}
		}
	}
}

Environment info

  • WordPress 6.4.3
  • Gutenberg 17.8.2

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

Metadata

Metadata

Labels

Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions