styled-ppx icon indicating copy to clipboard operation
styled-ppx copied to clipboard

Server-side apis get all stylesheet at once (maybe it should only get the "current")

Open davesnx opened this issue 1 year ago • 3 comments

This isn't a big issue and more like an optimisation, where we could only append to the stylesheet the current classNames being used.

We could introduce Stylesheet.collect to analyse the html as a string, and compare the classnames. Making sure the "critical" is the required to be appended to the resultant HTML.

let stylesheet = Stylesheet.get_all();
let html = ReactDOMServer.renderToString(<App />);
let (critical, other) = Stylesheet.collect(html, css);

Taken from: https://github.com/callstack/linaria/blob/master/docs/API.md#collecthtml-string-css-string--string

The API might change, but the solution should look quite similar

davesnx avatar Oct 21 '24 22:10 davesnx

Emotion have an implementation as well (https://emotion.sh/docs/ssr#on-server) maybe we can port this?

zakybilfagih avatar Dec 07 '24 08:12 zakybilfagih

I didn't want to jump into this issue since I wanted to do first https://github.com/davesnx/styled-ppx/issues/433 and then see if this is actually a problem? Since If we just generate a static file, we could append prefix per module or other techniques where this problems goes away. WDYT?

davesnx avatar Dec 07 '24 20:12 davesnx

For ppx usages, we could detect the ppx execution and flag those styles with unique ids. For style calls, via direct API should push those into a global one

davesnx avatar Sep 03 '25 09:09 davesnx