Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React-Icons is blowing up the package size #837

Closed
rguerrettaz opened this issue Jul 2, 2023 · 3 comments
Closed

React-Icons is blowing up the package size #837

rguerrettaz opened this issue Jul 2, 2023 · 3 comments
Labels
help wanted Extra attention is needed 🚀 enhancement New feature or request

Comments

@rguerrettaz
Copy link

rguerrettaz commented Jul 2, 2023

Is your feature request related to a problem? Please describe.
Yes, from the screenshots below you can see the usage of react-icons balloons the sized of the package. You can see in 0.4.8 (which I understand did not work properly) it was taking up 1MB (which seems like quite a lot anyway) and in 0.4.9 it takes up 3.8MB.

Version 0.4.8
Screenshot 2023-07-02 at 07 28 20

Version 0.4.9
Screenshot 2023-07-02 at 07 22 32

The total package size when bundled with Webpack is right now is 4.56MB (screenshot below). I am a paying customer and use 7 components out of the library, making it hard to justify including it in my project. I understand this a pre-release, but am hoping there's a quick way to reduce the size of the package.

Screenshot 2023-07-02 at 07 21 11

Describe the solution you'd like
Perform an optimization pass on the package to reduce the size.

Describe alternatives you've considered
Replace react-icons with hero-icons?

Additional context

@rluders
Copy link
Collaborator

rluders commented Jul 2, 2023

We are planning to replace the react-icons with https://github.com/themesberg/flowbite-icons - but first, we need to create the package for react. :)

@rluders rluders added the 🚀 enhancement New feature or request label Jul 2, 2023
@tulup-conner
Copy link
Collaborator

tulup-conner commented Jul 12, 2023

OK, I have looked into this a lot now.

This is a pretty popular known issue that appears to have still not been resolved by the maintainers of react-icons: react-icons/react-icons#154 There doesn't appear to be a solution for all users.

It looks like Bundlephobia agrees that react-icons is taking up a bunch of space in the final package: https://bundlephobia.com/package/flowbite-react@0.4.11 However, the GZipped size of the package is still 49 KB. Additionally, if you look at older versions of the package, you'll notice that the size of the react-icons chunk has actually increased in total KB as we have added more icons, which would imply that Bundlephobia's script is tree-shaking correctly.

So I ran webpack-bundle-analyzer on our Next.js - the entire react-icons library is in the server bundle, but not the client bundle. That seems to align with the total download size of flowbite-react.com's JS which is about 200 KB minified/GZipped/Brotli'd/whatever else by Vercel.

In other words, it isn't like you are loading 8 MB of icons when someone visits one of your Next.js pages. Regardless, this shouldn't be happening in server or client bundle. I believe what's happening here is an issue with react-icons but I don't really know how we can fix it on our end.

The only specific suggestion I saw in the react-icons issue thread is that we could change the imports to load directly from individual files

import HiHome from "react-icons/lib/hi/home";

But that isn't how react-icons is documented to be used, so, I don't like it. That's also a substantial refactor.

I don't really know what to do about this issue, but I wanted to share what I learned.

@rluders rluders added the help wanted Extra attention is needed label Jul 25, 2023
@tulup-conner
Copy link
Collaborator

This isn't relevant now that we have a Flowbite Icons library available to us. We'll resolve this naturally by migrating. But thank you for pointing this out!

@tulup-conner tulup-conner closed this as not planned Won't fix, can't repro, duplicate, stale Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed 🚀 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants