You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fonts not loading in page/site editor with Gutenberg 15.9 RC1 #50965
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
Activate theme with Google fonts
Activate Gutenberg 15.9 RC1
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.
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.
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.
Navigated to the Site Editor > Styles > Typography UI
Selected "Headings"
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)
Scenario 2: After saving the custom style in the Site Editor.
✅ 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.
✅ 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.
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?
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.
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.
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.
@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.
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.
Activity
bgardner commentedon May 25, 2023
Adding video to show what happens when plugin is activated/deactivated:
Screen.Recording.2023-05-25.at.8.51.07.AM.mov
ndiego commentedon May 25, 2023
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.
WraithKenny commentedon May 25, 2023
Able to reproduce also, shows Helvetica in FSE editor.
WraithKenny commentedon May 26, 2023
#50929 is also a font related regression.
cbravobernal commentedon May 29, 2023
I'm not really sure that I will be able to fix it before the RC2 😢
richtabor commentedon May 30, 2023
Confirmed this issue.
hellofromtonya commentedon May 31, 2023
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-facesrc 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.
hellofromtonya commentedon May 31, 2023
Test Report
Env:
Test Steps
Results
✅ 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.
hellofromtonya commentedon May 31, 2023
Test Report 2
Env:
Test Steps
Set up
Scenario 1: Selecting a Google Font in Site Editor but not saving the custom style.
Scenario 2: After saving the custom style in the Site Editor.
Do they match?
Scenario 3: Editing an existing post after saving the custom style in the Site Editor.
Results
Scenario 1:
✅ Google Font rendered as expected.
❌ Could not reproduce the reported issue.
Scenario 2: After saving the custom style in the Site Editor.
✅ 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.
✅ 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-facestyles were correct in the HTML for each.bgardner commentedon May 31, 2023
@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.
bgardner commentedon May 31, 2023
@hellofromtonya And additionally, how they are registered via theme.json.
hellofromtonya commentedon May 31, 2023
Thanks @bgardner. Let me try the Frost theme with my test set up. Test Report coming.
hellofromtonya commentedon May 31, 2023
Test Report
Env:
Test Steps
wp-fonts-local. Does the CSS match:Results
Without Gutenberg activated
✅ The
@font-facestyles are correct✅ The font matches the Outfit rendering on the Google Fonts site

With Gutenberg 15.9.0 activated
✅ The
@font-facestyles are correct❌ The font does not match the Outfit rendering on the Google Fonts site
Summary
Yes, I can reproduce the issue using the Frost theme.
👉 But the
@font-faceCSS generated is the same with and without Gutenberg plugin activated.Hmm, why isn't the Outfit font being rendered when it's
@font-faceCSS is there?hellofromtonya commentedon May 31, 2023
Investigating ...
Is the Fonts API working?
Yes.
As I noted in my last test report, the
@font-faceCSS generated is the same with and without Gutenberg plugin activated:With the plugin activated:
Without the plugin activated:
The Fonts API is working ✅
What about which font-family is assigned to the
h2element?Inspecting the element and its rules:
With the Gutenberg plugin activated:
where
--wp--preset--font-family--primary = Outfit, sans-serif.It's the same.
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-faceCSS with and without the Gutenberg plugin activated?bgardner commentedon May 31, 2023
@hellofromtonya Worth noting, I know you tested the H2 in this, but it's all type—paragraphs, etc.
ndiego commentedon May 31, 2023
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):

How it looks with Gutenberg 15.9:

hellofromtonya commentedon Jun 1, 2023
Thank you @bgardner! I see the issue. Let me explain.
tl;dr
In the admin area, the font
srcneeds 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.Possible solution:
There are a couple of ways to solve this:
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.
ndiego commentedon Jun 1, 2023
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.
hellofromtonya commentedon Jun 1, 2023
@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.
WraithKenny commentedon Jun 1, 2023
I think this would also be testable on twenty-twentythree, since it also loads local fonts.
hellofromtonya commentedon Jun 1, 2023
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.
webd-uk commentedon Aug 27, 2023
OMG, I've been stuck on exactly this issue for days. THANK YOU!