LiveReactIslands.SSR.Renderer behaviour (LiveReactIslands v0.1.1)

View Source

Behaviour for SSR renderer implementations.

Implementations should handle rendering React components to HTML strings. This allows for different SSR backends (Deno, Node, Bun, etc.)

Summary

Callbacks

Clear any cached component data.

Get renderer statistics.

Optionally preload a component for faster rendering.

Renders a React component to an HTML string.

Callbacks

clear_cache()

(optional)
@callback clear_cache() :: :ok

Clear any cached component data.

get_stats()

(optional)
@callback get_stats() :: map()

Get renderer statistics.

preload_component(component_name)

(optional)
@callback preload_component(component_name :: String.t()) :: :ok

Optionally preload a component for faster rendering.

render_component(component_name, id, props, global_state, strategy)

@callback render_component(
  component_name :: String.t(),
  id :: String.t(),
  props :: map(),
  global_state :: map(),
  strategy :: atom()
) :: {:ok, String.t()} | {:error, term()}

Renders a React component to an HTML string.

Parameters

  • component_name: String name of the React component
  • id: Unique identifier for this island instance
  • props: Map of props to pass to the component
  • global_state: Map of global state shared across islands
  • strategy: SSR strategy (:overwrite or :hydrate_root)

Returns

  • {:ok, html_string} on success
  • {:error, reason} on failure