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:
2026-03-23 18:14:43 +00:00
parent 5b370b69e3
commit fe84b57bed
2 changed files with 9 additions and 2 deletions

View File

@@ -31,6 +31,14 @@
(when meta-html (raw! meta-html))
(meta :name "csrf-token" :content csrf)
(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 ""))
;; CDN / head scripts — configurable per app
;; 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"
;; 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