From f3c0cbd8e24493d7779fe4e2df630f94ca33966b Mon Sep 17 00:00:00 2001 From: giles Date: Mon, 23 Mar 2026 14:53:31 +0000 Subject: [PATCH] CSSX rules from island SSR: flush collected rules via ~cssx/flush in shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added (~cssx/flush) to shell after sx-root div — picks up CSS rules generated during island SSR via (collect! "cssx" ...). Registered clear-collected! primitive for the flush component. Standard CSSX classes now styled server-side. Custom colour shades (e.g. text-violet-699) still need investigation. Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/bin/sx_server.ml | 10 ++++++++++ shared/sx/templates/shell.sx | 2 ++ 2 files changed, 12 insertions(+) diff --git a/hosts/ocaml/bin/sx_server.ml b/hosts/ocaml/bin/sx_server.ml index 4689590..daa4b4b 100644 --- a/hosts/ocaml/bin/sx_server.ml +++ b/hosts/ocaml/bin/sx_server.ml @@ -184,6 +184,16 @@ let () = Sx_primitives.register "collected" (fun args -> (match stack with List items :: _ -> List items | _ -> List []) | _ -> List []) +let () = Sx_primitives.register "clear-collected!" (fun args -> + match args with + | [String name] -> + let stack = try Hashtbl.find _scope_stacks name with Not_found -> [] in + (match stack with + | _ :: rest -> Hashtbl.replace _scope_stacks name (List [] :: rest) + | [] -> Hashtbl.replace _scope_stacks name [List []]); + Nil + | _ -> Nil) + let () = Sx_primitives.register "scope-emit!" (fun args -> match args with | [String name; value] -> diff --git a/shared/sx/templates/shell.sx b/shared/sx/templates/shell.sx index 3b0c406..daf0f93 100644 --- a/shared/sx/templates/shell.sx +++ b/shared/sx/templates/shell.sx @@ -68,6 +68,8 @@ details.group{overflow:hidden}details.group>summary{list-style:none}details.grou (body :class "bg-stone-50 text-stone-900" ;; Server-rendered HTML — visible immediately before JS loads (div :id "sx-root" (raw! (or body-html ""))) + ;; Flush CSSX rules collected during island SSR + (~cssx/flush) (script :type "text/sx" :data-components true :data-hash component-hash (raw! (or component-defs ""))) (when init-sx