Repository navigation
Google Fonts: preserve native sources and trim frontend catalogue work - #52653
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 2 files.
|
c56c98b to
ec54f43
Compare
27ca8c3 to
6227a3f
Compare
|
I had AI compile my testing notes. But I did this testing manually by visiting the sites and taking notes in a txt file. All looked good across a variety of themes and (simple, jetpack, atomic) on each. Testing notes: WordPress.com SimpleTrunk = production. PR = sandbox with this branch and the WordPress.com filter. On the sandbox, theme files are served from the site instead of s0.wp.com; that is sandbox behaviour and does not happen in production.
Standalone Jetpack (Jurassic Ninja)Trunk = Jetpack 16.3-a.3 through Jetpack Beta. No Gutenberg plugin, so every block is
Editor font picker and Styles → Typography list the full catalogue on both. With the module off, only theme fonts remain. WordPress.com AtomicSame themes and setups as standalone, same results. The Gutenberg plugin is active, so the PR prints theme fonts in
WordPress.com theme previews (v1.2
|
| Jetpack | WordPress.com filter | Regex fix | default | blue / pink / swiss |
|---|---|---|---|---|
| trunk | no | no | 0 | 0 / 0 / 0 |
| trunk | yes | yes | 706 | 4 / 8 / 1 |
| PR | no | no | 0 | 0 / 0 / 0 |
| PR | yes | yes | 706 | 4 / 8 / 1 |
| PR | no | yes | 0 | 4 / 8 / 1 |
Performance(AI compiled the following perf notes but I did these measurements by hand with my usual methods) TLDR: About -20ms rendering the front page of both twentytwenty and twentytwentyfour themes, on a stock site on WPCOM simple. Performance: time to first byte on a WordPress.com Simple sandboxMethod: 600 uncached requests per run to a stock test site on a WordPress.com Simple sandbox, measuring time to first byte (TTFB). Runs alternate trunk / this PR / trunk / this PR. No profiler was running.
Averages of the two runs:
|
|
@jeherve I know this is big and possibly intimidating, maybe you'd like to take a look? I know you were active in the Google Fonts retirement thread. Basically, here, I'm looking to make ThemeJSON code process less data without breaking anything for people using the module. |
jeherve
left a comment
There was a problem hiding this comment.
This looks good, and tests well. Thank you for the detailed testing instructions; it had been a long while since I looked at that module, I had forgotten everything about it 😅
|
Thank you! I will aim for a Monday deploy. |
8e19c0d to
269f02c
Compare
Native theme and user font files still take precedence, but only for the styles and weights they provide. Catalogue faces now fill the gaps, so a theme that bundles only upright faces keeps real italics instead of browser-synthesized ones. Faces that overlap a native weight are skipped so the two sources never compete at the same weight and style. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The google-font-face tests were registered only in the multisite configs, which CI runs on WordPress trunk jobs alone. Register them in the single-site configs so every PHP job runs them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er case Add `jetpack_google_fonts_load_font_faces` so WordPress.com can force the full catalogue where it builds cached theme previews. The Customizer preview frame is an ordinary front-end page, so it no longer loads every catalogue face; its controls run in wp-admin and keep the full catalogue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`get_font_slug_aliases()` lost its last caller when the printer started reading merged settings. The tests share one theme JSON cache helper, and cover catalogue registration through the resolver and single-quoted family names as the real catalogue writes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The printer only handles catalogue faces now, and every catalogue source is an absolute URL (fonts.gstatic.com, or fonts.wp.com on WordPress.com). Theme `file:./` sources are native fonts, which core resolves. Only the old test fixture used `file:./`, so it now uses an absolute URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`wp_is_json_request()` matches any Accept header that mentions JSON, such as axios's default `application/json, text/plain, */*`. A front-end page requested that way loaded every catalogue face into theme JSON, so the native printer output about 700 rules, and the page cache could keep that HTML because it only varies on JSON-only Accept headers. The REST prefix or `rest_route` argument identifies REST requests from the start, including when a theme resolves theme JSON before REST_REQUEST is defined. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
269f02c to
42f8560
Compare
|
wp.com 16:04 UTC 9/30 |
Gutenberg 24.1.0 dropped this function, which breaks the stub update job. Looks like #52653 already dropped the use of it in the actual code, but left usages behind in tests. Drop it there too, so we can drop it from the stubs.
Human Desc
Big Picture.
Jetpack Google Fonts is an older module with planned retirement that lets users use a wide range of fonts. It came before core WordPress's official Font Library added to WP 6.5 in 2024. It works by injecting 60 font-families (comprising of 706 font faces) into the theme json's default origin, which is a lot of data.
When profiling front-end renders on sites with this enabled, Gutenberg processing the 706 fonts with sanitizing and merging, comes up as one of the longest executing filters - somewhere in the 10-20ms range. The goal of this PR is to lessen this processing, but without losing any fonts that sites use, and fixing duplicated font faces in CSS.
The old way of doing it:
The new way of doing it:
unset( $font_family['fontFace'] );which stops the font face from going into theme json data where it has to be processed by Gutenberg. We only add name, slug, and fontFamily, which is ~60 entries.When testing the front-page render of one of my testing sites, it moved the number of PHP function calls executed from 274k -> 267k. I also have some TTFB times down in the PR comments.
I've also done a manual test of 6 different types of themes and sites across (Simple, Jetpack, Atomic) and (Trunk, This PR). See PR comments below.
We're doing 3 things:
(1) Stop turning off Gutenberg's font printer
OLD
NEW
This is safe to do because our (2) change next, removes the fontFaces, meaning they won't all be printed.
(2) Lighter font presets on the front-end
When filling out the list of fonts in load-google-fonts.php, the front-end only needs name, slug, and fontFamily. We can remove a lot of data and only load it in the editor (and also customizer, REST API and CLI):
(3) Let our print_font_faces() respect other sources
For each font family in the catalog, check first:
Note that if the theme or user font is missing a weight or a style (like italic), then the catalogue version should fill in those gaps.
AI Desc (Codex, Astra 6)
Proposed changes
When the Google Fonts module is active, its printer replaces Core/Gutenberg font printing and applies legacy usage detection to every font. This can omit native fonts and emit catalogue sources alongside a theme's bundled version of the same family.
Keep Core/Gutenberg responsible for native theme and user fonts. On ordinary frontend requests, register the catalogue's presets without their
fontFacearrays, then convert and print only the legacy catalogue families detected in use. Native sources take precedence by family, and a preset that replaces a catalogue family takes precedence by slug.Preserve older themes that declare a family or alias without font files: those presets can still use catalogue files. Keep full catalogue metadata for admin, REST/JSON, Customizer and CLI contexts, and preserve the full-data getter used by preview consumers.
Add regression tests for native collisions, aliases, system-font replacements, block-only selections, catalogue filtering, missing data, editor metadata and head/footer ordering. Include generated Gutenberg declarations for static analysis.
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
@font-facerules: the theme's local font should be present without competing catalogue sources. Native fonts should print even when used only through CSS or a style location outside Jetpack's legacy detector.@font-facerules. Repeat with a font selected only on a block.fontFace, both with the catalogue slug and a custom alias. It should still load the catalogue font. Replacing the catalogue slug withsystem-uishould not download the old font.tests/php/modules/google-font-face.Local validation (PHP 8.4.11 / WordPress 7.2-alpha-63394):
git diff --check: passed.These integration runs load real WordPress and, where noted, Gutenberg through a focused test bootstrap. The full Jetpack bootstrap was also attempted, but this checkout cannot load
Automattic\Jetpack\Assets\Shared_Stores_Assets. CI and the site/editor smoke test remain to be checked. No new end-to-end performance measurement is claimed by this PR.WP.COM Simple Front-end font checks (Simple site with this branch; view page source)
Theme fonts print in
<style id='wp-fonts-local'>(core/Gutenberg). Catalogue fonts print in<style class="wp-fonts-local">withfonts.wp.comURLs (Jetpack; in the footer on classic themes). Add a post with some italic and bold text to each test.loudness: the theme ships DM Mono (body) upright only and Rubik (headings) at 400/500. Expect catalogue DM Mono 300/500 and italics, Rubik 300 and 600–900 and all italics, and no catalogue copies of the theme's own faces. Italic text should be a real italic, not slanted upright.message: the theme ships Inter 400/700. Expect catalogue Inter 100–300, 500, 600, 800 and 900 only. (The catalogue has no Inter italics, so italics stay synthesized, as they do without Jetpack.)strand(Newsreader and Plus Jakarta Sans with italics): expect no Jetpackwp-fonts-localblock at all.twentytwentytwo-swiss(Inter preset, nofontFace): expect catalogue Inter faces and no theme faces.twentytwentytwo, switch to the Blue variation (DM Sans 400/700 with italics): expect only the missing DM Sans weights from the catalogue.twentyseventeen: pick a catalogue font (e.g. Lora) on one paragraph. Expect that family's catalogue faces in the footer, and no other catalogue families.