Skip to content

Log unrecognized font family on Android - #58804

Closed
mosab-nasrallah wants to merge 1 commit into
react:mainfrom
mosab-nasrallah:android-log-unrecognized-font-family
Closed

mosab-nasrallah wants to merge 1 commit into
react:mainfrom
mosab-nasrallah:android-log-unrecognized-font-family

Conversation

@mosab-nasrallah

Copy link
Copy Markdown
Contributor

Summary:

On Android, a fontFamily that can't be resolved silently falls back to the default system font. iOS logs Unrecognized font family '<name>' in the same case (RCTFont.mm). This adds the same log on Android, only when Typeface.create falls back to the default typeface, so valid system families like monospace don't log. Like RCTLogInfo on iOS, it only runs in debug builds.

Fixes #58750

Replaces #58751, which was closed by accident when its fork got detached.

Changelog:

[ANDROID] [ADDED] - Log unrecognized font families, matching iOS

Test Plan:

Ran this branch's ReactFontManager.kt in a test app on an API 35 emulator and checked logcat. Debug build:

  • 'FontFamilyThatDoesNotExist' logs Unrecognized font family 'FontFamilyThatDoesNotExist' (once per style)
  • 'monospace', 'serif', 'sans-serif', 'sans-serif-medium', 'cursive', fonts in assets/fonts/ and fonts added with addCustomFont log nothing
  • Every font family name declared on the device (34 names, all 4 styles) logs nothing

Release build: nothing is logged, including for 'FontFamilyThatDoesNotExist'.

Repro: RNTesterPlayground.js

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 1, 2026
@mosab-nasrallah

Copy link
Copy Markdown
Contributor Author

@javache I moved this to a new PR because #58751 was closed by accident. This addresses both of your comments:

  • Accuracy: it now only logs when Typeface.create falls back to the default typeface (Typeface.defaultFromStyle(style)), and it skips sans-serif, since that is the default family. It also uses the same message as iOS. I checked every system font family name on an API 35 emulator, and none of them trigger the log.
  • Cost: the existing code already called Typeface.create(fontFamilyName, style) and returned it. This keeps that call, so it doesn't create an extra Typeface. Typeface.defaultFromStyle(style) returns one of the 4 default instances Android creates at startup, and this path only runs once per font family and style because of fontCache. I measured the check at about 25–30 ns on an API 35 emulator (release build), compared to about 57 µs for the two failed asset lookups that already run here. It's also now wrapped in ReactBuildConfig.DEBUG, so release builds skip it entirely, which matches RCTLogInfo on iOS.

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 1, 2026
@meta-codesync

meta-codesync Bot commented Oct 2, 2026

Copy link
Copy Markdown

@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this in D122984557.

@cortinico cortinico left a comment

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.

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in c1401a1 Oct 2, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Oct 2, 2026
@meta-codesync

meta-codesync Bot commented Oct 2, 2026

Copy link
Copy Markdown

@fabriziocucci merged this pull request in c1401a1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Unrecognized fontFamily silently falls back to the system font (no log, unlike iOS)

2 participants