View Source Inertia.SSR.Adapter behaviour (Inertia v3.1.0)

Behaviour for Inertia SSR adapters.

An adapter is responsible for taking an Inertia page payload and producing the rendered head and body strings. The default adapter (Inertia.SSR.NodeJSAdapter) calls into a Node.js process pool, but alternative runtimes (e.g. Bun, a Vite dev server) can be plugged in by implementing this behaviour and passing the module as the :ssr_adapter option to Inertia.SSR.

Callbacks

  • init/1 — build adapter configuration from the supervisor's options. Called once at startup. The returned term is passed back to children/1 and call/2 on every render.
  • children/1 — return any child specs the adapter needs added to the Inertia.SSR supervision tree (e.g. a Node.js worker pool).
  • call/2 — render a page payload. Called from the request process, so avoid serializing work through a singleton process.

Summary

Types

adapter_config()

@type adapter_config() :: term()

page()

@type page() :: %{
  :component => String.t(),
  :props => map(),
  :url => String.t(),
  :flash => map(),
  optional(:version) => String.t(),
  optional(:encryptHistory) => boolean(),
  optional(:clearHistory) => boolean(),
  optional(:mergeProps) => [String.t()],
  optional(:prependProps) => [String.t()],
  optional(:deepMergeProps) => [String.t()],
  optional(:matchPropsOn) => [String.t()],
  optional(:deferredProps) => map(),
  optional(:onceProps) => map(),
  optional(:scrollProps) => map(),
  optional(:rescuedProps) => [String.t()],
  optional(:sharedProps) => [String.t()],
  optional(:preserveFragment) => boolean()
}

ssr_result()

@type ssr_result() :: {:ok, map()} | {:error, term()}

Callbacks

call(page, adapter_config)

@callback call(page(), adapter_config()) :: ssr_result()

children(adapter_config)

@callback children(adapter_config()) :: [{module(), keyword()}]

init(opts)

@callback init(opts :: keyword()) :: adapter_config()