Move CSSX rules to <head>, skip client-affinity components in SSR
- Shell inlines CSSX flush logic in <head> (collected/clear-collected!) so island CSS rules survive #main-panel morphs during SPA navigation - OCaml render_to_html skips :affinity :client components during Phase 1b SSR (prevents ~cssx/flush rendering inside body-html) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -255,6 +255,7 @@ and render_list_to_html head args env =
|
|||||||
(try
|
(try
|
||||||
let v = env_get env name in
|
let v = env_get env name in
|
||||||
(match v with
|
(match v with
|
||||||
|
| Component c when c.c_affinity = "client" -> "" (* skip client-only *)
|
||||||
| Component _ -> render_component v args env
|
| Component _ -> render_component v args env
|
||||||
| Island _i ->
|
| Island _i ->
|
||||||
(* Islands: SSR via the SX render-to-html from adapter-html.sx.
|
(* Islands: SSR via the SX render-to-html from adapter-html.sx.
|
||||||
|
|||||||
@@ -31,6 +31,14 @@
|
|||||||
(when meta-html (raw! meta-html))
|
(when meta-html (raw! meta-html))
|
||||||
(meta :name "csrf-token" :content csrf)
|
(meta :name "csrf-token" :content csrf)
|
||||||
(style :id "sx-css" (raw! (or sx-css "")))
|
(style :id "sx-css" (raw! (or sx-css "")))
|
||||||
|
;; CSSX rules from island SSR — must be in <head> so they survive
|
||||||
|
;; #main-panel morphs during SPA navigation. Inline the flush logic
|
||||||
|
;; rather than calling ~cssx/flush (which has :affinity :client and
|
||||||
|
;; gets skipped during SSR rendering).
|
||||||
|
(let ((cssx-rules (collected "cssx")))
|
||||||
|
(clear-collected! "cssx")
|
||||||
|
(when (not (empty? cssx-rules))
|
||||||
|
(style :data-cssx true (raw! (join "" cssx-rules)))))
|
||||||
(meta :name "sx-css-classes" :content (or sx-css-classes ""))
|
(meta :name "sx-css-classes" :content (or sx-css-classes ""))
|
||||||
;; CDN / head scripts — configurable per app
|
;; CDN / head scripts — configurable per app
|
||||||
;; Pass a list (even empty) to override defaults; nil = use defaults
|
;; Pass a list (even empty) to override defaults; nil = use defaults
|
||||||
@@ -68,8 +76,6 @@ details.group{overflow:hidden}details.group>summary{list-style:none}details.grou
|
|||||||
(body :class "bg-stone-50 text-stone-900"
|
(body :class "bg-stone-50 text-stone-900"
|
||||||
;; Server-rendered HTML — visible immediately before JS loads
|
;; Server-rendered HTML — visible immediately before JS loads
|
||||||
(div :id "sx-root" (raw! (or body-html "")))
|
(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
|
(script :type "text/sx" :data-components true :data-hash component-hash
|
||||||
(raw! (or component-defs "")))
|
(raw! (or component-defs "")))
|
||||||
(when init-sx
|
(when init-sx
|
||||||
|
|||||||
Reference in New Issue
Block a user