Is `style={}` performant?
I am using Vanilla Extract's Sprinkles API in my project to get static performance and a css-in-js feel but I can't put every style I need in a utility class. For instance sometimes I want to define a specific grid layout or gradient background. As far as I can tell my best options are using a style tag inline in the element which puts the css rules all together or to use vanilla extract's css modules which defines those specific styles in a separate file. What I don't know is the difference in performance between them. I know that in html the style tag is seen as not performant, is Solid different?
Example with style tags: (I like this but don't know about performance)
Example with modules: (what I'm doing now but it's a bit clunky and I'd like to use the css in js patterns)
6 Replies
Yes, solid's handling of style attributes is remarkably performant. However, the browser usually prefers <style> tags to <node style> attributes.
It will only make a difference at scale.
what do you mean by <style> vs <node style>?
@lexlohr
do you mean like
vs
Yes.
interesting. but that only works for some things right? because I really only plan on using
style={}
for complex styles that don't have semantic elements that I would otherwise define with my utility classes or semantic elementsDon't overly avoid style, that would fall under premature optimization.
cool. I'll move forward using class for sprinkles and style for more complex stuff. thanks so much!