Is it better don't put dynamic styles in emotion ? #2857
-
Like the left and top propertity generated by drag. if put them in emotion, emotion will keep generate new classes, will this cause performance problems? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
It will cause performance issues. This is discussed in our docs here. :) |
Beta Was this translation helpful? Give feedback.
-
What about the |
Beta Was this translation helpful? Give feedback.
-
Make sence, thanks! |
Beta Was this translation helpful? Give feedback.
-
@srmagura @Andarist my understanding is that performance issues often come from Function Interpolation, i.e. FunctionInterpolation: styled.div(({disabled}) => ({
opacity: disabled ? 0.5 : undefined,
})) over CSSObject: styled.div({
"&[aria-disabled=true]": {
opacity: 0.5,
},
}) The above is a simple example and I'm not saying would on its own be the cause of a performance issue, but I think avoiding function interpolations is a good general principle. I think this also helps with server side static extraction. I was wondering about continuing to use emotion but opting out of Function Interpolations. I wonder if it would be worth having a package that doesn't export this functionality, or any other known bottlenecks? Alternatively perhaps this could be enforced via TypeScript by overriding the FunctionInterpolation to be |
Beta Was this translation helpful? Give feedback.
-
I think this can be done with import * as Serialize from "@emotion/serialize";
declare module "@emotion/serialize" {
export interface FunctionInterpolation<Props> {
(props: never): Serialize.Interpolation<Props> & never;
}
} I would prefer to mark it as deprecated than never, but not figured that out yet. Would be good to hear others thoughts on this approach! |
Beta Was this translation helpful? Give feedback.
-
I'm a bit late to the party but I think the best way to dynamically manipulate directly via DOM. |
Beta Was this translation helpful? Give feedback.
It will cause performance issues. This is discussed in our docs here. :)