Skip to content

fix: font rendering issues by updating font preloader to preload all custom font files#21199

Merged
georgewrmarshall merged 11 commits intomainfrom
fix/missing-font-preloader-variants
Oct 24, 2025
Merged

fix: font rendering issues by updating font preloader to preload all custom font files#21199
georgewrmarshall merged 11 commits intomainfrom
fix/missing-font-preloader-variants

Conversation

@brianacnguyen
Copy link
Copy Markdown
Contributor

@brianacnguyen brianacnguyen commented Oct 15, 2025

Description

This PR improves font rendering consistency across the entire app by enhancing the FontPreloader implementation to prevent font-related rendering issues.

What is the reason for the change?
The existing FontPreloader used a variant-based approach that maintained a manual list of TextVariant enums to preload. This approach was prone to:

  • Missing newly added TextVariants, causing font loading race conditions
  • Inconsistent font rendering with FOIT (Flash of Invisible Text) or FOUT (Flash of Unstyled Text)
  • Maintenance overhead to keep variant lists synchronized with actual usage
  • Potential layout shifts when fonts load asynchronously

What is the improvement/solution?
Refactored the FontPreloader to load all available font files directly instead of maintaining a variant-based list. The new approach:

  • Preloads all 6 Geist font variations (Regular, Medium, Bold + Italic versions)
  • Preloads all 4 MM font variations (MM Poly Regular, MM Sans Regular/Medium/Bold)
  • Eliminates the need to maintain TextVariant lists that could become outdated
  • Provides comprehensive font coverage that automatically supports any TextVariant
  • Future-proofs the system against font rendering issues

Changelog

CHANGELOG entry: Improved font rendering consistency by preloading all available font files

Related issues

Fixes: #15115 #19485 #20001

Manual testing steps

Feature: Comprehensive font preloading

  Scenario: user views components with various text variants
    Given the user navigates through different app screens
    And components use different TextVariant types (DisplayLG, BodyMDBold, BodySMBold, etc.)
    
    When the user views any text content
    Then all text should render immediately with correct fonts
    And there should be no font flashing or layout shifts
    
  Scenario: user experiences consistent font rendering across platforms
    Given the FontPreloader has loaded all font files
    And the user is on web or native platform
    
    When the user interacts with any UI components containing text
    Then font rendering should be consistent and immediate
    And no fallback fonts should be visible during loading

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Refactors FontPreloader to preload all Geist/MM fonts across web/native, standardizes text input typography (adds fontFamily, sets lineHeight, removes fontWeight), and updates tests/snapshots accordingly.

  • Core:
    • FontPreloader: Refactor to preload all custom font families (Geist Regular/Medium/Bold + Italics; MM Poly/Sans Regular/Medium/Bold) via FontFace on web and timed warm-up on native; add extractFontProperties; improve logging and error handling; return consistent loading promise.
    • Tests: Rewrite with platform/timeouts/DOM mocks; add coverage for concurrency, platform-specific delays, web API success/fallback paths, and error handling.
  • UI/Typography:
    • Inputs: Standardize typography by adding fontFamily: 'Geist Regular' in Views/EnterPasswordSimple, Views/RevealPrivateCredential, MultichainAccounts/PrivateKeyList; enforce lineHeight and remove fontWeight from input styles.
    • Snapshots: Update across components to reflect removed fontWeight and added lineHeight/fontFamily.

Written by Cursor Bugbot for commit 1652c65. This will update automatically on new commits. Configure here.

@brianacnguyen brianacnguyen self-assigned this Oct 15, 2025
@brianacnguyen brianacnguyen added needs-qa Any New Features that needs a full manual QA prior to being added to a release. team-design-system All issues relating to design system in Mobile labels Oct 15, 2025
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

cursor[bot]

This comment was marked as outdated.

@brianacnguyen brianacnguyen changed the title chore: updated font preloader to preload all custom font files chore: updated font preloader to preload all custom font files cp-7.57.0 Oct 15, 2025
@brianacnguyen brianacnguyen added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Oct 15, 2025
@Cal-L Cal-L changed the title chore: updated font preloader to preload all custom font files cp-7.57.0 chore: updated font preloader to preload all custom font files Oct 17, 2025
@brianacnguyen brianacnguyen requested a review from a team as a code owner October 17, 2025 17:40
cursor[bot]

This comment was marked as outdated.

