Skip to content

feat: conditionally import fonts only when custom font family is not provided#4542

Merged
tomiir merged 6 commits intomainfrom
devin/1750387354-remove-unnecessary-font-import
Aug 11, 2025
Merged

feat: conditionally import fonts only when custom font family is not provided#4542
tomiir merged 6 commits intomainfrom
devin/1750387354-remove-unnecessary-font-import

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Remove unnecessary third-party font imports when custom fonts are provided

Summary

This PR fixes issue #4475 by conditionally importing external fonts only when no custom font family is provided via the --w3m-font-family CSS variable. This optimization improves performance by avoiding unnecessary font downloads when developers provide their own custom fonts.

Changes Made

packages/ui/src/utils/ThemeUtil.ts

  • Modified the Google Fonts import on line 47 to be conditional
  • Only imports Inter font when --w3m-font-family is not set
  • Uses empty CSS template when custom font is provided

packages/ui-new/src/utils/ThemeUtil.ts

  • Modified the KHTeka font-face declarations (lines 87-113) to be conditional
  • Only includes KHTeka and KHTekaMono font-face definitions when --w3m-font-family is not set
  • Uses empty CSS template when custom font is provided

Technical Implementation

  • Uses conditional logic: themeVariables?.['--w3m-font-family'] ? css`` : css...``
  • Maintains backward compatibility - default behavior unchanged when no custom font provided
  • Leverages existing themeVariables parameter in createRootStyles function
  • Uses lit's css template literals for type-safe CSS generation

Testing

  • pnpm build passes successfully
  • pnpm run prettier:format passes successfully
  • ✅ TypeScript compilation without errors
  • ✅ Maintains existing functionality when no custom font is provided

Performance Impact

  • Reduces unnecessary network requests when custom fonts are used
  • Eliminates redundant font downloads that would be overridden by custom fonts
  • No performance impact when using default fonts (existing behavior preserved)

Backward Compatibility

  • ✅ Fully backward compatible
  • ✅ Default behavior remains identical when --w3m-font-family is not provided
  • ✅ Existing implementations continue to work without changes

Link to Devin run: https://app.devin.ai/sessions/d0165cd1abce471badaf6c04fe7bafd7

Requested by: TomTom (tomas.rawski@reown.com)

Fixes #4475

…provided

- Skip Google Fonts import in packages/ui when --w3m-font-family is set
- Skip KHTeka font-face declarations in packages/ui-new when --w3m-font-family is set
- Improves performance by avoiding unnecessary font downloads when custom fonts are used
- Maintains backward compatibility - default behavior unchanged when no custom font provided

Fixes #4475

Co-Authored-By: TomTom <tomtom@reown.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jun 20, 2025

⚠️ No Changeset found

Latest commit: 9ed0f89

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Jun 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
appkit-basic-html ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2025 6:38am
appkit-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2025 6:38am
appkit-gallery ✅ Ready (Inspect) Visit Preview Aug 11, 2025 6:38am
appkit-laboratory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2025 6:38am
10 Skipped Deployments
Name Status Preview Comments Updated (UTC)
appkit-basic-example ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
appkit-basic-sign-client-example ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
appkit-basic-up-example ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
appkit-ethers5-bera ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
appkit-nansen-demo ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
appkit-vue-solana ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
appkit-wagmi-cdn-example ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
ethereum-provider-wagmi-example ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
next-wagmi-solana-bitcoin-example ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am
vue-wagmi-example ⬜️ Ignored (Inspect) Aug 11, 2025 6:38am

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 20, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 77.87% 32140 / 41271
🔵 Statements 77.87% 32140 / 41271
🔵 Functions 69.7% 2665 / 3823
🔵 Branches 84.78% 6837 / 8064
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/ui/src/utils/ThemeUtil.ts 92.2% 70.58% 100% 92.2% 27-28, 38-41
Generated in workflow #14138 for commit 9ed0f89 by the Vitest Coverage Report Action

@rtomas rtomas requested review from 0xmkh and tomiir and removed request for 0xmkh June 20, 2025 12:09
@tomiir
Copy link
Copy Markdown
Collaborator

tomiir commented Jul 18, 2025

Can you add some tests for this change?

devin-ai-integration bot and others added 2 commits July 18, 2025 01:28
- Add tests for packages/ui ThemeUtil to verify Google Fonts import behavior
- Add tests for packages/ui-new ThemeUtil to verify KHTeka font-face behavior
- Tests verify fonts are imported when no custom font family is provided
- Tests verify fonts are NOT imported when custom font family is provided
- Tests ensure keyframe animations are always included regardless of font settings

Co-Authored-By: TomTom <tomtom@reown.com>
- Export createRootStyles in packages/ui/src/utils/ThemeUtil.ts
- Export createRootStyles in packages/ui-new/src/utils/ThemeUtil.ts
- Enables direct testing of conditional font import logic

Co-Authored-By: TomTom <tomtom@reown.com>
cursor[bot]

This comment was marked as outdated.

- Apply prettier formatting to ThemeUtil.test.ts files
- Fix quote consistency and line spacing
- Resolve code_style (prettier) CI check failure

Co-Authored-By: TomTom <tomtom@reown.com>
cursor[bot]

This comment was marked as outdated.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
pay-test-exchange 961037b Jul 24 2025, 07:34 AM

1 similar comment
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
pay-test-exchange 961037b Jul 24 2025, 07:34 AM

cursor[bot]

This comment was marked as outdated.

@tomiir tomiir enabled auto-merge August 11, 2025 07:22
@tomiir tomiir disabled auto-merge August 11, 2025 07:23
@tomiir tomiir merged commit a3f4f18 into main Aug 11, 2025
42 checks passed
@tomiir tomiir deleted the devin/1750387354-remove-unnecessary-font-import branch August 11, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Remove unnessesary third party import if we use custom fonts.

1 participant