Custom font fine in admin when Vite running hot, but not after npm run build

I’m using custom fonts defined using @font-face statements in editor.css

When Vite is running hot, these display fine in admin - here’s a nav:

But after running npm run build they no longer work - I just get a default sans:

All other styles are loading and I can even see the @font-face statements in the styles within window._wpLoadBlockEditor, for example: @font-face{font-family:FSIndustrie;font-style:normal;font-weight:400;src:url(\/app\/themes\/my-theme\/public\/build\/assets\/FSIndustrie-Regular-BWK6lX9d.woff)format(\"woff\")} but they are just not loading or displaying. I used Charles web proxy and the asset is never accessed. The only asset actually loaded from the theme is editor.js

Additionally, if I change the code in setup.php from

$settings['styles'][] = [
        'css' => Vite::isRunningHot()
            ? "@import url('{$style}')"
            : Vite::content('resources/css/editor.css'),
    ];

to just

$settings['styles'][] = [
        'css' => "@import url('{$style}')"
    ];

It works perfectly after npm run build (so this is my workaround)

So why is the inlined Vite output not loading the fonts?

Has anyone got any pointers as to why this might be? I’m drawing a blank and kind of tearing my hair out as everything looks to be correct. Thanks :slight_smile:

I’m trying to figure this out as well. It seems to only have issues with @font-face so far.

Did you update setup.php to reflect the latest changes to sage/app/setup.php at 5ffb5636b2eae99afd6522eaba7e7809d8b939f5 · roots/sage · GitHub ?

I made those changes myself and it’s fine in the normal editor.

However, it doesn’t work when previewing block patterns, just as an aside.

In situ, when editing a post containing a block pattern, custom fonts render fine:

But previewing the block pattern elsewhere, the fonts are good old Times New Roman:

I had issues with loading styles into the different environments as well and ended up with different approaches for production/dev env like this:

   if(!Vite::isRunningHot()) {
        $style = Vite::content('resources/styles/editor.scss');
        $settings['styles'][] = [
            'css' => $style,
        ];
    } else {
        $style = Vite::asset('resources/styles/editor.scss');
        $settings['styles'][] = [
            'css' => "@import url('{$style}')",
        ];
    }

To me it looked like when running the dev server it parsed the @import statement whereas in production it failed somehow..