Fonts chosen under a classic theme keep loading after switching to a block theme
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 58/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- php
- Domain
- performance
Research direction
Start by reading Jetpack_Fonts::maybe_render_fonts() and get_font_css(); the issue does not name their file or any tests. Check how the method handles empty CSS and the jetpack_fonts_render_without_rules filter, then verify that themes without applicable font rules emit neither the loader nor the style while themes with rules still do.
Written by the indexing model from the issue text.
Description
Impacted plugin
Wpcomsh
Quick summary
If a user uses a classic theme, and adds custom fonts in the customizer, then switches to a block theme, those added fonts will still be loaded for visitors, even if they aren't used. And the site admin cannot remove the fonts as the block theme now hides access to the customizer.
Custom Fonts stores the chosen fonts in the site option jetpack_fonts (selected_fonts), whatever theme is active. Jetpack_Fonts::maybe_render_fonts() prints the WebFontConfig loader and webfont.js whenever that option has fonts. If the active theme has no font annotations (any block theme, for example), the generated font CSS is empty, so nothing on the page uses the fonts. But webfont.js still downloads them on every page view. On a block theme the Customizer isn't in the Appearance menu, so site owners can't clear the setting themselves.
Steps to reproduce
- On a classic theme with font annotations, choose a heading and a body font in Customizer → Fonts, then publish.
- Switch to Twenty Twenty-Five.
- View the front-end page source.
Expected: no Custom Fonts output, because the theme has no rules to apply the fonts.
Actual: a WebFontConfig block and webfont.js load both fonts (through fonts-api.wp.com on WordPress.com), and <style id="jetpack-custom-fonts-css"> is empty.
Site owner impact
Fewer than 20% of the total website/platform users
Severity
Minor
What other impact(s) does this issue have?
No response
If a workaround is available, please outline it here.
Cause
maybe_render_fonts()checks onlyget_fonts()(plus Customizer preview and AMP) before callingoutput_webfont_loader().get_font_css()returns no rules for themes without annotations, but the loader runs anyway.- Nothing clears or ignores
selected_fontswhen the theme changes. (gutenberg-integration.phpalready skips block themes for editor styles.)
Impact
Unused font downloads plus an extra script on every page view, on any site that picked fonts under an annotated theme and later moved to a theme without annotations. Reported by an Atomic customer on Twenty Twenty-Five, who had Arimo and Lato loading for nothing.
Proposed fix
In maybe_render_fonts(), build the font CSS first, and return before printing the loader if it is empty. See the comments below for details, and for why no data backfill is needed.
public function maybe_render_fonts( $force = false ) {
if ( ( is_customize_preview() && ! $force ) || ! $this->get_fonts() || ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) ) {
return;
}
$css = $this->get_font_css();
// Without theme rules for the chosen fonts, nothing on the page uses them.
if ( '' === trim( $css ) && ! apply_filters( 'jetpack_fonts_render_without_rules', false ) ) {
return;
}
$webfont_options = $this->get_webfont_options();
if ( count( (array) $webfont_options ) > 0 ) {
$this->output_webfont_loader( $webfont_options );
}
echo '<style id="jetpack-custom-fonts-css">' . $css . "</style>\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
Why this, and why no backfill:
- The check runs at page render, so it fixes every affected site as soon as it deploys. No option data needs migrating.
- Deleting selected_fonts in bulk would be worse. It can't be undone, and a site that switches back to its classic theme would lose fonts it chose deliberately. With the guard, those picks simply start working again.
- It's precise. It skips output only when no rule applies to any chosen font, whatever the theme type. It also covers classic themes without annotations, which have the same waste.
One risk to check first: someone might have picked a font in Custom Fonts and then used it in their own Additional CSS, relying on the loader to fetch it. The guard would stop loading that font. The jetpack_fonts_render_without_rules filter is an escape hatch for those sites. Before shipping, it's worth sampling how many sites have selected_fonts set, no annotation rules, and Additional CSS that mentions one of those family names.
Workaround
Delete the stale selection: wp option patch delete jetpack_fonts selected_fonts.
Platform (Simple and/or Atomic)
Atomic
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 913
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 809
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Automattic/jetpack
-
Bug Needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Automattic/jetpack#55870 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Automattic/jetpack#55385 · 1 comment ·
Maintainers usually reply within 1 day
-
WAF: jetpack_waf_blocklog is created without the site's charset and collationPossibly taken @jwebbdev claimed this 3 days ago. Open[Plugin] Protect Bug Customer Report
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Automattic/jetpack#55365 · 1 assignee ·
Maintainers usually reply within 1 day
-
[Package] Stats Admin [Type] Bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
Automattic/jetpack#54188 ·
Maintainers usually reply within 1 day
-
Bug Needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/jetpack#53467 ·
Maintainers usually reply within 1 day
All issues in Automattic/jetpack
Similar issues
-
follow-up
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Invoice reminders more than a month after the due date, and bill reminders more than a month before it, are not sentPossibly taken @officialasishkumar claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/blocks-engine#7881 ·
Maintainers usually reply within 1 day
-
[FrameworkBundle] MicroKernelTrait lists BundleAdapter instead of the bundle class in kernel.bundlesPossibly taken A pull request linked to this issue is open or already merged. OpenBug FrameworkBundle Status: Needs Review
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
[Flaky Test] testMonitorCallbackReturnExitsPossibly taken @uintaam claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
valkey-io/valkey-glide-php#515 ·
Maintainers usually reply within 4 days