Isomorphic SSR: server renders HTML body, client takes over with SX
Server now renders page content as HTML inside <div id="sx-root">, visible immediately before JavaScript loads. The SX source is still included in a <script data-mount="#sx-root"> tag for client hydration. SSR pipeline: after aser produces the SX wire format, parse and render-to-html it (~17ms for a 22KB page). Islands with reactive state gracefully fall back to empty — client hydrates them. Supporting changes: - Load signals.sx into OCaml kernel (reactive primitives for island SSR) - Add cek-call and context to kernel env (needed by signals/deref) - Island-aware component accessors in sx_types.ml - render-to-html handles Island values (renders as component with fallback) - Fix 431 (Request Header Fields Too Large): replace SX-Components header (full component name list) with SX-Components-Hash (12 chars) - CORS allow SX-Components-Hash header Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
(sx-css :as string?) (sx-css-classes :as string?)
|
||||
(component-hash :as string?) (component-defs :as string?)
|
||||
(pages-sx :as string?) (page-sx :as string?)
|
||||
(body-html :as string?)
|
||||
(asset-url :as string) (sx-js-hash :as string) (body-js-hash :as string?)
|
||||
(head-scripts :as list?) (inline-css :as string?) (inline-head-js :as string?)
|
||||
(init-sx :as string?) (body-scripts :as list?))
|
||||
@@ -65,6 +66,8 @@ details.group{overflow:hidden}details.group>summary{list-style:none}details.grou
|
||||
.sx-error .sx-indicator{display:none}.sx-loading .sx-indicator{display:inline-flex}
|
||||
.js-wrap.open .js-pop{display:block}.js-wrap.open .js-backdrop{display:block}"))))
|
||||
(body :class "bg-stone-50 text-stone-900"
|
||||
;; Server-rendered HTML — visible immediately before JS loads
|
||||
(div :id "sx-root" (raw! (or body-html "")))
|
||||
(script :type "text/sx" :data-components true :data-hash component-hash
|
||||
(raw! (or component-defs "")))
|
||||
(when init-sx
|
||||
@@ -72,7 +75,7 @@ details.group{overflow:hidden}details.group>summary{list-style:none}details.grou
|
||||
(raw! init-sx)))
|
||||
(script :type "text/sx-pages"
|
||||
(raw! (or pages-sx "")))
|
||||
(script :type "text/sx" :data-mount "body"
|
||||
(script :type "text/sx" :data-mount "#sx-root"
|
||||
(raw! (or page-sx "")))
|
||||
(script :src (str asset-url "/scripts/sx-browser.js?v=" sx-js-hash))
|
||||
;; Body scripts — configurable per app
|
||||
|
||||
Reference in New Issue
Block a user