diff --git a/hosts/ocaml/bin/sx_server.ml b/hosts/ocaml/bin/sx_server.ml index 5905c28f..f447075f 100644 --- a/hosts/ocaml/bin/sx_server.ml +++ b/hosts/ocaml/bin/sx_server.ml @@ -1484,13 +1484,15 @@ let http_render_page env path = | _ -> serialize_value body_result in let t2 = Unix.gettimeofday () in - (* Phase 2: SSR — render to HTML *) + (* Phase 2: SSR — render to HTML using native renderer. + Native Sx_render handles islands as placeholders when SSR fails, + avoiding deep recursion into client-only island bodies. *) let body_html = try let body_exprs = Sx_parser.parse_all body_str in let body_expr = match body_exprs with | [e] -> e | [] -> Nil | _ -> List (Symbol "<>" :: body_exprs) in - sx_render_to_html body_expr env + Sx_render.render_to_html body_expr env with e -> Printf.eprintf "[http-ssr] failed: %s\n%!" (Printexc.to_string e); "" in diff --git a/hosts/ocaml/lib/sx_render.ml b/hosts/ocaml/lib/sx_render.ml index ed1cc8cd..58436129 100644 --- a/hosts/ocaml/lib/sx_render.ml +++ b/hosts/ocaml/lib/sx_render.ml @@ -258,9 +258,10 @@ and render_list_to_html head args env = | Component c when c.c_affinity = "client" -> "" (* skip client-only *) | Component _ -> render_component v args env | Island _i -> - (* Islands: SSR via the SX render-to-html from adapter-html.sx. + (* Islands: try SSR via the SX render-to-html from adapter-html.sx. It handles deref/signal/computed through the CEK correctly, - and renders island bodies with hydration markers. *) + and renders island bodies with hydration markers. + On failure, emit a placeholder — client hydrates from SX source. *) (try let call_expr = List (Symbol name :: args) in let quoted = List [Symbol "quote"; call_expr] in @@ -269,9 +270,9 @@ and render_list_to_html head args env = (match result with | String s | RawHTML s -> s | _ -> value_to_string result) - with e -> - Printf.eprintf "[ssr-island] ~%s FAILED: %s\n%s\n%!" _i.i_name (Printexc.to_string e) (Printexc.get_backtrace ()); - "") + with _e -> + (* Placeholder — client will hydrate this island *) + Printf.sprintf "" _i.i_name) | Macro m -> let expanded = expand_macro m args env in do_render_to_html expanded env