-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Style HTML tag #467
Style HTML tag #467
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
871fe6c
to
667611d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this, it's a great improvemenet
|
||
let one_property () = | ||
let className = CssJs.style [| CssJs.display `block |] in | ||
let css = render_style_html_tag () in | ||
assert_string css | ||
(Printf.sprintf | ||
"<style data-s data-emotion=\"css %s\">.%s { display: block; }</style>" | ||
className className) | ||
|
||
let multiple_properties () = | ||
let className = | ||
CssJs.style [| CssJs.display `block; CssJs.fontSize (`px 10) |] | ||
in | ||
let css = render_style_html_tag () in | ||
assert_string css | ||
(Printf.sprintf | ||
"<style data-s data-emotion=\"css %s\">.%s { display: block; font-size: \ | ||
10px; }</style>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might not need the same tests cases as test_css_js_styles and we can live with one simple case and a "real world" example.
packages/emotion/native/Css.ml
Outdated
Stylesheet.get_all instance | ||
|> List.fold_left | ||
(fun (prevDataEmotion, prevStyles) (hash, rules) -> | ||
match rules with | ||
| Classnames rules -> | ||
let rules = | ||
pp_rules hash rules | ||
|> Printf.sprintf "%s %s" prevStyles | ||
|> String.trim | ||
in | ||
let dataEmotion = | ||
Printf.sprintf "%s %s" prevDataEmotion hash |> String.trim | ||
in | ||
dataEmotion, rules | ||
| Keyframes keyframes -> | ||
let rules = | ||
pp_keyframes hash keyframes | ||
|> Printf.sprintf "%s %s" prevStyles | ||
|> String.trim | ||
in | ||
let dataEmotion = | ||
Printf.sprintf "%s %s" prevDataEmotion hash |> String.trim | ||
in | ||
dataEmotion, rules) | ||
("css", "") | ||
|> (fun (dataEmotion, styles) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use render_style_tag inside render_style_html_tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @davesnx thank you for the review, to use the render_style_tag
we would need something like this:
(** Deprecated: Use get_string_style_rules instead*)
let render_style_tag () =
Stylesheet.get_all instance
|> List.fold_left
(fun accumulator (hash, rules) ->
match rules with
| Classnames rules ->
let rules = pp_rules hash rules |> String.trim in
Printf.sprintf "%s %s" accumulator rules
| Keyframes keyframes ->
let rules = pp_keyframes hash keyframes |> String.trim in
Printf.sprintf "%s %s" accumulator rules)
""
|> String.trim
let get_string_style_rules = render_style_tag
let get_string_style_hashes () =
Stylesheet.get_all instance
|> List.fold_left
(fun accumulator (hash, _) ->
Printf.sprintf "%s %s" accumulator hash |> String.trim)
""
let render_style_html_tag () =
Printf.sprintf "<style data-s data-emotion=\"css %s\">%s</style>"
(get_string_style_hashes ()) (get_string_style_rules ())
WDYT?
I'm also trying to define a better name for those functions, any idea about it?
packages/emotion/test/test.ml
Outdated
Test_css_js_tag.tests; | ||
Test_css_tag.tests; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having both tests is a bit unnecessary, I would only keep one
This looks good so far! Though, there's one quirk about the style tag rendering that I misspoke about in the screenshot above. The expected output should actually look like this: <style data-emotion="css id123-someName" data-s>
.css-id123-someName { }
</style> Basically, the IDs used in To my knowledge, |
Probably best to add the prefix where it matters only, and render here without any change. Do you know why emotion doesn't need the "css-" prefix here? |
@purefunctor What about the |
I'm not entirely sure myself, maybe it's just how emotion encodes it? Ultimately it sees the prefix already as the first word under
Not sure as well, it's be good to check but I won't be able to until tomorrow! |
Were you talking about something like this? - let pp_keyframes hash keyframes =
+ let pp_keyframes preffix hash keyframes =
let pp_keyframe (percentage, rules) =
Printf.sprintf "%i%% { %s }" percentage (render_declarations rules)
in
let definition = keyframes |> List.map pp_keyframe |> String.concat " " in
- Printf.sprintf "@keyframes %s { %s }" hash definition
+ Printf.sprintf "@keyframes %s-%s { %s }" preffix hash definition
(* ... *)
(* `resolved_rule` here means to print valid CSS, selectors are nested
and properties aren't autoprefixed. This function transforms into correct CSS. *)
- let pp_rules hash rules =
+ let pp_keyframes preffix hash keyframes =
(* TODO: Refactor with partition or partition_map. List.filter_map is error prone.
Ss might need to respect the order of definition, and this breaks the order *)
let list_of_rules = rules |> resolve_selectors in
let declarations =
list_of_rules
|> List.map Autoprefixer.prefix
|> List.flatten
|> List.filter_map render_declaration
|> String.concat " "
- |> fun all -> Printf.sprintf ".%s { %s }" hash all
+ |> Printf.sprintf "@keyframes %s-%s { %s }" preffix hash definition
in
(* ... *)
- let render_hash prefix hash styles =
+ let render_hash hash styles =
let is_label = function D ("label", value) -> Some value | _ -> None in
match List.find_map is_label styles with
- | None -> Printf.sprintf "%s-%s" prefix hash
- | Some label -> Printf.sprintf "%s-%s-%s" prefix hash label
+ | None -> Printf.sprintf "%s" hash
+ | Some label -> Printf.sprintf "%s-%s" hash label
let style (styles : rule list) =
match styles with
| [] -> ""
| _ ->
+ let type_ = "css"
let hash = Emotion_hash.Hash.default (rules_to_string styles) in
- let className = render_hash "css" hash styles in
+ let className = render_hash hash styles in
Stylesheet.push instance (type_, className, Classnames styles);
- className
+ Printf.sprintf "%s-%s" type_ className
let keyframes (keyframes : (int * rule list) list) =
match keyframes with
| [] -> ""
| _ ->
+ let type_ = "animation"
let hash = Emotion_hash.Hash.default (keyframes_to_string keyframes) in
Stylesheet.push instance (type_, hash, Keyframes keyframes);
- animationName
+ "Printf.sprintf "%s-%s" type_ animationName
let get_style_rules () =
Stylesheet.get_all instance
|> List.fold_left
(fun accumulator (type_, hash, rules) ->
match rules with
| Classnames rules ->
let rules = pp_rules type_ hash rules |> String.trim in
Printf.sprintf "%s %s" hash rules
| Keyframes keyframes ->
let rules = pp_keyframes type_ hash keyframes |> String.trim in
Printf.sprintf "%s %s" hash rules)
""
|> String.trim |
Here's an initial fix I came up with, it doesn't account for animations yet: |
Okay, so with animations, here's what <style data-emotion="css-global 1acbpvw">
@-webkit-keyframes animation-1acbpvw {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes animation-1acbpvw {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
</style> I also discovered that for <style data-emotion="css-global 1dvid4v">
body {
background-color: #1F1F1F;
color: #F5F5F5;
margin: 0;
padding: 0;
}
#root {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
box-sizing: border-box;
padding: 1rem;
min-height: 100vh;
}
#root>main {
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
}
@media screen and (min-width: 768px) {
#root {
max-width: 900px;
margin-left: auto;
margin-right: auto;
}
}
</style> |
@davesnx I have to issue a mea culpa for not testing it on a project using a reasonml SSR. |
667611d
to
c6f8eeb
Compare
It would be nice to have a demo of this feature on styleppx |
c6f8eeb
to
3d770e4
Compare
packages/emotion/native/Css.ml
Outdated
| Classnames of rule list | ||
| Keyframes of (int * rule list) list | ||
|
||
module Stylesheet = struct | ||
module Hashes = Set.Make (String) | ||
|
||
type 'a t = { | ||
mutable rules : (string * declarations) list; | ||
(* rules: (prefix * hash * rules) *) | ||
mutable rules : (string * string * declarations) list; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a record here would be needed now, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to your comment below (#467 (comment))
I was thinking to keep as before:
mutable rules : (string * string * declarations) list; | |
mutable rules : (string * declarations) list; |
And have the declarations like this:
type declarations =
| Global of rule list
| Classnames of (string * rule list)
| Keyframes of (string * (int * rule list) list)
Maybe declarations Classnames and Keyframes could be a record for better documentation.
type declarations =
| Global of rule list
| Classnames of {
name : string;
styles : rule list;
}
| Keyframes of {
name : string;
keyframes : (int * rule list) list;
}
(* ... *)
let render_style_tag () =
Stylesheet.get_all instance
|> List.fold_left
(fun accumulator (_, rules) ->
match rules with
| Global rules ->
Printf.sprintf "%s %s" accumulator (rules_to_string rules)
| Classnames { name; styles } ->
let rules = pp_rules name styles |> String.trim in
Printf.sprintf "%s %s" accumulator rules
| Keyframes { name; keyframes } ->
let rules = pp_keyframes name keyframes |> String.trim in
Printf.sprintf "%s %s" accumulator rules)
""
|> String.trim
WDYT?
packages/emotion/native/Css.ml
Outdated
| [] -> "" | ||
| _ -> | ||
let hash = Murmur2.default (rules_to_string styles) in | ||
Stylesheet.push instance ("", hash, Global styles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this I wonder if the prefix can be stored inside Classnames and don't need to do anything in Global, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea, what about something like this:
let style (styles : rule list) =
match styles with
| [] -> ""
| _ ->
let hash = render_hash (Murmur2.default (rules_to_string styles)) styles in
let className = Printf.sprintf "%s-%s" "css" hash in
Stylesheet.push instance (hash, Classnames (className, styles));
className
let global (styles : rule list) =
match styles with
| [] -> ""
| _ ->
let hash = Murmur2.default (rules_to_string styles) in
Stylesheet.push instance (hash, Global styles);
hash
let keyframes (keyframes : (int * rule list) list) =
match keyframes with
| [] -> ""
| _ ->
let hash = Murmur2.default (keyframes_to_string keyframes) in
let animationName = Printf.sprintf "%s-%s" "animation" hash in
Stylesheet.push instance (hash, Keyframes (animationName, keyframes));
animationName
Then we can manage hash, which is a value for all styles, and the variant provides the need for extra info.
The usage can be:
let render_style_tag () =
Stylesheet.get_all instance
|> List.fold_left
(fun accumulator (_, rules) ->
match rules with
| Global rules ->
Printf.sprintf "%s %s" accumulator (rules_to_string rules)
| Classnames (className, rules) ->
let rules = pp_rules className rules |> String.trim in
Printf.sprintf "%s %s" accumulator rules
| Keyframes (animationName, keyframes) ->
let rules = pp_keyframes animationName keyframes |> String.trim in
Printf.sprintf "%s %s" accumulator rules)
""
|> String.trim
packages/emotion/native/Css.ml
Outdated
Printf.sprintf "%s %s" accumulator hash |> String.trim) | ||
"" | ||
|
||
let render_style_html_tag () = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You moved away from the idea of having a server-reason-react component here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to add it.
I'm going to apply it like this:
let style_tag =
React.createElement "style"
[
String ("data-emotion", "css " ^ get_string_style_hashes ());
Bool ("data-s", true);
DangerouslyInnerHtml (get_string_style_rules ());
]
[]
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davesnx I was trying to create this style_tag to use like <Css.styleTag/>
let style_tag ?key:_ ()=
React.createElement "style"
[
String ("data-emotion", "css " ^ get_string_style_hashes ());
Bool ("data-s", true);
DangerouslyInnerHtml (get_string_style_rules ());
]
[]
But I'm receiving this issue:

A workaround for it is:
let style_tag ?key:_ ?children:_ ()=
React.createElement "style"
[
String ("data-emotion", "css " ^ get_string_style_hashes ());
Bool ("data-s", true);
DangerouslyInnerHtml (get_string_style_rules ());
]
[]
But seems strange to have children that isn't used and even without breaking the calling when adding it:
<Css.styleTag/> children </Css.styleTag>
It should have an error since it shouldn't receive a children value.
Should I use the workaround or do you have any idea how to handle it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message isn't the best, but it tells about a missing children
argument, which should be there, so the function should be:
let style_tag ?key:_ () =
React.createElement "style"
[
String ("data-emotion", "css " ^ get_string_style_hashes ());
Bool ("data-s", true);
DangerouslyInnerHtml (get_string_style_rules ());
]
[]
actually, not even key should be needed in this case, it doesn't hurt but isn't needed by any chance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the same, but I guess it is the way JSX is being handled, when calling the make function from the component as , it expects those parameters. Does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random idea: Do you have server-reason-react.react added as dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm testing it on e2e-melange
which has this dune
for the debug
:
(executable
(name debug)
(public_name e2e_melange_debug)
(modules :standard \ index)
(libraries ui_native server-reason-react.react server-reason-react.reactDom styled-ppx.emotion_native styled-ppx.css_native)
(preprocess
(pps styled-ppx)))
Here is where I'm testing it:
https://github.com/davesnx/styled-ppx/pull/467/files#diff-91524fce38f09c49377280b9f79564819152a9851f302f5a91ad126a0ea3b991
I update de PR to be better to read the new ideas.
BTW, is this the demo you're talking about at the discord? I didn't find any demo folder.
3d770e4
to
923c9ab
Compare
923c9ab
to
fd5eff5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great addition.
CHANGES: ## 0.57.0 - Improvement for locations in both code-gen and error reporting by @davesnx in davesnx/styled-ppx#456 - Support css min and max functions by @lubegasimon in davesnx/styled-ppx#411 - Update docs by @zakybilfagih in davesnx/styled-ppx#457 - update server-reason-react pin to main branch by @zakybilfagih in davesnx/styled-ppx#460 - Native support for styled.{{tag}} by @zakybilfagih in davesnx/styled-ppx#461 - Fix linear-gradient and radial-gradient by @davesnx in davesnx/styled-ppx#464 - Add getting started docs by @zakybilfagih in davesnx/styled-ppx#459 - escape curly on remote markdown content by @zakybilfagih in davesnx/styled-ppx#466 - Add Melange and native instructions by @davesnx in davesnx/styled-ppx#465 - Global styles for native server on emotion by @pedrobslisboa in davesnx/styled-ppx#468 - Style HTML tag by @pedrobslisboa in davesnx/styled-ppx#467 - [emotion native] Fix nested pseudoelements by @davesnx in davesnx/styled-ppx#470 - Transform with variable handle unsafe interpolation by @zakybilfagih in davesnx/styled-ppx#471 - Add depext for @emotion/css >= 11.0.0 by @feihong in davesnx/styled-ppx#473 - Add support for transition by @zakybilfagih in davesnx/styled-ppx#472 - Fix animation codegen by @zakybilfagih in davesnx/styled-ppx#475 - Fix error line number coming from parser by @zakybilfagih in davesnx/styled-ppx#478 - Polish emotion-native by @davesnx in davesnx/styled-ppx#481 - Rename `render_style_tag` to `get_stylesheet` (@davesnx) - Docs: Explain show server rendered stylesheets work natively by @ManasJayanth in davesnx/styled-ppx#480 ## 0.56.0 - Improvement for locations in both code-gen and error reporting (davesnx/styled-ppx#456) by @davesnx - Support css min and max functions (davesnx/styled-ppx#411) by @lubegasimon - Update docs (davesnx/styled-ppx#457) by @zakybilfagih - Native support for styled.{{tag}} (davesnx/styled-ppx#461) by @zakybilfagih - background-clip: text support by @davesnx - Fix linear-gradient and radial-gradient (davesnx/styled-ppx#464) by @davesnx - Rename emotion-hash into murmur2 and remove public testing cli by @davesnx - Use server-reason-react from opam by @davesnx
CHANGES: ## 0.57.1 - Remove public_name from alcotest_extra davesnx/styled-ppx#484 (@davesnx) - Fix nesting for selectors (and pseudo) in native davesnx/styled-ppx#483 (@davesnx) ## 0.57.0 - Improvement for locations in both code-gen and error reporting by @davesnx in davesnx/styled-ppx#456 - Support css min and max functions by @lubegasimon in davesnx/styled-ppx#411 - Update docs by @zakybilfagih in davesnx/styled-ppx#457 - update server-reason-react pin to main branch by @zakybilfagih in davesnx/styled-ppx#460 - Native support for styled.{{tag}} by @zakybilfagih in davesnx/styled-ppx#461 - Fix linear-gradient and radial-gradient by @davesnx in davesnx/styled-ppx#464 - Add getting started docs by @zakybilfagih in davesnx/styled-ppx#459 - escape curly on remote markdown content by @zakybilfagih in davesnx/styled-ppx#466 - Add Melange and native instructions by @davesnx in davesnx/styled-ppx#465 - Global styles for native server on emotion by @pedrobslisboa in davesnx/styled-ppx#468 - Style HTML tag by @pedrobslisboa in davesnx/styled-ppx#467 - [emotion native] Fix nested pseudoelements by @davesnx in davesnx/styled-ppx#470 - Transform with variable handle unsafe interpolation by @zakybilfagih in davesnx/styled-ppx#471 - Add depext for @emotion/css >= 11.0.0 by @feihong in davesnx/styled-ppx#473 - Add support for transition by @zakybilfagih in davesnx/styled-ppx#472 - Fix animation codegen by @zakybilfagih in davesnx/styled-ppx#475 - Fix error line number coming from parser by @zakybilfagih in davesnx/styled-ppx#478 - Polish emotion-native by @davesnx in davesnx/styled-ppx#481 - Rename `render_style_tag` to `get_stylesheet` (@davesnx) - Docs: Explain show server rendered stylesheets work natively by @ManasJayanth in davesnx/styled-ppx#480 ## 0.56.0 - Improvement for locations in both code-gen and error reporting (davesnx/styled-ppx#456) by @davesnx - Support css min and max functions (davesnx/styled-ppx#411) by @lubegasimon - Update docs (davesnx/styled-ppx#457) by @zakybilfagih - Native support for styled.{{tag}} (davesnx/styled-ppx#461) by @zakybilfagih - background-clip: text support by @davesnx - Fix linear-gradient and radial-gradient (davesnx/styled-ppx#464) by @davesnx - Rename emotion-hash into murmur2 and remove public testing cli by @davesnx - Use server-reason-react from opam by @davesnx
CHANGES: ## 0.59.0 - [BREAKING] Change entry point module `CSS` (from `CssJs`) on `styled-ppx.melange`, `styled-ppx.native` and `styled-ppx.rescript` (davesnx/styled-ppx#490) (@davesnx) - [FEATURE] Add support and interpolation for `zoom`, `will-change` and `user-select` properties (davesnx/styled-ppx#489) (@davesnx) - [FEATURE] Support content with interpolation davesnx/styled-ppx#494 (@davesnx) - [FEATURE] Support define CSS variables in global and use CSS variables in properties davesnx/styled-ppx#492 (@davesnx) - [FEATURE] Support overflow with 2 values - [FEATURE] Make animation-name abstract (@davesnx) - [FIX] Add 100 unsupported properties, which will render properly (davesnx/styled-ppx#489) (@davesnx) - [FIX] Inline all CSS.Var and CSS.Cascading in properties (davesnx/styled-ppx#495) (@davesnx) - [FIX] Color with support for rgba/hsla and others with calc/min and max (davesnx/styled-ppx#495) (@davesnx) - [FIX] Warning of kebab-case on emotion client side (davesnx/styled-ppx#493) (@davesnx) ## 0.58.1 - [BREAKING] FontFamilyName.t is now a string (@davesnx) - [FIX] Make unsafe calls from "Cascading" be camelCase to avoid emotion's warning davesnx/styled-ppx#488 (@davesnx) - [FIX] Keep classname when ampersand is at the end of the selector (@davesnx) - [FIX] Fix fontFace in both melange and native (@davesnx) ## 0.58.0 - [FEATURE] Initial @container support davesnx/styled-ppx#476 (@zakybilfagih) - [FIX] Make selector nested maintain other selectors davesnx/styled-ppx#486 (@davesnx) - [BREAKING] Remove `Css` module, `styled_label` and friends davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css and styled-ppx.emotion into styled-ppx.melange davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css-native and styled-ppx.emotion-native into styled-ppx.native davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css-native and styled-ppx.emotion-native into styled-ppx.native davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Remove PseudoClass and PseudoClassParam davesnx/styled-ppx#487 (@davesnx) - Remove functor from Css_Js_Core davesnx/styled-ppx#487 (@davesnx) - Remove melange.js and melange.belt from styled-ppx.melange davesnx/styled-ppx#487 (@davesnx) - Remove server-reason-react.js and server-reason-react.belt from styled-ppx.native davesnx/styled-ppx#487 (@davesnx) ## 0.57.1 - Remove public_name from alcotest_extra davesnx/styled-ppx#484 (@davesnx) - Fix nesting for selectors (and pseudo) in native davesnx/styled-ppx#483 (@davesnx) ## 0.57.0 - Improvement for locations in both code-gen and error reporting by @davesnx in davesnx/styled-ppx#456 - Support css min and max functions by @lubegasimon in davesnx/styled-ppx#411 - Update docs by @zakybilfagih in davesnx/styled-ppx#457 - update server-reason-react pin to main branch by @zakybilfagih in davesnx/styled-ppx#460 - Native support for styled.{{tag}} by @zakybilfagih in davesnx/styled-ppx#461 - Fix linear-gradient and radial-gradient by @davesnx in davesnx/styled-ppx#464 - Add getting started docs by @zakybilfagih in davesnx/styled-ppx#459 - escape curly on remote markdown content by @zakybilfagih in davesnx/styled-ppx#466 - Add Melange and native instructions by @davesnx in davesnx/styled-ppx#465 - Global styles for native server on emotion by @pedrobslisboa in davesnx/styled-ppx#468 - Style HTML tag by @pedrobslisboa in davesnx/styled-ppx#467 - [emotion native] Fix nested pseudoelements by @davesnx in davesnx/styled-ppx#470 - Transform with variable handle unsafe interpolation by @zakybilfagih in davesnx/styled-ppx#471 - Add depext for @emotion/css >= 11.0.0 by @feihong in davesnx/styled-ppx#473 - Add support for transition by @zakybilfagih in davesnx/styled-ppx#472 - Fix animation codegen by @zakybilfagih in davesnx/styled-ppx#475 - Fix error line number coming from parser by @zakybilfagih in davesnx/styled-ppx#478 - Polish emotion-native by @davesnx in davesnx/styled-ppx#481 - Rename `render_style_tag` to `get_stylesheet` (@davesnx) - Docs: Explain show server rendered stylesheets work natively by @ManasJayanth in davesnx/styled-ppx#480 ## 0.56.0 - Improvement for locations in both code-gen and error reporting (davesnx/styled-ppx#456) by @davesnx - Support css min and max functions (davesnx/styled-ppx#411) by @lubegasimon - Update docs (davesnx/styled-ppx#457) by @zakybilfagih - Native support for styled.{{tag}} (davesnx/styled-ppx#461) by @zakybilfagih - background-clip: text support by @davesnx - Fix linear-gradient and radial-gradient (davesnx/styled-ppx#464) by @davesnx - Rename emotion-hash into murmur2 and remove public testing cli by @davesnx - Use server-reason-react from opam by @davesnx
CHANGES: ## 0.59.0 - [BREAKING] Change entry point module `CSS` (from `CssJs`) on `styled-ppx.melange`, `styled-ppx.native` and `styled-ppx.rescript` (davesnx/styled-ppx#490) (@davesnx) - [FEATURE] Add support and interpolation for `zoom`, `will-change` and `user-select` properties (davesnx/styled-ppx#489) (@davesnx) - [FEATURE] Support content with interpolation davesnx/styled-ppx#494 (@davesnx) - [FEATURE] Support define CSS variables in global and use CSS variables in properties davesnx/styled-ppx#492 (@davesnx) - [FEATURE] Support overflow with 2 values - [FEATURE] Make animation-name abstract (@davesnx) - [FIX] Add 100 unsupported properties, which will render properly (davesnx/styled-ppx#489) (@davesnx) - [FIX] Inline all CSS.Var and CSS.Cascading in properties (davesnx/styled-ppx#495) (@davesnx) - [FIX] Color with support for rgba/hsla and others with calc/min and max (davesnx/styled-ppx#495) (@davesnx) - [FIX] Warning of kebab-case on emotion client side (davesnx/styled-ppx#493) (@davesnx) ## 0.58.1 - [BREAKING] FontFamilyName.t is now a string (@davesnx) - [FIX] Make unsafe calls from "Cascading" be camelCase to avoid emotion's warning davesnx/styled-ppx#488 (@davesnx) - [FIX] Keep classname when ampersand is at the end of the selector (@davesnx) - [FIX] Fix fontFace in both melange and native (@davesnx) ## 0.58.0 - [FEATURE] Initial @container support davesnx/styled-ppx#476 (@zakybilfagih) - [FIX] Make selector nested maintain other selectors davesnx/styled-ppx#486 (@davesnx) - [BREAKING] Remove `Css` module, `styled_label` and friends davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css and styled-ppx.emotion into styled-ppx.melange davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css-native and styled-ppx.emotion-native into styled-ppx.native davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css-native and styled-ppx.emotion-native into styled-ppx.native davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Remove PseudoClass and PseudoClassParam davesnx/styled-ppx#487 (@davesnx) - Remove functor from Css_Js_Core davesnx/styled-ppx#487 (@davesnx) - Remove melange.js and melange.belt from styled-ppx.melange davesnx/styled-ppx#487 (@davesnx) - Remove server-reason-react.js and server-reason-react.belt from styled-ppx.native davesnx/styled-ppx#487 (@davesnx) ## 0.57.1 - Remove public_name from alcotest_extra davesnx/styled-ppx#484 (@davesnx) - Fix nesting for selectors (and pseudo) in native davesnx/styled-ppx#483 (@davesnx) ## 0.57.0 - Improvement for locations in both code-gen and error reporting by @davesnx in davesnx/styled-ppx#456 - Support css min and max functions by @lubegasimon in davesnx/styled-ppx#411 - Update docs by @zakybilfagih in davesnx/styled-ppx#457 - update server-reason-react pin to main branch by @zakybilfagih in davesnx/styled-ppx#460 - Native support for styled.{{tag}} by @zakybilfagih in davesnx/styled-ppx#461 - Fix linear-gradient and radial-gradient by @davesnx in davesnx/styled-ppx#464 - Add getting started docs by @zakybilfagih in davesnx/styled-ppx#459 - escape curly on remote markdown content by @zakybilfagih in davesnx/styled-ppx#466 - Add Melange and native instructions by @davesnx in davesnx/styled-ppx#465 - Global styles for native server on emotion by @pedrobslisboa in davesnx/styled-ppx#468 - Style HTML tag by @pedrobslisboa in davesnx/styled-ppx#467 - [emotion native] Fix nested pseudoelements by @davesnx in davesnx/styled-ppx#470 - Transform with variable handle unsafe interpolation by @zakybilfagih in davesnx/styled-ppx#471 - Add depext for @emotion/css >= 11.0.0 by @feihong in davesnx/styled-ppx#473 - Add support for transition by @zakybilfagih in davesnx/styled-ppx#472 - Fix animation codegen by @zakybilfagih in davesnx/styled-ppx#475 - Fix error line number coming from parser by @zakybilfagih in davesnx/styled-ppx#478 - Polish emotion-native by @davesnx in davesnx/styled-ppx#481 - Rename `render_style_tag` to `get_stylesheet` (@davesnx) - Docs: Explain show server rendered stylesheets work natively by @ManasJayanth in davesnx/styled-ppx#480 ## 0.56.0 - Improvement for locations in both code-gen and error reporting (davesnx/styled-ppx#456) by @davesnx - Support css min and max functions (davesnx/styled-ppx#411) by @lubegasimon - Update docs (davesnx/styled-ppx#457) by @zakybilfagih - Native support for styled.{{tag}} (davesnx/styled-ppx#461) by @zakybilfagih - background-clip: text support by @davesnx - Fix linear-gradient and radial-gradient (davesnx/styled-ppx#464) by @davesnx - Rename emotion-hash into murmur2 and remove public testing cli by @davesnx - Use server-reason-react from opam by @davesnx
CHANGES: ## 0.59.0 - [BREAKING] Change entry point module `CSS` (from `CssJs`) on `styled-ppx.melange`, `styled-ppx.native` and `styled-ppx.rescript` (davesnx/styled-ppx#490) (@davesnx) - [FEATURE] Add support and interpolation for `zoom`, `will-change` and `user-select` properties (davesnx/styled-ppx#489) (@davesnx) - [FEATURE] Support content with interpolation davesnx/styled-ppx#494 (@davesnx) - [FEATURE] Support define CSS variables in global and use CSS variables in properties davesnx/styled-ppx#492 (@davesnx) - [FEATURE] Support overflow with 2 values - [FEATURE] Make animation-name abstract (@davesnx) - [FIX] Add 100 unsupported properties, which will render properly (davesnx/styled-ppx#489) (@davesnx) - [FIX] Inline all CSS.Var and CSS.Cascading in properties (davesnx/styled-ppx#495) (@davesnx) - [FIX] Color with support for rgba/hsla and others with calc/min and max (davesnx/styled-ppx#495) (@davesnx) - [FIX] Warning of kebab-case on emotion client side (davesnx/styled-ppx#493) (@davesnx) ## 0.58.1 - [BREAKING] FontFamilyName.t is now a string (@davesnx) - [FIX] Make unsafe calls from "Cascading" be camelCase to avoid emotion's warning davesnx/styled-ppx#488 (@davesnx) - [FIX] Keep classname when ampersand is at the end of the selector (@davesnx) - [FIX] Fix fontFace in both melange and native (@davesnx) ## 0.58.0 - [FEATURE] Initial @container support davesnx/styled-ppx#476 (@zakybilfagih) - [FIX] Make selector nested maintain other selectors davesnx/styled-ppx#486 (@davesnx) - [BREAKING] Remove `Css` module, `styled_label` and friends davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css and styled-ppx.emotion into styled-ppx.melange davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css-native and styled-ppx.emotion-native into styled-ppx.native davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Merge styled-ppx.css-native and styled-ppx.emotion-native into styled-ppx.native davesnx/styled-ppx#487 (@davesnx) - [BREAKING] Remove PseudoClass and PseudoClassParam davesnx/styled-ppx#487 (@davesnx) - Remove functor from Css_Js_Core davesnx/styled-ppx#487 (@davesnx) - Remove melange.js and melange.belt from styled-ppx.melange davesnx/styled-ppx#487 (@davesnx) - Remove server-reason-react.js and server-reason-react.belt from styled-ppx.native davesnx/styled-ppx#487 (@davesnx) ## 0.57.1 - Remove public_name from alcotest_extra davesnx/styled-ppx#484 (@davesnx) - Fix nesting for selectors (and pseudo) in native davesnx/styled-ppx#483 (@davesnx) ## 0.57.0 - Improvement for locations in both code-gen and error reporting by @davesnx in davesnx/styled-ppx#456 - Support css min and max functions by @lubegasimon in davesnx/styled-ppx#411 - Update docs by @zakybilfagih in davesnx/styled-ppx#457 - update server-reason-react pin to main branch by @zakybilfagih in davesnx/styled-ppx#460 - Native support for styled.{{tag}} by @zakybilfagih in davesnx/styled-ppx#461 - Fix linear-gradient and radial-gradient by @davesnx in davesnx/styled-ppx#464 - Add getting started docs by @zakybilfagih in davesnx/styled-ppx#459 - escape curly on remote markdown content by @zakybilfagih in davesnx/styled-ppx#466 - Add Melange and native instructions by @davesnx in davesnx/styled-ppx#465 - Global styles for native server on emotion by @pedrobslisboa in davesnx/styled-ppx#468 - Style HTML tag by @pedrobslisboa in davesnx/styled-ppx#467 - [emotion native] Fix nested pseudoelements by @davesnx in davesnx/styled-ppx#470 - Transform with variable handle unsafe interpolation by @zakybilfagih in davesnx/styled-ppx#471 - Add depext for @emotion/css >= 11.0.0 by @feihong in davesnx/styled-ppx#473 - Add support for transition by @zakybilfagih in davesnx/styled-ppx#472 - Fix animation codegen by @zakybilfagih in davesnx/styled-ppx#475 - Fix error line number coming from parser by @zakybilfagih in davesnx/styled-ppx#478 - Polish emotion-native by @davesnx in davesnx/styled-ppx#481 - Rename `render_style_tag` to `get_stylesheet` (@davesnx) - Docs: Explain show server rendered stylesheets work natively by @ManasJayanth in davesnx/styled-ppx#480 ## 0.56.0 - Improvement for locations in both code-gen and error reporting (davesnx/styled-ppx#456) by @davesnx - Support css min and max functions (davesnx/styled-ppx#411) by @lubegasimon - Update docs (davesnx/styled-ppx#457) by @zakybilfagih - Native support for styled.{{tag}} (davesnx/styled-ppx#461) by @zakybilfagih - background-clip: text support by @davesnx - Fix linear-gradient and radial-gradient (davesnx/styled-ppx#464) by @davesnx - Rename emotion-hash into murmur2 and remove public testing cli by @davesnx - Use server-reason-react from opam by @davesnx
Why
As mentioned by @purefunctor it would be nice to have full SSR support on styled-ppx:

That way the user doesn't need to create a function to handle it and it will work out of the box by the library.
How
render_style_tag
since it doesn't render a tag but the style rules;get_string_style_rules
based onrender_style_tag
;get_string_style_hashes
to get all hashes;render_style_html_tag
to deliver a full SSR-supported style tag.<style data-s data-emotion="css className1">.css-className1 { display: block; }</style>
Attention, this branch is a extension of this one: #468
Screenshot
The screenshot below shows how the emotion handles it well, only creating on client size only client styles the universal styles were not recreated.