question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when "font-weight" is present on html

See original GitHub issue

Whenever i try to render a page which contains font-Weight, i get the following error:

Warning: Failed prop type: Invalid prop fontWeight of value 400 supplied to Text, expected one of [“normal”,“bold”,“100”,“200”,“300”,“400”,“500”,“600”,“700”,“800”,“900”]. Bad object: { “marginTop”: 14, “marginBottom”: 14, “fontWeight”: 400 } in Text (at HTML.js:460)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Feb 28, 2018

I stumbled upon a weird issue which caused this error in the following HTML:

<h5><strong>Text <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/Small-world-network-example.png/220px-Small-world-network-example.png" alt="sample_image" /></strong></h5>

with fontWeight: '500' set in tagStyles for both h5 and strong.

After removing <strong> or <img> everything works properly. It seems that the string value gets converted to a number in the child Text component. I managed to find a hacky way to get around this by modifying source code of this library from https://github.com/archriss/react-native-render-html/blob/60d53598e35f5cf36d89a5c9a526d85a9744288f/src/HTMLStyles.js#L143 to

       if (value.search('px') !== -1 && !isNaN(numericValue)) {

I’m not sure if this is the right way to tackle this problem though and if it would not cause some other issues. Do you have any suggestions?

0reactions
ghostcommented, Mar 8, 2018

@Exilz Yes, you’re right - my initial solution would result in problems with other styles like margin: 3 or font-size: 12 (without px). Filtering just fontWeight is enough for now I guess. I’ll try to submit a PR later tonight.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when "font-weight" is present on html · Issue #111 - GitHub
Whenever i try to render a page which contains font-Weight, i get the following error: Warning: Failed prop type: Invalid prop fontWeight of ......
Read more >
font-weight is not working properly? - Stack Overflow
Its because the font size (9px) is too small to display bold. Try 11px or more and it works ...
Read more >
font-weight - CSS: Cascading Style Sheets - MDN Web Docs
The font-weight CSS property sets the weight (or boldness) of the font. The weights available depend on the font-family that is currently ...
Read more >
Alignment, font styles, and horizontal rules in HTML documents
This attribute takes the following values: left: Floats the object to the current left margin. Subsequent text flows along the image's right side....
Read more >
HTML DOM Style fontWeight Property - W3Schools
The fontWeight property sets or returns how thick or thin characters in a text should be displayed. Browser Support. Property. fontWeight, Yes, Yes,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found