libero/ssr
Helpers for server-side rendering with Libero.
Server-side: call a dispatch handler directly, encode flags for the HTML document, and render the full page shell.
Client-side: read and decode flags embedded by the server.
Types
Values
pub fn call(
handle handle: fn(state, BitArray) -> #(
BitArray,
option.Option(error.PanicInfo),
state,
),
state state: state,
module module: String,
msg msg: msg,
expect expect: fn(response) -> payload,
) -> Result(payload, SsrError)
Call a dispatch handler directly on the server, returning a
decoded payload. Encodes the call envelope, invokes the handler,
strips the wire framing, and passes the MsgFromServer response
through the expect function to extract the desired value.
The expect parameter works like Elm’s Http.expect — you tell
the call how to unwrap the response variant into the value you
actually want:
ssr.call(
handle: dispatch.handle,
state:,
module: "shared/messages",
msg: GetCounter,
expect: fn(resp) {
let assert CounterUpdated(Ok(n)) = resp
n
},
)
// Returns Result(Int, SsrError)
pub fn decode_flags(
flags: dynamic.Dynamic,
) -> Result(a, SsrError)
Decode flags from a Dynamic value (base64 ETF string). Use this in a Lustre init function to decode server-embedded flags.
pub fn document(
title title: String,
body body: String,
flags flags: a,
client_module client_module: String,
) -> String
Generate a complete HTML document with a pre-rendered body, embedded flags, and a client module import.
The title is HTML-escaped automatically. The body is inserted
as raw HTML (assumed to be pre-rendered Lustre output). The
client_module is a JS import path controlled by the developer,
not user input — it is not escaped (by design). If you derive this
value from external input, you must validate it yourself.
The flags value is encoded
internally via encode_flags, producing a base64 string that is
safe to embed in a JS string literal.
pub fn encode_flags(data: a) -> String
Encode a value as a base64 ETF string, ready to embed in HTML as client flags.