Skip to content

Commit

Permalink
Reduce log level of "unrecognized font family" from Error to Info
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[iOS][Fixed] - Unrecognized fontFamily values no longer trigger a redbox

## Context

We are starting to roll out a new consistent approach to style errors in React Native, where malformed or semantically invalid style values will never be treated as runtime errors. Instead, bad style values will consistently fall back to known defaults; the incorrect visual rendering will serve as the main runtime diagnostic for developers. We will advise developers to rely on static types for additional diagnostics.

This work will take place over multiple commits and possibly multiple releases of React Native.

## This diff

Here we fix this issue as it applies to the `fontFamily` style prop. The legacy (Paper) renderer on iOS is the only concrete implementation that had to change. Fabric and Android already implement the correct behaviour.

h/t EvanBacon for the report: https://twitter.com/Baconbrix/status/1623039650775371792

Reviewed By: huntie

Differential Revision: D43159284

fbshipit-source-id: 6afeef3abc5781e18671708f642073d25f2347e9
  • Loading branch information
motiz88 authored and facebook-github-bot committed Feb 9, 2023
1 parent 8a0fe30 commit d6e9891
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion React/Views/RCTFont.mm
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ + (UIFont *)updateFont:(UIFont *)font
isCondensed = isCondensedFont(font);
} else {
// Not a valid font or family
RCTLogError(@"Unrecognized font family '%@'", familyName);
RCTLogInfo(@"Unrecognized font family '%@'", familyName);
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
font = [UIFont systemFontOfSize:fontSize weight:fontWeight];
} else if (fontWeight > UIFontWeightRegular) {
Expand Down
3 changes: 3 additions & 0 deletions packages/rn-tester/js/examples/Text/TextExample.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ class TextExample extends React.Component<{...}> {
<Text style={{fontFamily: 'monospace', fontWeight: 'bold'}}>
Monospace Bold (After 5.0)
</Text>
<Text style={{fontFamily: 'Unknown Font Family'}}>
Unknown Font Family
</Text>
</RNTesterBlock>
<RNTesterBlock title="Android Material Design fonts">
<View style={{flexDirection: 'row', alignItems: 'flex-start'}}>
Expand Down
3 changes: 3 additions & 0 deletions packages/rn-tester/js/examples/Text/TextExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@ exports.examples = [
}}>
Verdana bold
</Text>
<Text style={{fontFamily: 'Unknown Font Family'}}>
Unknown Font Family
</Text>
</View>
);
},
Expand Down

0 comments on commit d6e9891

Please sign in to comment.