-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
styled-jsx is always included in client bundle (even when unused) #30377
Comments
@GrantASL19 that's expected. We change the whole architecture to make it support react concurrent mode better. Part of styled-jsx registry and context are inside next.js. The normal part of your actual styles are still in other chunks. You can checkout the readme for the new API changes. |
Okay that makes more sense, thanks for the quick reply! Just to be clear, it’s expected that this code will be bundled with a Next.js 12 site even if the site e.g. uses only Emotion for styling? I found this change because I noticed that each page was ~3kb larger after I upgraded to 12. |
It will be bundled into next.js but only a small part of styled-jsx. For the 3kb increasing do you mean on the chunk files? |
I mean the styled-jsx files (mostly stylesheet.js and stylesheet-registry.js) in the main chunk pictured above. Because my previous understanding was that styled-jsx was entirely opt-in I figured this was a bug. If this is expected behaviour even if no stylesheets are loaded I understand, thanks for explaining! |
Going to re-open this to investigate if it might be optimized 👍 Thanks for bringing this to our attention @GrantASL19 👍 |
Hey, I also noticed this today when looking at our client bundle. |
Could you please try |
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. |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
We introduced the `StyleRegistry` on server side to make it concurrent safe for requests. For client we can have only 1 registry since there's only 1 instance per browser window. Keep consistence with previous usage Closes vercel#32417 Closes vercel#30377 Revert change in vercel#31357, it's not required anymore
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 freshcreate-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 thetypescript
preset):https://github.com/GrantASL19/nextjs-12-unusued-styled-jsx-in-bundle
It’s stock code with
WebpackBundleAnalyzer
set to run in thenext.config.js
webpack config.The text was updated successfully, but these errors were encountered: