# `PhoenixReplay.Web.Rendering`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/web/rendering.ex#L1)

Renders recorded views and LiveComponents with recorded assigns.

Recorded templates are foreign code rendered with assigns that may be
incomplete at a given position. HEEx evaluates assigns lazily while
LiveView computes the diff, so `render_error/2` evaluates a template up
front to report failures before LiveView sees them.

`rewrite/2` replaces every LiveComponent in a rendered tree with
`PhoenixReplay.Web.Live.ReplayComponent`, which renders the original
module with the component's recorded assigns. Components need no changes
to be replayed.

# `states`

```elixir
@type states() :: %{required({module(), term()}) =&gt; map()}
```

# `assignable`

```elixir
@spec assignable(map()) :: map()
```

Leaves out of recorded `assigns` those LiveView keeps for itself.

# `describe`

```elixir
@spec describe(Exception.t()) :: String.t()
```

Describes why a recorded template failed to render, in a line short
enough for the player: a missing assign is named as such.

# `render`

```elixir
@spec render(module(), map(), keyword()) :: Phoenix.LiveView.Rendered.t()
```

Renders a recorded view with `assigns`: with its `replay_render/1` when
it defines one, with `render/1` otherwise, inside its layout, as
LiveView renders it.

`:layout` is the layout the recording kept, `PhoenixReplay.Recording`'s
`layout`: a `{module, template}` pair of names, or `false` for none.
Without it, as in recordings made before it was kept, the view renders
in the layout its `use Phoenix.LiveView, layout: ...` names. A layout
module that no longer exists is left out.

`replay_render/1` is an optional callback for views whose live render
depends on code in the browser, such as a client-side component whose
state the server never sees. It receives the same assigns `render/1`
would, plus the client state the browser reported up to this point in
`PhoenixReplay.Recording.State.assign/0`, `%{key => merged changes}`,
and returns a rendered template the replay frame can show without that
code.

It is rendered in full on every step, without change tracking: a view
typically derives assigns from the reported state with `assign/3`, and
tracking would compare them with the recorded assigns, not with the
previous step, so a value that went back to what was recorded would stay
stale on the page.

# `render_check`

```elixir
@spec render_check(module(), map(), keyword()) ::
  :ok | {:missing, atom()} | {:error, String.t()}
```

Renders `module` with `assigns`, as `render_error/2` does, telling an
assign the recording lacks, such as one the template began to read after
the session was recorded, from other failures: `{:missing, key}`, or
`{:error, description}`. Takes `render/3`'s options.

# `render_error`

```elixir
@spec render_error(module(), map(), keyword()) :: String.t() | nil
```

Renders `module` with `assigns`, returning a short description of the
error when any part of the template fails to evaluate, or `nil`.

Exception messages can include every assign, so the description names a
missing assign or keeps the first line of the message; the full message
is logged at the debug level.

# `rewrite`

```elixir
@spec rewrite(Phoenix.LiveView.Rendered.t(), states()) ::
  Phoenix.LiveView.Rendered.t()
```

Routes every LiveComponent in `rendered` through the replay component.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
