-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Port @emotion/babel-plugin to SWC #30804
Comments
@sanderkooger Same we just did the same! We tried using styled components with MUI5 initially, but that was a mess. MUI5 had pretty bad support/documentation for swapping their styling engine from Emotion to Styled Components, so we ended up having quite some issues... With emotion it worked out of the box. Expect many Next users using MUI5 to swap soon :) |
@opolo same, after migrating to MUI5, swapping styled-components to emotion was really painless as lots of things worked quite similarly. altho shouldForwardProp is an annoying thing. |
Any process or status on this? |
Mui folks just stopped trying to make styled-components work with SSR, my team patiently waits for SWC to support @emotion for now |
Things like that make me, dislike the Mui team. But same hopefully SWC will work with @emotion soon! |
Yup same. Upgrading 15+ packages to new major versions (including NextJS to 12) took a couple of hours. We spent 3-4 days trying to upgrade to MUI5 from 4 with our styled-component implementation (and their own example didnt work, they have since removed it .__.)... It was a kick in the face for our senior-developer, when he after those days removed styled-components in favor of Emotion, not knowing the knew consequences it brought (fortunately none so far, it seems... Except slower upgrade to using SWC now :D ) |
This comment has been minimized.
This comment has been minimized.
FYI if your project is flexible to it and you're fine missing out on the extra optimizations of the babel plugin, I haven't had any problems at my company using the emotion ESLint plugin to just auto-add the JSX pragma at the top of any file that needs it, and not relying on the babel plugin at all. would be nice to have this but that option isn't the end of the world. |
This comment has been minimized.
This comment has been minimized.
Considering SWC is disabled when a project has a babel config and most people use babel-plugin-import to minimize bundle size with MUI, as well as @emotion/babel-plugin to use component selectors, I'm wondering how can we make a MUI v5 project work with SWC? |
is there any roadmap for supporting @emotion/babel-plugin? Is there any work that community can help with to push this forward? |
I've posted an update on the feedback thread recently: #30174 (comment) If someone wants to work on it before Heyang gets around to work on it I'd be happy to land a PR for the transform if it matches the babel plugin, you can have a look at the styled-components transform in |
This comment was marked as spam.
This comment was marked as spam.
@RangerCoder99 do you have a link to resource where next team say they won't be doing this? |
@williamtetlow Spoiler: he doesn't. He's upset at the recent release of 12.1 where they picked to support the more popular styled-components first. I highly suspect they're working on Emotion and will land it within the next release or two. In fact, Tim said:
I'm glad they don't hold up releases until they support everything. |
This comment was marked as spam.
This comment was marked as spam.
Even if the team did add emotion support for SWC, Material UI would still not be usable with SWC. A properly configured MUI project will use babel-plugin-import to minimize bundle size with MUI, as well as @emotion/babel-plugin to use component selectors. In short, MUI needs babel to be properly configured and SWC is disabled when a project has a babel config. |
@CloutProject the documentation reads:
MUI does not require babel in SWC, or any modern project that has tree-shaking. |
@markhughes Oh, I see, thanks for correcting me! |
@CloutProject its a common misunderstanding :) |
hey, could you elaborate on why swc emotion transform plugin is in next.js package, not directly in swc? is it backmerged later on, or there is different workflow here? Thank you! |
First of all thank you for the great work!
Here is an example repo with the issue. https://github.com/macko911/next-swc-emotion-component-selector export const ComponentSelectors = styled.div`
${Basic} {
color: red;
}` Is this a feature that might come later, or will I have to refactor my code so that it doesn't rely on the component selector API? |
@macko911 this feature hasn't been released to the stable channel, so you need to change https://github.com/macko911/next-swc-emotion-component-selector/blob/main/package.json#L11 to |
@Brooooooklyn Sorry, I was trying it with the canary version locally but didn't use it in the reproduction repo. I found out that I have to use an "extended" styled component as a selector for it to break. export const Basic = styled.div`
${basicStyles};
`
export const BasicExtended = styled(Basic)``
export const ComponentSelectorsExtended = styled.div`
${BasicExtended} {
color: green;
}
` With this code I get the error even on the latest canary release. I've updated the repo. |
Just to clarify @macko911's example, standard styled components as selectors are fine e.g. const StyledComponent = styled.div` /* styles */ `
const Wrapper = styled.div`
${StyledComponent} {
...
}
` but extending or wrapping an existing component with const StyledComponent = styled.div` /* styles */ `
const ExtendedStyledComponent = styled(StyledComponent)`...` // or
const WrappedOtherComponent = styled(OtherComponent)`...`
const Wrapper = styled.div`
/* neither work individually */
${ExtendedStyledComponent},
${WrappedOtherComponent} {
...
}
` Again, thanks for putting this together. I'm excited to use it in my projects. |
Mui doesn't support that yet, use |
Unfortunately that then reintroduces the |
Looks like |
Is this usable with Jest? I see the following error when I try to use it: |
I am getting the same error. There is an issue related to it. #35661 |
@timneutkens I tried turning on the experimental feature for emotion but am now experiencing issues related to twin.macro (which many people use for tailwind css with emotion/styled-components):
|
@tettoffensive
|
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
This plugin is being used by a good chunk of users. #30802 has even more users though so it's best to start with that one.
The text was updated successfully, but these errors were encountered: