styled-jsx is always included in client bundle (even when unused)
See original GitHub issueWhat version of Next.js are you using?
12.0.0
What version of Node.js are you using?
16.6.2
What browser are you using?
N/A
What operating system are you using?
macOS
How are you deploying your application?
N/A
Describe the Bug
Starting with nextjs 12.0.0 styled-jsx
is included in the client bundle even when it’s not used anywhere in the project. e.g. in a fresh create-next-app
:

This wasn’t the case with Next.js 11.
Expected Behavior
styled-jsx
should only be included in the bundle if it’s used in the project.
To Reproduce
Here’s a reproduction based on the latest create-next-app
(with the typescript
preset):
https://github.com/GrantASL19/nextjs-12-unusued-styled-jsx-in-bundle
It’s stock code with WebpackBundleAnalyzer
set to run in the next.config.js
webpack config.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Styled-JSX for React: How and Why | by John Au-Yeung
As mentioned above, it does a very good job of making sure not to include unused CSS and encapsulate styling. Styled JSX also...
Read more >Unused JS massive amounts even though code splitting ...
I am doing the following in my app. Code splitting, and using React.Lazy. Here is my base webpack file: const path = require( ......
Read more >Landing Page with React: 33 kb of JS, 100 ...
styled -components keeps track of which components are rendered on a page and ... So it will be included in the client-side JS...
Read more >Complete Guide to React Lazy Loading and Code Splitting
This bundle can then be included on a webpage to load an entire app at once. If you're using Create React App, Next.js,...
Read more >Tooling
Additional Tools for styled-components, babel and TypeScript plugins, testing. ... not use this plugin and try to server-side render styled-components React ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Going to re-open this to investigate if it might be optimized 👍 Thanks for bringing this to our attention @GrantASL19 👍
next@12.0.8-canary.13
resolves the issue, thanks! 🙏I’m still seeing a ~4kb bundle size increase vs. 11.1.2, but that’s described by #32417. I’ll try to make a reproduction for it in January.