-
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
Turbopack does not compile CSS nesting for styled-jsx #57718
Comments
Investigation
|
Ah gotcha — does that mean there's no ability to process the CSS in If so, do you have any recommendation on what we should do in order to get our codebase (lu.ma) ready for Turbopack / SWC? We extensively use SCSS for CSS nesting (via Babel plugin) in Styled JSX — should we try and migrate off of CSS nesting entirely? Thanks for looking into this @kdy1! |
Hi @kdy1 just wanted to follow up what you are thinking here. Are you planning on adding a post processor for nested CSS into SWC / Turbopack? Any advice you could share would be awesome. 🙏 |
@vpontis how do you feel about native CSS nesting? Is that an option to consider? https://caniuse.com/css-nesting 82% browser adoption at the moment. If you need syntax lowering, that's possible as well. |
Hi @leerob thanks for getting back to us here. We can switch to native CSS nesting syntax in our code but we will need to compile it to a format that supports more browsers. This is for lu.ma and we want to make sure it's accessible for as many people as possible. We have dropped IE 11, but we can't drop ~ 20% of browsers (esp when it includes iOS Safari 16). Do you have any other suggestions of what we can do here? My idea was to do a PostCSS phase in SWC / Turbopack if that's possible... |
# Turbopack * vercel/turborepo#7027 <!-- Donny/강동윤 - Update `swc_core` to `v0.87.28` --> --- ### What? Update swc crates ### Why? Required for #57718. `styled-jsx` crate now has a hook to transform CSS code using a Rust-side API ### How? Fixes #57718 Closes PACK-2256
Thank you @kdy1! I'll try to test this out later today 👍. Really appreciate it. |
Opening as this is reverted. |
### Description This PR partially reverts #7027 to fix build issues. - Reopens vercel/next.js#57718 ### Testing Instructions Local override will work Closes PACK-2322
# Turbopack * vercel/turborepo#7167 <!-- Leah - fix: catch import map lookup error properly in `ResolvingIssue` --> * vercel/turborepo#7182 <!-- Donny/강동윤 - feat: Re-enable `preset-env` mode of `styled-jsx` in turbopack --> * vercel/turborepo#7161 <!-- Tobias Koppers - add support for globs in sideEffects field in package.json --> * vercel/turborepo#7184 <!-- Donny/강동윤 - chore: Update `swc_core` to `v0.89.6` --> ### What? Update turbopack ### Why? To test vercel/turborepo#7182 against internal webapps. ### How? - Closes #57718 Closes PACK-2334
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
As turbopack is currently dev-mode-only, you need to configure the |
Hi @kdy1, could you share a bit more information about how to get this working? I've been struggling with it for a few weeks. I made a small repo that shows how this currently works for me — https://github.com/luma-team/nextjs-swc-sass-test I am running it in dev and I see that the CSS is still nested. I have Screenshot from my demo page: |
You need to pass the css plugin names to stlyed jsx babel plugin |
@kdy1 can you share a little more? I'm still lost. Are you suggesting that I need to import the styled-jsx-plugin-postcss to get this working on both dev and production? I would expect Turbopack to compile the CSS on dev since I am running I created a {
"plugins": [
[
"styled-jsx/babel",
{
"plugins": ["postcss-nested"]
}
]
]
} But I got an error since babel and Turbopack don't work together? |
You can't use turbopack for it |
@kdy1 so why is this issue closed? It sounds like we are in the same position as before this issue, right? Is this issue closed as wontfix or solved? If it's solved, how do I compile nested CSS in Styled JSX without using Babel? Why did you close this issue? I'm not sure what new functionality in Next.js addresses the original issue. Is there new functionality? If so, how do I enable it? I know you are busy (and you are doing great work with |
Turbopack supports it. That's why this issue is closed. But we don't have If your app is in development mode only, you can set the appropriate browserslist config to enable CSS nesting. |
Can you share how to do this? I've tried a bunch of different things and have gone back and forth with the Vercel team but I haven't figured out how to get it working for development. I would think that the default browserslist would compile nested CSS because older versions of Safari don't support CSS nesting. I have made an example repo and tried like 10 different ways to get this enabled in development mode. Can you let me know how I can change my repo to get it working? |
@vpontis, what @kdy1 is trying to articulate, I think, is:
|
How do I enable this? I have tried multiple
Should this issue be re-opened? Or should I open another issue? The issue is "Turbopack does not compile CSS nesting for styled-jsx" — so if it only compiles it in a subset of cases (which I have not encountered) — then the issue should still be open. |
looked into it, I think one thing that @kdy1 might have overlooked is that the browserlists might not get consumed properly. We're investigating. |
Investigation
|
I think turbopack is not applying |
Thanks for looking into this. What's the current status of this issue? Should we re-open it? It seems like my original issue wasn't fixed. Is there a plan to support Turbopack and compiling Styled JSX so that I can drop Babel? I feel pretty lost here. |
Hey @vpontis I had a look at the initial question to dig into the confusion between what @kdy1 and @feedthejim said and what you were asking about. @kdy1 added support for CSS nesting, the official specification: https://www.w3.org/TR/css-nesting-1/ which is handled in styled-jsx by default now for both Webpack and Turbopack, the Turbopack documentation is not super clear on this as it was written with the assumption that postcss-nested is the same as CSS nesting, but it's unfortunately not, postcss-nested has additional features which are not in the spec, the spec calls this out in the green section as part of this section: https://www.w3.org/TR/css-nesting-1/#syntax. We'll update the documentation to reflect that it's not Specifically the example you gave of I've also had a look into the browserlist config not applying, it is indeed the case that we currently don't pass along the browserlist config but that is not the intended outcome, we're going to add support for passing browserslist to Turbopack (including applying to the CSS) soon, @wbinnssmith is opening an issue for it on the turbo repository right now and will post back here when it's added to the issue tracker. Update: Issue was created here: #63430 Does that answer all your questions? If not let me know and I can provide additional details. If you have more Babel config let me know as well, if it's only adding postcss-nested to styled-jsx it should be straightforward to migrate from postcss-nested to the official spec. |
Thank you Tim! So to clarify my understanding:
If that is right, then once step 4 is complete, we should be able to drop Babel entirely. |
Removing Babel is unrelated to using Turbopack, you can already do this today to use SWC instead. Can you share your babel config so that I can confirm that? |
Additional clarification: This is the correct syntax for CSS nesting spec: .container {
color: blue;
padding: 3rem;
.inner {
color: yellow
}
} Output: .container {
color: blue;
padding: 3rem;
}
.container .inner {
color: yellow;
} The .container {
color: blue;
padding: 3rem;
&.inner {
color: yellow
}
} Output: .container {
color: blue;
padding: 3rem;
}
.container.inner {
color: yellow;
} You can try it in the LightningCSS playground |
Thanks Tim! I think there is one last point of confusion.
You could mean two things by "current version of Next.js supports CSS nesting spec in styled-jsx":
I recorded a 2 minute video showing how I am not able to get nested CSS to compile. You can see the demo repository I used in that video. |
Hey Victor, |
Thanks Tim! I think I published all of the information required to report this bug a few times in multiple different formats above in this thread. It's been a bit frustrating on my side. I truly appreciate the work y'all do but I felt like my multiple reproductions and examples have not been taken seriously until you took another look at things. I hope you can fix this. It would be certainly very helpful for us. Even before I created this issue, this is something I've been looking into for over a year. |
Should be fixed by #63541 |
@kdy1 — we've gone back and forth many times on this issue. You've marked it "fixed" a few times but I never know what that is supposed to mean. Can you share what you mean by "fixed"? How do I reproduce your fix? Is it fixed for Turbopack? For SWC? Can you please, please use a few sentences to describe the fix and how you verified it. I will also spend time tomorrow trying to figure out and verify your fix. |
|
Thank you for the explanation! I think I'll need to wait until the next Canary release is published before testing this, is that right? Will this mean that:
|
I got it working on dev (without Turbopack)!!!!!! Incredible!!!!!!!!!!!!!!!!!!!! |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/vpontis/nextjs-14-turbo-styled-jsx
To Reproduce
The Turbopack docs it says that it supports PostCSS nested which allows you to nest CSS selectors.
This would be very useful for us since we are currently using Sass just to be able to nest selectors. We would like to
move off Sass / Babel and use Turbo.
But I think Turbopack doesn't apply the PostCSS plugins to the CSS generated by Styled JSX.
For example, the following code:
Gives me this CSS:
Where I would expect:
Current vs. Expected behavior
CSS nesting should be compiled but it's not.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 Binaries: Node: 18.16.1 npm: 9.5.1 Yarn: 1.22.19 pnpm: 8.10.0 Relevant Packages: next: 14.0.0 eslint-config-next: 14.0.0 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
SWC transpilation, Turbopack (--turbo)
Additional context
This would be super super helpful to us to get working :). Happy to look into this if you'd like to point me in the right direction :)
PACK-2106
The text was updated successfully, but these errors were encountered: