cljss icon indicating copy to clipboard operation
cljss copied to clipboard

Replace runtime with emotion.js

Open roman01la opened this issue 5 years ago • 6 comments

CSS-in-JS libraries in JavaScript world are mature enough already so it makes little sense to ignore them. I'd propose to replace library runtime with existing JS library, like Emotion, and make cljss essentially a thin wrapper on top of JS library.

roman01la avatar May 27 '19 16:05 roman01la

I came here looking for any issues about performance, since a tool I'm using makes heavy use of dynamic styles and I noticed cljss was slowing down the repaints quite a bit.

Replacing cljss with emotion for a single heavily-used dynamic style (that often had to change at least 15 instances on a repaint) took my repaint times from 175ms to 13ms.

mattly avatar Oct 22 '19 04:10 mattly

@mattly Would you mind sharing how you're using emotion in your cljs project? Are you using the "vanilla" emotion package, or @emotion/styled or something else?

knubie avatar Oct 28 '19 17:10 knubie

I've used the one which is published to cljsjs, guess it's vanilla. The only issue with js lib is that it won't work with SSR on JVM

roman01la avatar Oct 28 '19 18:10 roman01la

I was just wondering if it needed to be used a certain way to take advantage of the performance benefits, but it doesn't seem like emotion/styled is doing anything special over vanilla emotion.

For example I was surprised to see it wasn't using CSS variables, since I figured swapping out css vars would be more performant than generating entirely new classes each time a prop changes.

knubie avatar Oct 29 '19 14:10 knubie

I'm using it from npm under shadow-cljs. I replaced my cljss defstyles with a function that called emotion/css in a js primitive, with values determined at call time. My use-case for this particular style could require over 100 variations of it at once, with about 1/5th of those needing repaint on the change of a single value.

mattly avatar Oct 30 '19 03:10 mattly

FYI, I created a tiny wrapper for emotion https://github.com/khmelevskii/emotion-cljs and maybe it can be useful

khmelevskii avatar Jun 09 '20 07:06 khmelevskii