Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix font CSS variable injection for fonts loaded from font panel #2916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
Copilot wants to merge 3 commits into main
base: main
Choose a base branch
Loading
from copilot/fix-818a068c-a59b-4f8c-b9ce-c18a489f3056

Conversation

Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025
edited
Loading

Problem

When users selected fonts from the font panel, the fonts were often only partially implemented and didn't work correctly with Tailwind CSS classes. The system was properly:

  • ✅ Adding fonts to Tailwind config
  • ✅ Adding font imports to layout files
  • ✅ Loading fonts via WebFont API

But it was missing the critical step of injecting CSS variables into the user's globals.css file.

This meant that Tailwind font classes like font-inter would fail because var(--font-inter) was undefined in the CSS.

Solution

Added a new CSSManager class that automatically injects CSS variables into the user's globals.css file when fonts are added through the font panel.

Before the fix:

/* globals.css - no font variables */
html, body { margin: 0; }
// ❌ This doesn't work - var(--font-inter) is undefined
<div className="font-inter">Hello World</div>

After the fix:

/* globals.css - CSS variables properly injected */
/* Onlook Font Variables */
:root {
 --font-inter: 'Inter', sans-serif;
}
html, body { margin: 0; }
// ✅ This now works correctly 
<div className="font-inter">Hello World</div>

Key Features

  • 🎯 Automatic CSS Variable Injection: CSS variables are injected as --font-{id}: '{family}', sans-serif;
  • 🧹 Clean Removal: Variables are properly removed when fonts are deleted, including cleanup of empty sections
  • 🛡️ Error Resilient: Gracefully handles missing globals.css files (fonts still work via WebFont loading)
  • 🔍 Smart Detection: Finds globals.css in common Next.js locations (src/styles/, styles/, src/app/, etc.)
  • 🔄 Integrated Workflow: Seamlessly integrates with existing font management system

Implementation Details

  1. CSSManager - New class that handles CSS variable injection/removal
  2. Updated FontManager - Integrated CSS manager into existing font workflow
  3. File Detection - Automatically finds globals.css in standard locations
  4. CSS Format - Injects variables in :root selector with proper fallbacks

Testing

  • ✅ 10 comprehensive unit tests for CSSManager
  • ✅ 2 integration tests demonstrating complete font lifecycle
  • ✅ All existing tests pass (965 total tests)
  • ✅ TypeScript compliance verified

This fix ensures that fonts loaded from the font panel are immediately functional and can be used with Tailwind CSS classes without any additional manual configuration.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.hubspotusercontent40.net

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[bug] Fonts loaded from the font panel are not implemented correctly</issue_title>
<issue_description>#### Describe the bug
If the user chooses a font from the font panel, it is often only partially implemented. It may still needed to be added to the globals.css to be used correctly in the project </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #2912

💬 Share your feedback on Copilot coding agent for the chance to win a 200ドル gift card! Click here to start the survey.

ellipsis-dev[bot] reacted with rocket emoji
Copy link

vercel bot commented Sep 25, 2025
edited
Loading

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
web Canceled Canceled Sep 25, 2025 6:10am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 25, 2025 6:10am

Copy link

supabase bot commented Sep 25, 2025

This pull request has been ignored for the connected project wowaemfasoptxrdjhilu because there are no changes detected in apps/backend/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

Co-authored-by: Kitenite <31864905+Kitenite@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – docs September 25, 2025 06:03 Inactive
Co-authored-by: Kitenite <31864905+Kitenite@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – docs September 25, 2025 06:05 Inactive
@Copilot Copilot AI changed the title (削除) [WIP] [bug] Fonts loaded from the font panel are not implemented correctly (削除ここまで) (追記) Fix font CSS variable injection for fonts loaded from font panel (追記ここまで) Sep 25, 2025
@Copilot Copilot AI requested a review from Kitenite September 25, 2025 06:06
Copilot finished work on behalf of Kitenite September 25, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Kitenite Kitenite Awaiting requested review from Kitenite

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[bug] Fonts loaded from the font panel are not implemented correctly

2 participants

AltStyle によって変換されたページ (->オリジナル) /