A behaviour for rendering React components server-side.
To define a custom renderer, change the application config in config.exs:
config :liveview_react, ssr_module: MyCustomSSRModuleExposes a telemetry span for each render under key [:liveview_react, :ssr]
Summary
Types
One Phoenix JavaScript command encoded for an SSR event callback.
Event callback props mapped to ordered Phoenix JavaScript command lists.
A JSON-compatible value used in a materialized stream item.
The plain prop map passed to an SSR renderer.
The normalized HTML returned by render/1.
The exact transport-v2 request passed to a configured SSR renderer.
Rendered slot HTML keyed by default or a named slot.
A materialized stream item passed to an SSR renderer.
A dead-render stream snapshot keyed by non-empty stream name.
Callbacks
Renders one validated transport-v2 request as a complete HTML binary.
Functions
Validates and renders a transport-v2 request with the configured SSR module.
Types
One Phoenix JavaScript command encoded for an SSR event callback.
The command is exactly [operation, options], where operation is a
lowercase command name and options is a plain map. Elixir typespecs cannot
express a fixed-length heterogeneous list, so the element type below is
intentionally broader than the runtime validation.
@type events() :: %{optional(String.t()) => [event_command()]}
Event callback props mapped to ordered Phoenix JavaScript command lists.
Event names use React's onEvent naming convention.
@type json_value() :: nil | boolean() | number() | String.t() | [json_value()] | %{optional(String.t()) => json_value()}
A JSON-compatible value used in a materialized stream item.
The plain prop map passed to an SSR renderer.
Keys must be non-empty, string-compatible names and cannot use prototype-sensitive JavaScript property names.
@type render_response() :: %{html: binary()}
The normalized HTML returned by render/1.
@type request() :: %{ version: 2, component: String.t(), events: events(), identifierPrefix: String.t(), props: props(), streams: streams(), slots: slots() }
The exact transport-v2 request passed to a configured SSR renderer.
All seven fields are required and additional fields are rejected.
Rendered slot HTML keyed by default or a named slot.
@type stream_item() :: %{required(String.t()) => json_value()}
A materialized stream item passed to an SSR renderer.
Every item is a plain JSON object with string keys and a unique, non-empty
"__dom_id" string field.
@type streams() :: %{optional(String.t()) => [stream_item()]}
A dead-render stream snapshot keyed by non-empty stream name.
Callbacks
Renders one validated transport-v2 request as a complete HTML binary.
Renderer implementations should raise LiveViewReact.SSR.NotConfigured
when their infrastructure is unavailable and
LiveViewReact.SSR.RenderError when rendering fails.
Functions
@spec render(request()) :: render_response()
Validates and renders a transport-v2 request with the configured SSR module.
Returns the renderer's HTML in a normalized %{html: html} response. Raises
LiveViewReact.SSR.NotConfigured when required SSR infrastructure is
unavailable and LiveViewReact.SSR.RenderError when the request or renderer
response is invalid, or when a built-in renderer fails. Other exceptions
raised by a custom renderer propagate unchanged.