Skip to content

All registered fonts being enqueued; Jetpack fonts module leads to 24,000 lines of CSS #48263

Closed
@mreishus

Description

@mreishus

Description

When Jetpack registers fonts to make them generally available, Gutenberg is enqueuing them even if they aren't used, causing unneeded font css to render to the front-end of sites.

End result: There is no distinction between fonts that are only registered, and fonts that are registered and enqueued. All registered fonts are enqueued even if not used, causing extra font CSS to be rendered on the front-end.

I believe this bit of code is related:

			// BEGIN OF EXPERIMENTAL CODE. Not to backport to core.
			static::$theme = gutenberg_add_registered_fonts_to_theme_json( static::$theme );
			// END OF EXPERIMENTAL CODE.

On WPCOM, I see the bug begin to happen when WPCOM started to use Gutenberg 15.1.1.

Step-by-step reproduction instructions

Gutenberg + wp-env only

This can be reproduced by using this test plugin which imitates Jetpack's Google Fonts module. Tested using commit a9db335 2023-02-21 19:16 +0100.

## Resetting Gutenberg Repo + Destroying wp-env
wp-env destroy
git reset --hard
git pull
npm run build

## Setting up example Jetpack fonts plugin
mkdir /tmp/webfonts-jetpack-test
git clone [email protected]:mreishus/webfonts-jetpack-test.git /tmp/webfonts-jetpack-test
cd /tmp/webfonts-jetpack-test
composer install
cd -

## Adding the new plugin to be loaded and starting wp-env
sed -i '3s/.*/       "plugins": [ ".", "\/tmp\/webfonts-jetpack-test" ],/' .wp-env.json
wp-env start

The .wp-env.json file should now point to the new plugin:

diff --git a/.wp-env.json b/.wp-env.json
index aa8dfaf3c0..788e754f70 100644
--- a/.wp-env.json
+++ b/.wp-env.json
@@ -1,6 +1,6 @@
 {
        "core": "WordPress/WordPress",
-       "plugins": [ "." ],
+       "plugins": [ ".", "/tmp/webfonts-jetpack-test" ],
        "themes": [ "./test/emptytheme" ],
        "env": {
                "tests": {

If all went well, the wp-admin plugins page should show the new plugin:

2023-02-21_17-17

Now visit http://localhost:8888/ and view source.

  • Actually see: There will be over 20,000 lines of font CSS added.
  • Expected to see: Only fonts used will be enqueued on the front-end, not all registered fonts.

WPCOM + Jetpack + Gutenberg

  • Visit https://wordpress.com/start/ and create a new free site
  • Skip past as many of the signup prompts as possible
  • Change the site's theme to twentytwentytwo
  • Visit the frontend of the site and view source. (Example: https://testsitemmrfont1.wordpress.com/ )
  • See: 24,000 lines of font css

Screenshots, screen recording, code snippet

2023-02-21_17-10

Environment info

wp-env off commit a9db335 2023-02-21 19:16 +0100

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature does not function as intended[Type] PerformanceRelated to performance efforts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions