Skip to content

Fonts not loading in page/site editor with Gutenberg 15.9 RC1 #50965

Closed

Description

@bgardner

Description

I have several themes that load Outfit font from Google, and with Gutenberg 15.9 RC1 active, they are not being enqueued properly in page/site editors. The front end works as expected. To further test, I confirmed this is also true of the Hey theme by Automattic. If I deactivate the plugin, the fonts load as expected.

Step-by-step reproduction instructions

  1. Activate theme with Google fonts
  2. Activate Gutenberg 15.9 RC1
  3. View content on page/site editors

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.2.2, Gutenberg 15.9 RC1

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

Activity

  1. bgardner commented on May 25, 2023

    @bgardner
    Author

    Adding video to show what happens when plugin is activated/deactivated:

    Screen.Recording.2023-05-25.at.8.51.07.AM.mov
  2. added
    [Type] Bug
    [Type] Regression
    on May 25, 2023
  3. ndiego commented on May 25, 2023

    @ndiego
    Member

    I am able to confirm with TT3 using the included font families. cc @c4rl0sbr4v0 this would be great to get fixed before 15.9 goes out the door.

  4. WraithKenny commented on May 25, 2023

    @WraithKenny

    Able to reproduce also, shows Helvetica in FSE editor.

  5. WraithKenny commented on May 26, 2023

    @WraithKenny

    #50929 is also a font related regression.

  6. cbravobernal commented on May 29, 2023

    @cbravobernal
    Contributor

    I'm not really sure that I will be able to fix it before the RC2 😢

  7. richtabor commented on May 30, 2023

    @richtabor
    Member

    Confirmed this issue.

  8. hellofromtonya commented on May 31, 2023

    @hellofromtonya
    Contributor

    Activate theme with Google fonts

    Does the theme have a local asset file for the Google font? Or is a custom provider included that remotely interacts with Google Fonts foundry API?

    Why am I asking?

    Because Gutenberg ships with a "local" provider for processing local asset files. But if the @font-face src comes from Google Fonts API, then a custom provider is needed, which could mean there's an issue within that provider (which is not provided in Gutenberg).

    Knowing this can help with reproduction and investigation.

  9. hellofromtonya commented on May 31, 2023

    @hellofromtonya
    Contributor

    Test Report

    Env:

    • Plugins: Gutenberg 15.9 RC2
    • Theme: TT3
    • Must-Use: none
    • LocalHost: Local
    • OS: macOS
    • Browser: Firefox

    Test Steps

    1. Downloaded the 15.9 RC2 gutenberg.zip file and added it as new plugin through WP's Plugins > Add New UI
    2. Navigated to the Site Editor > Styles > Typography UI
    3. Selected "Headings"
    4. Selected the "Font" as "Source Serif Pro" (which has a local font file in the TT3 theme)
    5. Compared the rendered heading font to the same font on Google Fonts site

    Results

    Screen Shot 2023-05-31 at 10 29 36 AM

    ✅ Font rendered as expected.

    ❌ Could not reproduce the reported issue using a font that has a local asset file in the theme.

    Summary

    Next, I'll try using a Google Fonts Provider that interacts with Google Fonts Foundry API rather than supplying a local font asset file. I'll use this test plugin that includes Jetpack's Google Fonts Provider package.

  10. hellofromtonya commented on May 31, 2023

    @hellofromtonya
    Contributor

    Test Report 2

    Env:

    Test Steps

    Set up

    1. Gutenberg 15.9 RC plugin:
    2. Webfonts Jetpack Test plugin
      • Downloaded the zip file from GitHub by clicking on the "Code" selector and then selecting "Download ZIP".
      • Added it as new plugin through WP's Plugins > Add New UI.
      • Activated it.

    Scenario 1: Selecting a Google Font in Site Editor but not saving the custom style.

    1. Navigated to the Site Editor > Styles > Typography UI
    2. Selected "Headings"
    3. Selected the "Font" as "Merriweather" (which is a Google Font that does not have a local asset file in the plugin or theme but instead will interact with Google Fonts Foundry API)
    4. Selected the "Appearance" as "Bold Italic".
    5. Compared the rendered heading font to the same font on Google Fonts site. Do they match?

    Scenario 2: After saving the custom style in the Site Editor.

    1. Save the custom heading.
    2. Reload the Site Editor.
    3. Again compare the headings to the same font on Google Fonts site
      Do they match?

    Scenario 3: Editing an existing post after saving the custom style in the Site Editor.

    1. Exit the Site Editor.
    2. Open an existing Post by navigating to All Posts > selecting the Hello World or other existing post
    3. Again compare the headings to Google Fonts site. Do they match?

    Results

    Scenario 1:

    Screen Shot 2023-05-31 at 10 32 45 AM

    ✅ Google Font rendered as expected.

    ❌ Could not reproduce the reported issue.

    Scenario 2: After saving the custom style in the Site Editor.

    Screen Shot 2023-05-31 at 10 41 12 AM

    ✅ Google Font rendered as expected.

    ❌ Could not reproduce the reported issue.

    Scenario 3: Editing an existing post after saving the custom style in the Site Editor.

    Screen Shot 2023-05-31 at 10 43 30 AM

    ✅ Google Font rendered as expected.

    ❌ Could not reproduce the reported issue.

    Summary

    Hmm, in all 3 scenarios, I could not reproduce the reported issue for a Google Font. Each scenario rendered as expected and the @font-face styles were correct in the HTML for each.

  11. bgardner commented on May 31, 2023

    @bgardner
    Author

    @hellofromtonya Yes, my themes (as did the Hey theme I also tested) come packaged with local font source files. For example, you can see how Frost has them included.

  12. bgardner commented on May 31, 2023

    @bgardner
    Author
  13. hellofromtonya commented on May 31, 2023

    @hellofromtonya
    Contributor

    Thanks @bgardner. Let me try the Frost theme with my test set up. Test Report coming.

  14. hellofromtonya commented on May 31, 2023

    @hellofromtonya
    Contributor

    Test Report

    Env:

    • Plugins: Gutenberg 15.9 RC2
    • Theme: Frost
    • Must-Use: none
    • LocalHost: Local
    • OS: macOS
    • Browser: Firefox

    Test Steps

    1. Gutenberg 15.9.0: install and activate.
    2. Theme: Appearance > Themes > Add New > find Frost. Then install and activate.
    3. Navigate to Appearance > Editor
    4. Compare the heading "Experience the next generation of WordPress" to the Outfit font on the Google Fonts site. Do they match?
    5. Using your browser's dev tools, inspect the HTML. Search for wp-fonts-local. Does the CSS match:
    <style id="wp-fonts-local">
    @font-face{font-family:Outfit;font-style:normal;font-weight:100 900;font-display:block;src:url('/wp-content/themes/frost/assets/fonts/Outfit-Variable.woff2') format('woff2');font-stretch:normal;}
    </style>

    Results

    Without Gutenberg activated

    ✅ The @font-face styles are correct

    <style id="wp-block-library-inline-css">
    @font-face{font-family:Outfit;font-style:normal;font-weight:100 900;font-display:block;src:url('/wp-content/themes/frost/assets/fonts/Outfit-Variable.woff2') format('woff2');font-stretch:normal;}
    </style>

    ✅ The font matches the Outfit rendering on the Google Fonts site
    Screen Shot 2023-05-31 at 1 20 47 PM

    With Gutenberg 15.9.0 activated

    ✅ The @font-face styles are correct

    <style id="wp-fonts-local">
    @font-face{font-family:Outfit;font-style:normal;font-weight:100 900;font-display:block;src:url('/wp-content/themes/frost/assets/fonts/Outfit-Variable.woff2') format('woff2');font-stretch:normal;}
    </style>

    ❌ The font does not match the Outfit rendering on the Google Fonts site

    Screen Shot 2023-05-31 at 1 16 58 PM

    Summary

    Yes, I can reproduce the issue using the Frost theme.

    👉 But the @font-face CSS generated is the same with and without Gutenberg plugin activated.

    Hmm, why isn't the Outfit font being rendered when it's @font-face CSS is there?

  15. hellofromtonya commented on May 31, 2023

    @hellofromtonya
    Contributor

    Investigating ...

    Is the Fonts API working?

    Yes.

    As I noted in my last test report, the @font-face CSS generated is the same with and without Gutenberg plugin activated:

    With the plugin activated:

    <style id="wp-fonts-local">
    @font-face{font-family:Outfit;font-style:normal;font-weight:100 900;font-display:block;src:url('/wp-content/themes/frost/assets/fonts/Outfit-Variable.woff2') format('woff2');font-stretch:normal;}
    </style>

    Without the plugin activated:

    <style id="wp-block-library-inline-css">
    @font-face{font-family:Outfit;font-style:normal;font-weight:100 900;font-display:block;src:url('/wp-content/themes/frost/assets/fonts/Outfit-Variable.woff2') format('woff2');font-stretch:normal;}
    </style>

    The Fonts API is working ✅

    What about which font-family is assigned to the h2 element?

    Inspecting the element and its rules:

    With the Gutenberg plugin activated:

    .editor-styles-wrapper {
      --wp--style--root--padding-top: 0px;
      --wp--style--root--padding-right: var(--wp--custom--spacing--gap);
      --wp--style--root--padding-bottom: 0px;
      --wp--style--root--padding-left: var(--wp--custom--spacing--gap);
      color: var(--wp--preset--color--contrast);
      font-family: var(--wp--preset--font-family--primary);
    }

    where --wp--preset--font-family--primary = Outfit, sans-serif.

    Screen Shot 2023-05-31 at 1 51 58 PM
    • Without the Gutenberg plugin activated:

    It's the same.

    Screen Shot 2023-05-31 at 1 53 07 PM

    .editor-styles-wrapper {
      --wp--style--root--padding-top: 0px;
      --wp--style--root--padding-right: var(--wp--custom--spacing--gap);
      --wp--style--root--padding-bottom: 0px;
      --wp--style--root--padding-left: var(--wp--custom--spacing--gap);
      color: var(--wp--preset--color--contrast);
      font-family: var(--wp--preset--font-family--primary);
    }

    where --wp--preset--font-family--primary = Outfit, sans-serif.

    What next?

    Picture me shrugging 🤷‍♀️ Hmm, likely someone needs to confirm my findings. Do you also get the same @font-face CSS with and without the Gutenberg plugin activated?

  16. bgardner commented on May 31, 2023

    @bgardner
    Author

    @hellofromtonya Worth noting, I know you tested the H2 in this, but it's all type—paragraphs, etc.

  17. ndiego commented on May 31, 2023

    @ndiego
    Member

    I also wanted to mention you can test this with fonts included in TT3. In Global Styles I set all text to IBM Plex Mono. This is included with the theme and I do not have it on my local machine. With 15.9, this font is no longer loaded.

    How it should look (Gutenberg deactivated):
    image

    image

    How it looks with Gutenberg 15.9:
    image

    image
  18. hellofromtonya commented on Jun 1, 2023

    @hellofromtonya
    Contributor

    Thank you @bgardner! I see the issue. Let me explain.

    tl;dr

    In the admin area, the font src needs to be absolute URL to work within an iframe.

    Explanation:

    The issue:
    The WP_Fonts_Provider_Local::compile_src() converts the font src 'url' from absolute to relative. Relative works fine when the font asset files are referenced in the main document. But in an iframe, the relative URL relates to the main document, rather than the path from the iframe to the font asset file.

    When making the URL absolute, notice the asset file is included in the editor-canvas (the iframe) list.
    editor-canvas source files

    Possible solution:

    There are a couple of ways to solve this:

    • Option 1: Within an iframed editor, use the absolute URL.
    • Option 2: Remove the make relative code so that all font src URLs are absolute.

    I don't remember the reasoning for why relative URLs were used in the Local Provider. Pinging @aristath for insights.

    But I think Option 2 is likely the best option. Why? It will ensure assets load in all instances (iframe or main document) while reducing the amount of code. That gives a bonus of less code to maintain and a tiny micro-optimization for performance (less code to run).

    I'll open a PR for Option 2 for consideration. I would like @aristath input to refresh my memory of why relative URLs were used, i.e. in case they are indeed needed in certain instances.

  19. ndiego commented on Jun 1, 2023

    @ndiego
    Member

    Thanks for the insight @hellofromtonya . @ellatrix do you think this issue in 15.9 could be related to #50875? This only started occurring in 15.9.

  20. added
    [Status] In Progress
    on Jun 1, 2023
  21. hellofromtonya commented on Jun 1, 2023

    @hellofromtonya
    Contributor

    @bgardner Would you have time to test the bugfix? If no, that's okay. But if yes, please test PR #51178 with the Frost theme. Testing instructions are listed in the description. It works for me. I want to certain it also works for you.

  22. WraithKenny commented on Jun 1, 2023

    @WraithKenny

    I think this would also be testable on twenty-twentythree, since it also loads local fonts.

  23. hellofromtonya commented on Jun 1, 2023

    @hellofromtonya
    Contributor

    I think this would also be testable on twenty-twentythree, since it also loads local fonts.

    You're right @WraithKenny, though there's more steps for testing as you need to select one of the fonts in Site Editor > Styles > Typography UI. For example you can select "Source Serif Pro" for all the Text fonts.

  24. removed
    [Status] In Progress
    on Jun 3, 2023
  25. webd-uk commented on Aug 27, 2023

    @webd-uk

    OMG, I've been stuck on exactly this issue for days. THANK YOU!

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

Metadata

Metadata

Labels

[Type] Bug[Type] Regression

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions