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

[Bug]: Using styled-octicons in development mode significantly bloats bundle #981

Open
pveierland opened this issue Aug 26, 2023 · 2 comments

Comments

@pveierland
Copy link

Describe the bug

Importing a single icon from styled-octicons into my Next.js React application increases the bundle size of the importing component from ~2 MB to ~350 MB in a development build when using the next dev server. When viewing the files distributed as node_modules/@primer/styled-octicons/dist/icons/*, it appears that every icon file includes every icon distributed. In a development build, all N icons are included fully N times, causing an N*N import footprint in the bundle. This causes the developer experience to become very slow and unstable.

Steps to reproduce

Steps to reproduce the behavior:

  1. Use next dev to run a Next development server.
  2. Add import import { CheckboxIcon } from '@primer/styled-octicons'; within React application using Next.js + webpack.

(The same issue appears when using: import * as StyledOcticons from '@primer/styled-octicons';)

image

Expected behavior

When using import { CheckboxIcon } from '@primer/octicons-react'; the size of the resulting webpack component bundle is ~2 MB. It is not expected that the size would be exactly the same, but that the size difference would be less excessive.

In a production build using next build; next export, the issue is resolved as the tree-shaking appears to correctly get rid of unused icons.

image

Device details

  • OS: Linux skylab-x1 6.1.41 #1-NixOS SMP PREEMPT_DYNAMIC Mon Jul 24 16:55:35 UTC 2023 x86_64 GNU/Linux
  • Browser: Firefox 115.0.2 (64-bit)
  • Package next: 13.4.12
  • Package @primer/styled-octicons: 19.5.0
  • Package @primer/octicons-react: 19.5.0
  • Package react: 18.2.0

Additional info

Version 17.5.0 is listed with an unpacked size of 1.4 MB:
https://www.npmjs.com/package/@primer/styled-octicons/v/17.5.0

Version 17.8.0 is listed with an unpacked size of 107 MB:
https://www.npmjs.com/package/@primer/styled-octicons/v/17.8.0

@pveierland
Copy link
Author

For those using Next.js, the following helps mitigate the issue:

const nextConfig = {
    experimental: {
        optimizePackageImports: [
            '@primer/octicons-react',
            '@primer/styled-octicons'
        ],
    },
};

@fregante
Copy link
Contributor

This is a severe build bug in the @primer/styled-octicons package.

In short, each icon contains the whole library, even if unused.

This is /dist/icons/AccessibilityIcon.js:

Screenshot

You're importing from the index, which internally looks like:

export {AccessibilityIcon.js} from './dist/AccessibilityIcon.js'
// etc repeated N times

So yes, that's why the weight is N*N 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants