Skip to content

Astro fontProviders.googleicons() experimental.glyphs not working correctly #17565

Closed

Description

@keratomalaciant

Astro Info

Astro                    v7.0.7
Node                     v26.5.0
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

On the astro config file, when asking for multiple specific glyphs for fontProviders.googleicons() by using:

fonts: [
      {
        name: "Material Symbols Outlined",
        cssVariable: "--font-material-symbols",
        provider: fontProviders.googleicons(),
        options: {
          experimental: {
            glyphs: [
              "add_shopping_cart",
              "remove_shopping_cart",
              ...
            ],
          },
        },
      },
    ],

the output .woff font will contain what I believe is the entire Google Icons font including every glyph, instead of just the requested ones, as seen by analyzing the font with fontforge:

Image

this results on a 3+ mb font file. meanwhile, if only a single glyph is on the list, like:

  experimental: {
    glyphs: [
      "add_shopping_cart"
    ],

then it propertly downloads just that single one, resulting in the font file being around 3kb in my case.

What's the expected result?

When multiple glyphs are requested, only the requested glyphs should be downloaded instead of the entire glyph library, resulting in a font that is a lot smaller.

I have added a minimal reproducible example via Github since StackBlitz seems to have problems when fetching Google Icons. The only important part on my demonstration is the astro.config.mjs file.

Link to Minimal Reproducible Example

https://github.com/keratomalaciant/glyph-issue-demonstration/

Participation

  • I am willing to submit a pull request for this issue.

Activity

  1. astrobot-houston commented on Jul 31, 2026

    @astrobot-houston
    Contributor
    • Reproduced: Yes
    • Exploration: Yes — View branch
    • Unit Test: Yes — packages/astro/test/units/assets/fonts/googleicons-glyphs.test.ts
    • Priority: P3: minor bug. This affects the experimental glyphs option for fontProviders.googleicons() only when specifying more than one glyph. A simple workaround exists (pre-joining glyph names into a single array element), and the feature itself is marked as experimental.

    The root cause is an upstream bug in unifont v0.7.4 (unjs/unifont#336). The googleicons provider joins glyph names with .join(\"\") (no separator) instead of .join(\",\"), producing an invalid icon_names query parameter like \"add_shopping_cartremove_shopping_cart\". Google's API doesn't recognize the concatenated string and silently falls back to returning the entire ~3.9MB font instead of a subset.

    I found a potential fix for this issue. The fix adds a workaround in Astro's googleicons() wrapper (packages/astro/src/assets/fonts/providers/index.ts) that pre-joins multiple glyphs into a single comma-separated string before passing them to unifont. This sidesteps unifont's .join(\"\") bug by ensuring it only receives a single-element array.

    Try this fix

    You can test this fix right now without waiting for a release:

    npm i https://pkg.pr.new/astro@0a76412
    

    If this fixes your issue, please leave a comment letting us know (e.g. "confirmed, this fixes it"). We'll then open a pull request to get this merged.

    Full Triage Report

    Issue Title

    Astro fontProviders.googleicons() experimental.glyphs not working correctly

    Issue Description

    When using fontProviders.googleicons() with experimental.glyphs containing multiple glyph names, the downloaded font file contains the entire Google Icons library (~3.9MB) instead of just the requested glyphs. With a single glyph, subsetting works correctly (~2.7KB).

    Reporter's Environment

    • Astro v7.0.7
    • Node v26.5.0
    • Linux (x64)
    • pnpm
    • Output: static
    • No adapter, no integrations

    Reproduction Steps

    1. Create an Astro project with the following astro.config.mjs:
    import { defineConfig, fontProviders } from \"astro/config\";
    
    export default defineConfig({
      fonts: [
        {
          name: \"Material Symbols Outlined\",
          cssVariable: \"--font-material-symbols\",
          provider: fontProviders.googleicons(),
          options: {
            experimental: {
              glyphs: [
                \"add_shopping_cart\",
                \"remove_shopping_cart\",
              ],
            },
          },
        },
      ],
    });
    1. Run astro build
    2. Check the generated font file size in dist/_astro/fonts/

    Expected Result

    The font file should contain only the two requested glyphs, resulting in a small file (a few KB).

    Actual Result

    The font file is ~3.9MB, containing the entire Google Icons library.

    Reproduction Evidence

    • Two glyphs: 3,964,620 bytes (3.9MB) ❌
    • One glyph: 2,696 bytes (2.7KB) ✅

    Root Cause

    The bug is in the unifont package (v0.7.4), Astro's upstream dependency for font resolution.

    In unifont's googleicons provider (src/providers/googleicons.ts):

    const iconNames = (options.options?.experimental?.glyphs ?? providerOptions.experimental?.glyphs?.[family])?.join(\"\");

    The .join(\"\") concatenates icon names without any separator:

    • [\"add_shopping_cart\"] → \"add_shopping_cart\" ✅
    • [\"add_shopping_cart\", \"remove_shopping_cart\"] → \"add_shopping_cartremove_shopping_cart\" ❌

    This invalid value is passed as the icon_names query parameter to Google's CSS API. Google doesn't recognize it and silently returns the full font.

    This was already reported upstream as unjs/unifont#336 and closed as "COMPLETED", but no new unifont version has been released with the fix.

    Fix Applied

    Added a workaround in Astro's googleicons() wrapper in packages/astro/src/assets/fonts/providers/index.ts. The wrapper pre-joins multiple glyphs into a single comma-separated element before passing to unifont. When unifont does .join(\"\") on the single-element array, it produces the correct comma-separated string.

    Verification Results

    Scenario Before Fix After Fix
    Two glyphs 3,964,620 bytes (3.9MB) ❌ 3,068 bytes (3KB) ✅
    Single glyph 2,696 bytes (2.7KB) ✅ 2,696 bytes (2.7KB) ✅
    No glyphs (full font) 3,964,620 bytes (3.9MB) ✅ 3,964,620 bytes (3.9MB) ✅

    Confidence: HIGH

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  2. added
    triage: fix pending
    - P3: minor bug
    pkg: astro
    on Jul 31, 2026
  3. keratomalaciant commented on Jul 31, 2026

    @keratomalaciant
    Author

    Yep, the fix works correctly, and now only the requested glyphs are properly downloaded instead of the entire Google Icons collection.

  4. removed
    triage: fix pending
    on Aug 1, 2026
  5. astrobot-houston commented on Aug 1, 2026

    @astrobot-houston
    Contributor

    The fix has been verified! A pull request has been created: #17566

  6. added
    triage: fix verified
    on Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugpkg: astrotriage: fix verified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions