Local Fonts CSS files are not attached on frontend after upgrade to 4.3.0
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3630630. -->
Reported by: [tiziano.sartori](https://www.drupal.org/user/251638)
Related to !20
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>After upgrading Font Your Face to version 4.3.0, Local Fonts are no longer loaded on frontend pages.</p>
<p>Font Display CSS files are still generated and attached correctly, and the Local Font entities remain available and functional. However, the generated Local Font CSS files containing the @font-face definitions are never attached to the page.</p>
<p>As a result, the frontend receives CSS rules such as:</p>
<p>font-family: 'Akzidenz Grotesk Next';</p>
<p>but never receives the corresponding @font-face declarations. Browsers therefore fall back to other fonts.</p>
<p>Investigation shows that:</p>
<p>- Local Font entities still exist.<br>
- Generated font.css and font.woff files exist under sites/default/files/fontyourface/local_fonts/.<br>
- Font Display CSS files are generated correctly.<br>
- No requests for local_fonts/*/font.css or font.woff are made by the browser.</p>
<p>The issue appears to be related to local_fonts_page_attachments() relying on:</p>
<p>drupal_static('fontyourface_fonts')</p>
<p>which is empty during normal frontend page rendering.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>1. Install Font Your Face 4.3.0 with the Local Fonts submodule enabled.<br>
2. Create one or more Local Fonts.<br>
3. Create Font Displays using those fonts.<br>
4. Clear caches.<br>
5. Visit a frontend page using the configured Font Displays.<br>
6. Inspect the generated HTML and browser Network tab.</p>
<p>Observed result:<br>
- Font Display CSS is loaded.<br>
- No local_fonts/.../font.css files are attached.<br>
- No local .woff files are requested.</p>
<p>Expected result:<br>
- local_fonts/.../font.css should be attached automatically.<br>
- Browsers should download the related font.woff files.<br>
- Custom fonts should render correctly.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Investigate the logic used by local_fonts_page_attachments() to discover enabled fonts.</p>
<p>Currently the function relies on:</p>
<p>drupal_static('fontyourface_fonts')</p>
<p>but this array appears empty during normal frontend requests.</p>
<p>The attachment of Local Font CSS files should not depend on runtime data that is only populated during font entity rendering or preview pages.</p>
<p>A possible solution would be to retrieve active fonts directly from Font Display configuration or from the Font entities configured as enabled.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>- Reproduce the issue on a clean Drupal installation.<br>
- Verify whether the problem affects all Local Fonts or only upgraded installations.<br>
- Identify why drupal_static('fontyourface_fonts') is empty on frontend pages.<br>
- Implement and test a fix.<br>
- Add automated coverage for frontend attachment of Local Fonts.</p>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>None.</p>
<h3 id="summary-api-changes">API changes</h3>
<p>None expected.</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>None expected.</p>
<h4>Workaround</h4>
<p>Manually adding the generated Local Font CSS files to the page restores correct behavior immediately:</p>
<p>/sites/default/files/fontyourface/local_fonts/{font_id}/font.css</p>
<p>Once these files are loaded, browsers correctly download the associated .woff files and render the custom font.</p>
issue
GitLab AI Context
Project: project/fontyourface
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/fontyourface/-/raw/8.x-3.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/fontyourface
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD