Make WordPress Core

Opened 5 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#61282 closed enhancement (fixed)

Backport theme.json version 3 migrations

Reported by: ajlende's profile ajlende Owned by: ellatrix's profile ellatrix
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch has-unit-tests
Focuses: Cc:

Change History (16)

@ramonopoly commented on PR #6616:


3 weeks ago
#2

Hi there, to help folks (like me) who don't have much context, are there any specific things that should be tested in this PR?

Or is the assumption to run through the test instructions for each Gutenberg PR?

@ajlende commented on PR #6616:


3 weeks ago
#3

Hi there, to help folks (like me) who don't have much context, are there any specific things that should be tested in this PR?

Or is the assumption to run through the test instructions for each Gutenberg PR?

The focus for the PHP side of things is more around what gets generated by global styles which is only tested via the UI on the gutenberg PRs.

The dev note summarizes the changes that need to be made to make a v3 theme.json work like a v2 theme.json. But without changing the version, the styles generated for any existing v2 theme.json should remain unchanged from before.

If the dev note doesn't explain enough, the original two PRs https://github.com/WordPress/gutenberg/pull/58409 and https://github.com/WordPress/gutenberg/pull/61842 are a good place to find more info if I'm not around.

@ramonopoly commented on PR #6616:


3 weeks ago
#4

So far I've been stuck on testing defaultFontSizes.

I can confirm that migration works - I tested that manually using WP_Theme_JSON_Schema::migrate( $theme_json ) and seeing that 'defaultFontSizes' => false is appended to settings.typography.

But I'm having trouble manually testing.

I've started off with font sizes and am following the instructions over at https://github.com/WordPress/gutenberg/pull/58409 and the dev note

I understand the editor UI won't reflect theme.json definitions until the JS packages are migrated, so I've been testing the output of WP_Theme_JSON::compute_preset_vars() and wp_get_global_stylesheet().

With theme.json version 2 the default font sizes are generated by WP_Theme_JSON::compute_preset_vars() (and therefore wp_get_global_stylesheet all the time), and CSS custom vars are printed to the frontend. This is legacy, default behavior I understand.

With theme.json version 3 settings.typography.defaultFontSizes appears to have no effect. When set to false the default font sizes are still output.

Logging where $prevent_override is set, I see settings.typography.defaultFontSizes still returns bool(true).

Just to be sure I also set settings.typography.defaultFontSizes to false in src/wp-includes/theme.json. Now the value of $prevent_override is false.

Even hardcoding a bool for $prevent_override` in the PRESETS_METADATA doesn't have an effect.

Am I missing something or should I be testing the output of WP_Theme_JSON->get_stylesheet() directly given some input?

It would be nice to have some steps to test this backport in particular. Sorry I ran out of time to go further.

Thanks!

@ajlende commented on PR #6616:


3 weeks ago
#5

I can confirm that migration does something - I tested that manually using WP_Theme_JSON_Schema::migrate( $theme_json_v2 ) and seeing that the version is bumped to 3 and 'defaultFontSizes' => false is appended to settings.typography.

I basically copied the wpThemeJson tests. Shouldn't it be true?

It should be false whenever there were existing settings, otherwise it should be left empty.

With theme.json version 3 settings.typography.defaultFontSizes appears to have no effect. When set to false the default font sizes are still output.
...
Am I missing something or should I be testing the output of WP_Theme_JSON->get_stylesheet() directly given some input?

This is the correct behavior. The default* options only control whether the theme can override the defaults and if they show up in the _UI_. It does not remove them from the stylesheet. You can confirm with the color presets, for example if you'd like.

@ramonopoly commented on PR #6616:


3 weeks ago
#6

Okay I think there was a bit of a 🤦🏻 moment on my side. It took me a while to grok.

Now I'm seeing the following:

Theme with "defaultFontSizes": true, (overwritten by the default)

    --wp--preset--font-size--small: 13px;

Theme with "defaultFontSizes": false, (not overwritten by the default)

    --wp--preset--font-size--small: 333rem;

I'll continue to test the spacing later - I'm AFK for a few hours.

@ramonopoly commented on PR #6616:


3 weeks ago
#7

### Manual testing

I tested by manipulating 2024 theme.json files.

#### Spacing sizes

"defaultSpacingSizes": true, is the default for theme.json v2. The WordPress default spacing sizes take precedence over active theme sizes with the same slug
✅ With "defaultSpacingSizes": false, set for theme.json v3 the theme's spacing sizes take precedence over WordPress default sizes with the same slug
✅ With "defaultSpacingSizes": true, set for theme.json v3 the WordPress default spacing sizes take precedence over active theme sizes with the same slug

#### Font sizes

✅ As above, but tested with same-slugged fontSizes items toggling between "defaultFontSizes": false, and "defaultFontSizes": true,

I also added a theme.json to a classic theme (2020) and repeated the above.

#8 @ellatrix
3 weeks ago

  • Owner set to ellatrix
  • Resolution set to fixed
  • Status changed from new to closed

#9 @kebbet
3 weeks ago

With changesets during 6.6 development, please milestone this ticket accordingly @ellatrix. Thanks!

#10 @ellatrix
3 weeks ago

  • Milestone changed from Awaiting Review to 6.6

Didn't have the permissions until now

@ajlende commented on PR #6616:


3 weeks ago
#11

One of the tests I've done was to switch back every input dataset to v2 and see the test report, as we don't want to require any change to consumers that still use the v2 version. TLDR: test work as expected. If the theme was a v2, what happened is that the migration added defaultFontSizes: false, which is how it works because we changed the prevent override logic to default to true — hence this addition in the migration.

@oandregal I went back and forth in the Gutenberg PR for this if I should fix all the tests that were testing the exact output of the theme.json instead of the specific thing they should have been testing or just update the theme.json version to latest everywhere. The later seemed easier because I could do it with a simple find and replace, so that's what I went with. Would have you preferred the former? I can still update things in the follow-up.

@ramonopoly commented on PR #6616:


3 weeks ago
#12

Thanks again for the help on reviewing folks and for all the work @ajlende

Great that this has landed overnight!

This ticket was mentioned in PR #6737 on WordPress/wordpress-develop by @oandregal.


3 weeks ago
#13

Trac ticket https://core.trac.wordpress.org/ticket/61282

Commit message:

Editor: code quality improvements for theme.json migrate API

Backports https://github.com/WordPress/gutenberg/pull/62305

Follow-up [58328], #61282.

Props ajlende, oandregal.
Fixes #61282.

@oandregal commented on PR #6737:


3 weeks ago
#14

cc @ajlende @ramonjd

#15 @oandregal
3 weeks ago

In 58354:

Editor: code quality improvements for theme.json migrate API

Backports https://github.com/WordPress/gutenberg/pull/62305

Follow-up to [58328], #61282.

Props ajlende, oandregal, ramonopoly, mukesh27.
Fixes #61282.

Note: See TracTickets for help on using tickets.