Comment on lines +97 to +103
document.fonts.load('italic 400 16px "Geist Regular Italic"'),
document.fonts.load('italic 500 16px "Geist Medium Italic"'),
document.fonts.load('italic 700 16px "Geist Bold Italic"'),
document.fonts.load('400 16px "MM Poly Regular"'),
document.fonts.load('400 16px "MM Sans Regular"'),
document.fonts.load('500 16px "MM Sans Medium"'),
document.fonts.load('700 16px "MM Sans Bold"'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we store these strings in a const?

@brianacnguyen brianacnguyen requested a review from a team as a code owner October 17, 2025 18:40
davibroc
davibroc previously approved these changes Oct 17, 2025
Copy link
Copy Markdown
Contributor

@davibroc davibroc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the fix and it's looking good now

@davibroc davibroc added the QA Passed QA testing has been completed and passed label Oct 17, 2025
Copy link
Copy Markdown
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Do we have a planned follow-up to make these changes more maintainable? Defining fontFamily: 'Geist Regular' for each input that isn't working doesn't seem very scalable. Is there a way to set this globally, or should we replace these inputs with design system versions instead? What are your thoughts?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the FontPreloader to comprehensively preload all custom font files rather than maintaining a manual list of TextVariant enums, improving font rendering consistency and preventing FOIT/FOUT issues across the app.

  • Replaces variant-based font preloading with direct font family preloading for all Geist and MM font variations
  • Adds explicit font family declarations to input fields for consistent rendering
  • Cleans up Input component styles by removing redundant fontWeight and fixing lineHeight formatting

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/core/FontPreloader/FontPreloader.ts Refactored to preload all 10 custom font families directly instead of using TextVariant mappings
app/components/Views/RevealPrivateCredential/styles.ts Added explicit Geist Regular font family to input styles
app/components/Views/MultichainAccounts/PrivateKeyList/styles.ts Added explicit Geist Regular font family to input styles
app/components/Views/EnterPasswordSimple/index.js Added explicit Geist Regular font family to input styles
app/component-library/components/Form/TextField/foundation/Input/Input.styles.ts Fixed lineHeight formatting and removed redundant fontWeight property

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +84 to 87
span.style.fontFamily = fontFamily;
span.textContent = 'Font preload test';
preloadContainer.appendChild(span);
});
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The web font preloading logic creates DOM elements but doesn't set fontWeight, which may not fully exercise all font variations. Consider adding fontWeight extraction from the fontFamily name (e.g., 'Medium' -> '500', 'Bold' -> '700') to ensure proper font loading.

Copilot uses AI. Check for mistakes.
@georgewrmarshall georgewrmarshall dismissed stale reviews from davibroc and themself via 5bf2017 October 23, 2025 20:25
@georgewrmarshall georgewrmarshall added No E2E Smoke Needed and removed needs-qa Any New Features that needs a full manual QA prior to being added to a release. labels Oct 23, 2025
@georgewrmarshall georgewrmarshall force-pushed the fix/missing-font-preloader-variants branch from 5bf2017 to 2987622 Compare October 23, 2025 21:10
@github-actions github-actions bot added size-M and removed size-S labels Oct 23, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

davibroc
davibroc previously approved these changes Oct 24, 2025
Copy link
Copy Markdown
Contributor

@davibroc davibroc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@georgewrmarshall georgewrmarshall dismissed stale reviews from davibroc and themself via c8c1280 October 24, 2025 16:06
@georgewrmarshall georgewrmarshall force-pushed the fix/missing-font-preloader-variants branch from b9cbdc8 to c8c1280 Compare October 24, 2025 16:06
@github-actions github-actions bot added size-L and removed size-M labels Oct 24, 2025
@@ -1,12 +1,155 @@
import FontPreloader from '../FontPreloader';
import { Platform } from 'react-native';
Copy link
Copy Markdown
Contributor

@georgewrmarshall georgewrmarshall Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improving testing coverage after SonarCloud test failures

Before

Screenshot 2025-10-24 at 9 11 17 AM Image

After

Image

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

app/core/FontPreloader/tests/FontPreloader.test.ts:1

  • This pattern of adding promisify to mock setTimeout is duplicated across multiple helper functions (lines 27, 50, 305, 373, 404, 427). Consider extracting this into a shared utility function within the test utilities to reduce duplication.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 47 to 50
paddingVertical: Platform.OS === 'ios' ? 2 : 1,
// Ensure consistent line height for custom font baseline alignment lineHeight: Platform.OS === 'ios' ? 20 : 22,
// Ensure consistent line height for custom font baseline alignment
lineHeight: Platform.OS === 'ios' ? 20 : 22,
fontFamily: getFontFamily(textVariant),
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lineHeight values (20 for iOS, 22 for Android) should be documented or extracted as named constants to clarify why different platforms require different values for custom font baseline alignment.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

@georgewrmarshall georgewrmarshall changed the title chore: updated font preloader to preload all custom font files fix: updated font preloader to preload all custom font files Oct 24, 2025
@georgewrmarshall georgewrmarshall changed the title fix: updated font preloader to preload all custom font files fix: font rendering issues by updating font preloader to preload all custom font files Oct 24, 2025
@georgewrmarshall georgewrmarshall removed the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Oct 24, 2025
Copy link
Copy Markdown
Member

@gantunesr gantunesr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for Accounts CO

@georgewrmarshall georgewrmarshall added this pull request to the merge queue Oct 24, 2025
Merged via the queue into main with commit 74b8745 Oct 24, 2025
212 of 216 checks passed
@georgewrmarshall georgewrmarshall deleted the fix/missing-font-preloader-variants branch October 24, 2025 19:42
@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2025
@metamaskbot metamaskbot added the release-7.59.0 Issue or pull request that will be included in release 7.59.0 label Oct 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

QA Passed QA testing has been completed and passed release-7.59.0 Issue or pull request that will be included in release 7.59.0 size-L team-design-system All issues relating to design system in Mobile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Sentry] EXC_BAD_ACCESS: hash >

6 participants