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.
Summary
Functions
Leaves out of recorded assigns those LiveView keeps for itself.
Describes why a recorded template failed to render, in a line short enough for the player: a missing assign is named as such.
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.
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.
Renders module with assigns, returning a short description of the
error when any part of the template fails to evaluate, or nil.
Routes every LiveComponent in rendered through the replay component.
Types
Functions
Leaves out of recorded assigns those LiveView keeps for itself.
@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.
@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.
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.
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.
@spec rewrite(Phoenix.LiveView.Rendered.t(), states()) :: Phoenix.LiveView.Rendered.t()
Routes every LiveComponent in rendered through the replay component.