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.

Importing fonts inside global styles cases re-importing fonts on every re-render

See original GitHub issue

Environment

## System:
 - OS: macOS 10.14.1
 - CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
 - Memory: 330.83 MB / 8.00 GB
 - Shell: 5.3 - /bin/zsh
## Binaries:
 - Node: 11.0.0 - /usr/local/bin/node
 - Yarn: 1.10.1 - /usr/local/bin/yarn
 - npm: 6.4.1 - /usr/local/bin/npm
 - Watchman: 4.9.0 - /usr/local/bin/watchman
## npmPackages:
 - styled-components: ^4.1.1 => 4.1.1

Reproduction

https://github.com/SilencerWeb/eslint-config-website

Steps to reproduce

Create file .env with this line - NODE_PATH="src/", then do the following:

git clone https://github.com/SilencerWeb/eslint-config-website
git checkout 5043b2e272b6f
npm i
npm run start

Expected Behavior

On re-rendering the elements, components should update without blinking.

Actual Behavior

On re-rendering the elements, components blink.

I’m sure it is because of new global styles API that was presented in 4th version of styled-components. I had the same issue with my app on electron and react but I thought it was next.js issue, not styled-components, I had to downgrade to 3th version and use old global styles API. In the current case, I had to move all my fonts to public folder - https://github.com/SilencerWeb/eslint-config-website/commit/7cd1722a816669b1a6d2642475cb11e4c7a77721. Please, check in Chrome, Opera or Safari - in these browser this bug exists for sure.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:29
  • Comments:24 (4 by maintainers)

github_iconTop GitHub Comments

25reactions
probablyupcommented, Mar 21, 2019

Long story short, make sure your fonts are served with appropriate HTTP caching headers. If there is no caching header set, the browser will re-request them every time the style tag is touched.

15reactions
danbopescommented, Nov 21, 2018

It’s absolutely a styled-components issue. The style tag is being rerendered again which is why another attempt to grab the fonts is made. Caching or not, it’s still an issue. Just because the base64 decodes offered a workaround to this problem, doesn’t mean that it’s not a styled components issue. I’ll have a look, and see if I can tackle the reason why this is happening.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Load and Use Custom Fonts with CSS
In the styles.css file, add the following code: styles.css ... In most cases, this will be a serif font like Times New Roman....
Read more >
3 ways to add custom fonts to your MUI project
Learn three simple ways to add custom fonts to a MUI project, including the Google Fonts CDN, google-webfonts-helper, and npm.
Read more >
Why is my local font not being applied with Emotion global ...
Host your downloaded fonts inside your src/myfonts directory then import any of your fonts using the static import statement.
Read more >
Best practices for fonts - web.dev
This article discusses performance best practices for fonts. There are a variety of ways in which web fonts impact performance:.
Read more >
3 quick ways to add fonts to your React app - GreenRoots Blog
✨ Using the Font link ... We can link to any fonts hosted online using the <link> tag inside an HTML file. Let's...
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