Fonts chosen under a classic theme keep loading after switching to a block theme
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 58/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- php
- Ambito
- performance
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- PHP
- Stelle
- 1.9k
- Fork
- 913
- Merge medio
- 1g 18h
- PR unite (30g)
- 809
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Automattic/jetpack
-
Bug Needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Automattic/jetpack#55870 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Automattic/jetpack#55385 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
WAF: jetpack_waf_blocklog is created without the site's charset and collationForse già presa @jwebbdev l’ha presa 3 giorni fa. Aperta[Plugin] Protect Bug Customer Report
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
Automattic/jetpack#55365 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Package] Stats Admin [Type] Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
Automattic/jetpack#54188 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
Automattic/jetpack#53467 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Automattic/jetpack
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
SVG path arcs with an explicit zero radius throw DivisionByZeroErrorForse già presa @Syed-Shehroz-Sohail l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 5 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
sync-en
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
Перевод устарел
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno