-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Description
Gutenberg adds the missing fonts to the theme json data. However, when it tries to merge the global styles (selected style variation) into the theme json data, the mergeBaseAndUserConfigs will override the old array (no merging) so that the font families from the theme json data will be overridden if the style variation has its own font families set.
Take the Pendant theme for example, it has the font assets here so those fonts would be injected into the theme JSON data via the add_missing_fonts_to_theme_json function. Then, you're able to select those fonts in the Site Editor. However, when you switch to the non-default style variation, those fonts are missing since the mergeBaseAndUserConfigs will override the old array.
Here are possible solutions
- Inject the missing fonts to the core data instead of the theme json so the injected fonts won't be overridden
- The mergeBaseAndUserConfigs should merge the font families instead of overriding
Related notes
- We proposed the first one on Jetpack but we found that the array_unique might make the
$settings['typography']['fontFamilies']['theme']becomesNULLand it leads to that the array_merge function is broken on the next iteration. - Only the font assets should be available across different style variations, and the fonts defined by a specific style variation should not be available when people switch to others.
Step-by-step reproduction instructions
- Go to Appearance > Themes
- Install and activate the Pendant theme via https://public-api.wordpress.com/rest/v1/themes/download/pendant.zip
- Go to the Site Editor
- Select Styles > Typography > Text > Font
- Ensure you're able to see all fonts defined by the Pendant theme

- Select Styles > Browse styles, and pick the non-default style variation
- Go back to Select Styles > Typography > Text > Font
- The fonts defined by the Pendant theme are missing

Screenshots, screen recording, code snippet
gutenberg-missing-fonts-issue.mp4
Environment info
- The latest Gutenberg
Please confirm that you have searched existing issues in the repo.
No
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes