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.

react-icons build optimization

See original GitHub issue

Hello. We are building our docs page and we have serious issues with the react-icons bundle size.

We are using server side rendering and there is 8 chunks that all have additional 1.8mb bundle size caused just in @patternfly/react-icons. In our project we are using only 5 distinct icons, but the build includes all of them. We have tree shaking enabled but with the way how the icons are exposed it will never mark them as unreachable and it will not exclude them from the build.

We could theoretically mark each icon file in node modules as a side effect but that would mean marking each and every single icon file separately which is not really. It is much simpler to take these 5 svgs and store them in our code base and drop the dependency all together (that is what will do for now).

Here you have a screenshot of bundle sizes of every page created for SSR chunks: Screenshot from 2019-11-05 16-35-07

Here is comparision of chunk sizes before (with react-icons) and after (without, moved svgs to code base)

Before

Screenshot from 2019-11-05 17-52-14

After

Screenshot from 2019-11-05 17-51-24

You can see that react-icons/dist/ems is in all of the biggest chunks. Each having 1.8 MB. That means that 8 of our SSR pages has over 2.2 MB of size which is not acceptable for SRR and completely defeats the purpose of this technology.

Can you please look at this issue? We are not able to use PF4 efficiently and we have to use different means (like duplicating components and having them in our code base).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:35 (35 by maintainers)

github_iconTop GitHub Comments

1reaction
evwilkincommented, Dec 20, 2019

Thanks for that context @Hyperkid123 - to catch you up, we’d been working on a few different approaches to getting the imports working using different Babel plugins while keeping the file structure as-is, in order to fix the issue you’re seeing but also not break imports for other users or make large variations to the file structure that’s in place.

A few solutions got us close but not quite there for all components, so we’re looking at other options now and will update you as this progresses - thank you again for the valuable feedback.

1reaction
Hyperkid123commented, Dec 18, 2019

@evwilkin I created simplest example possible which has the issue here:

https://github.com/Hyperkid123/pf-core-icons-deps

Steps to reproduce are in the readme

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimizing Performance - React
If you're benchmarking or experiencing performance problems in your React apps, make sure you're testing with the minified production build.
Read more >
React Icons: A comprehensive tutorial with examples
In this article, you will learn how to use the React Icons library to display icons in your React project.
Read more >
The "best" way to manage icons in React.js - Ben Adam
I have spent the last 7 years building UIs with React.js and I have tried a number of different techniques for managing icons....
Read more >
build-react-icons - npm
Start using build-react-icons in your project by running `npm i ... Features. Optimize and clean SVG to use on web; Create React components ......
Read more >
Optimizing, Converting And Exporting SVG Icons In React
At Vandebron we're maintaining a component library called Windmolen (Dutch for "wind turbine"). And if you've ever built a component library ...
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