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.

styled-jsx is always included in client bundle (even when unused)

See original GitHub issue

What 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:

Screen Shot 2021-10-26 at 5 32 27 PM

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:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
timneutkenscommented, Oct 29, 2021

Going to re-open this to investigate if it might be optimized 👍 Thanks for bringing this to our attention @GrantASL19 👍

1reaction
GrantASL19commented, Dec 24, 2021

Could you please try next@12.0.8-canary.13 to see if it resolves your issue? Thanks 🙏

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.

Read more comments on GitHub >

github_iconTop 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 >

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