-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Migrating to emotion 10 docs unclear relating to theming, keyframes and SSR #1578
Comments
Yes, when doing SSR with vanilla emotion you have to follow this https://emotion.sh/docs/ssr#using-emotion-10-with-the-old-ssr-apis
Yes,
No functionalities were moved per-se to that package. It just promotes a slightly different way of interacting with
Yes
This is vanilla's implementation: emotion/packages/create-emotion/src/index.js Lines 84 to 90 in 9767309
and this the one from the @emotion/core package:emotion/packages/core/src/keyframes.js Lines 11 to 23 in 9767309
So they are different. The main between core and vanilla is that core is lazy and vanilla has to be eager when it comes to actually inserting styles (this applies to both
I anything that I have described is useful and helped you to clarify things up then please consider preparing a documentation PR that would help future readers. If anything stays unclear - please just ask, I'm here to help you 😉 |
@genevieveloreal friendly 🏓 I would appreciate feedback on the given information and I'm wondering if it has helped you to understand how things are working right now. |
I think I've answered all the questions asked in the thread and I hope it was helpful. We are working on v11 right now and some parts of the docs will be reworked slightly - so hopefully it will be harder in the future to get confused about all of those things. |
@Andarist really helpful information as always! I found this thread looking for an answer to a question on Is there any way for It wouldn't surprise me if that's is simply not possible right now, but I haven't found mention anywhere. Edit: Also a totally unrelated question I've been wondering about if you don't mind, is there a substantial difference in performance between evaluating dynamic styles and static ones, or does it not matter? eg: All styles inside the const dynamicStyles = ({ theme }) => {
const { myColors } = theme;
return css`
color: ${myColors.colorA};
line-height: 1.5;
margin-top: 1px;
margin-bottom: 1px;
flex-grow: 1;
flex-shrink: 1;
white-space: nowrap;
`;
};
const StyledComponent = styled.span`
${dynamicStyles}
`; Only dynamic styles inside const dynamicStyles = ({ theme }) => {
const { myColors } = theme;
// Only dynamically changed styles inside the dynamicStyles variable
return css`
color: ${myColors.colorA};
`;
};
const StyledComponent = styled.span`
line-height: 1.5;
margin-top: 1px;
margin-bottom: 1px;
flex-grow: 1;
flex-shrink: 1;
white-space: nowrap;
`; |
It's not possible - it's the same case as with
Hard to answer - you'd have to benchmark this. Splitting dynamic & static is quite naturally better but the perf difference might not be worth trouble of doing this all over the place. |
Thank you a lot for your helpful explanation @Andarist! That's pretty much what I figured, but it's just so much tougher to work around with const ItemRoot = styled.div`
${props =>
props.isOpen &&
css`
animation-iteration-count: 1;
animation: ${keyframes` // <<< Must be defined anew in every component that uses the animation or not use theme
0% {
background-color: rgba(255, 247, 20, 0.4);
}
100% {
background-color: transparent;
}`} 3s;
`}
` Fortunately we only have a handful to use, but it would get tough if we had dozens of cases to cover. I'd love to run that benchmark, but will probably never find the time. If I do though, I'll share it somewhere. Thanks again @Andarist! |
Just use JavaScript to extract this to a function 😃 const getAnimation = theme => keyframes`
0% {
background-color: rgba(255, 247, 20, 0.4);
}
100% {
background-color: transparent;
}
`;
const ItemRoot = styled.div`
${props =>
props.isOpen &&
css`
animation-iteration-count: 1;
animation: ${getAnimation(props.theme)} 3s;
`}
`; |
I tried that, but functions get stringified inside of |
Notice that |
Ahh! Obviously I didn't try that, and obviously it works. Thank you @Andarist! I feel like the docs could benefit from an example like this. I know there's a project to improve the docs already, but there's a few things like this that don't really fall under any specific docs heading that exists today that might be worth including on a "Tips and Tricks" page or something. |
Firstly, thanks to the maintainers of emotion! I'm new to emotion, having used it for approximately 3 months so far with React.
I'm hoping to get some clarification surrounding migrating from emotion 9 to 10 as this is something we're currently working towards with the code base at my work, and I've found the docs to be somewhat vague in certain areas.
Questions not covered by docs
Does SSR working out of the box require you to only have @emotion/core and @emotion/styled as dependencies? Would utilising vanilla emotion (or any other emotion modules other than @emotion/core and @emotion/styled) mean SSR will not work out of the box?
When I visit https://emotion.sh/docs/introduction under the React section, one of the bullet points states "Theming works out of the box", which I would interpret as meaning that @emotion/core includes theming functionality. However, when I then go to https://emotion.sh/docs/emotion-theming, it states that Theming is accomplished using ThemeProvider (which requires emotion-theming). I suppose my question is, does theming work out of the box with @emotion/core? And if not, it may be helpful to list the requirement for emotion-theming. I'm wondering if ThemeProvider has been replaced by anything in Emotion 10? The Migrating to Emotion 10 page doesn't mention ThemeProvider and if it can continue to be used. I can't see it within any of the code snippets on this page, so I'm unsure.
What functionality has been moved to @emotion/core? Does this now contain the functionality of emotion-server and emotion-theming that were previously separate modules as part of Emotion 9, or are emotion-server and emotion-theming still required?
Can keyframes now be imported from @emotion/core and are there any differences between using keyframes from vanilla emotion and @emotion/core?
It'd be great to clarify these points and help improve documentation for others who are new to emotion and unfamiliar with the changes between emotion 9 and 10.
The text was updated successfully, but these errors were encountered: