Skip to content

Conversation

@aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Nov 3, 2025

What?

Fixes: #72810

Prevents an issue where block level presets do not work correctly when:

  • Default presets are disabled
  • Slug matches the default preset

Why?

Without this fix theme authors are forced to define presets only at the global level or fudge block-level preset definition slugs. This leads to a poorer end user experience.

How?

The naming and shape of these preset configs can be a bit confusing but the fix itself is rather straightforward. When merging the block level config for default presets is preferred, only falling back to the global config value if it hasn't been set.

Ensuring the correct default preset config from the block level is used prevents incorrect filtering of theme presets.

Testing Instructions

For each theme.json example config below:

  1. Ensure default presets for the feature being testing is on at the global level
  2. Add the block level preset config to your theme.json file
  3. Confirm in the editor the expected presets are available generally and at the block level

Duotone

In the image block, only the "Dark grayscale" duotone preset should be available

{
	"version": 3,
	"appearanceTools": true,
	"settings": {
		"blocks":{
			"core/image": {
				"color": {
					"defaultDuotone": false,
					"duotone": [
						{
							"name": "Dark grayscale",
							"colors": [ "#000000", "#7f7f7f" ],
							"slug": "dark-grayscale"
						}
					]
				}
			}
		}
	}
}

Shadow

In the image block, only the "Natural" shadow preset should be available

{
	"version": 3,
	"settings": {
		"appearanceTools": true,
		"blocks":{
			"core/image": {
				"shadow": {
					"defaultPresets": false,
					"presets": [
						{
							"name": "Natural",
							"slug": "natural",
							"shadow": "6px 6px 9px rgba(0, 0, 0, 0.2)"
						}
					]
				}
			}
		}
	}
}

Font Size

In the Paragraph block, only the "Small" duotone preset should be available

{
	"version": 3,
	"settings": {
		"appearanceTools": true,
		"blocks":{
			"core/paragraph": {
				"typography": {
					"defaultFontSizes": false,
					"fontSizes": [
						{
							"name": "Small",
							"slug": "small",
							"size": "13px"
						}
					]
				}
			}
		}
	}
}

Screenshots or screencast

Before After
Screenshot 2025-11-03 at 7 23 34 pm Screenshot 2025-11-03 at 7 20 28 pm

@aaronrobertshaw aaronrobertshaw self-assigned this Nov 3, 2025
@aaronrobertshaw aaronrobertshaw added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Nov 3, 2025
@aaronrobertshaw aaronrobertshaw marked this pull request as ready for review November 3, 2025 11:25
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: bph <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@aaronrobertshaw
Copy link
Contributor Author

I think this is testing ok for me now and ready for an initial review. I'll get the backport PR sorted tomorrow morning.

@bph
Copy link
Contributor

bph commented Nov 3, 2025

@aaronrobertshaw Thank you so much for jumping at it right away. I tested it with my gallery aspect ratio presets and it works as expected now! 🎉
Screenshot 2025-11-03 at 12 51 34

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shadow

Before the block support didn't show at all.

Before After
Screenshot 2025-11-04 at 12 19 53 pm Screenshot 2025-11-04 at 12 15 15 pm

Font sizes

Before After
Screenshot 2025-11-04 at 12 02 55 pm Screenshot 2025-11-04 at 12 05 11 pm

Duotone

Before After
Screenshot 2025-11-04 at 12 02 37 pm Screenshot 2025-11-04 at 12 05 04 pm

This is working as described for me. Thanks for the fix.

LGTM

I think it'd be worth adding coverage for the other presets just in case.

@ramonjd
Copy link
Member

ramonjd commented Nov 4, 2025

Just needs a backport PR too. 👍🏻

@aaronrobertshaw aaronrobertshaw added the Backport to WP 6.9 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 4, 2025
@github-actions
Copy link

github-actions bot commented Nov 4, 2025

Flaky tests detected in 8d9b8ca.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19066823529
📝 Reported issues:

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply. This pull request appears to be working as expected.

As one edge case, I defined presets with the same slug at both the global and block levels:

{
	"version": 3,
	"settings": {
		"appearanceTools": true,
		"typography": {
			"defaultFontSizes": false,
			"fontSizes": [
				{
					"name": "Small",
					"slug": "small",
					"size": "1em"
				}
			]
		},
		"blocks":{
			"core/paragraph": {
				"typography": {
					"defaultFontSizes": false,
					"fontSizes": [
						{
							"name": "Small",
							"slug": "small",
							"size": "2em"
						}
					]
				}
			}
		}
	}
}

The preset UI is displayed correctly at both the global and block levels, and the global styles are also output correctly.

:root {
   --wp--preset--font-size--small: 1em;
}
p {
    --wp--preset--font-size--small: 2em;
}

@aaronrobertshaw aaronrobertshaw merged commit 30c30aa into trunk Nov 5, 2025
39 checks passed
@aaronrobertshaw aaronrobertshaw deleted the fix/disabled-defaults-preset-merging branch November 5, 2025 02:18
@github-project-automation github-project-automation bot moved this from 🔎 Needs Review to ✅ Done in WordPress 6.9 Editor Tasks Nov 5, 2025
@aaronrobertshaw
Copy link
Contributor Author

Thanks for all the testing and reviews 🙇

@github-actions github-actions bot added this to the Gutenberg 22.1 milestone Nov 5, 2025
@github-actions github-actions bot removed the Backport to WP 6.9 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 5, 2025
gutenbergplugin pushed a commit that referenced this pull request Nov 5, 2025
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: bph <[email protected]>
@github-actions github-actions bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Nov 5, 2025
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

I just cherry-picked this PR to the wp/6.9 branch to get it included in the next release: 6763520

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

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended

Projects

Development

Successfully merging this pull request may close these issues.

Theme.json: Can't define default presets at the block level

5 participants