Skip to content

Fonts from add_missing_fonts_to_theme_json are missing if the style variation is applied #54008

@arthur791004

Description

@arthur791004

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'] becomes NULL and 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

  1. Go to Appearance > Themes
  2. Install and activate the Pendant theme via https://public-api.wordpress.com/rest/v1/themes/download/pendant.zip
  3. Go to the Site Editor
  4. Select Styles > Typography > Text > Font
  5. Ensure you're able to see all fonts defined by the Pendant theme
    image
  6. Select Styles > Browse styles, and pick the non-default style variation
  7. Go back to Select Styles > Typography > Text > Font
  8. The fonts defined by the Pendant theme are missing
    image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] TypographyFont and typography-related issues and PRs[Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions